Skip to content

fix(pi-stack): replace Type.Union/Literal with Type.String for JSON Schema 2020-12 compat#6

Open
chico-piaba wants to merge 1 commit intoaretw0:mainfrom
chico-piaba:fix/tool-schema-json-2020-12
Open

fix(pi-stack): replace Type.Union/Literal with Type.String for JSON Schema 2020-12 compat#6
chico-piaba wants to merge 1 commit intoaretw0:mainfrom
chico-piaba:fix/tool-schema-json-2020-12

Conversation

@chico-piaba
Copy link
Copy Markdown

Problem

When using claude-opus-4-6-thinking via the google-antigravity provider, the pi agent returns:

tools.N.custom.input_schema: JSON schema is invalid.
It must match JSON Schema draft 2020-12.

Root Cause

Three pi-stack extensions used Type.Union([Type.Literal(...)]) from @sinclair/typebox to define string enum parameters. This generates anyOf + const schemas.

The google-antigravity provider routes Claude models through Cloud Code Assist using the legacy parameters field (OpenAPI 3.03 Schema), which does not support anyOf + const patterns. The sanitizeSchemaForAntigravity() function converts constenum, but the outer anyOf wrapper remains invalid.

Serialization chain

Type.Union([Type.Literal("a"), ...])
  → anyOf: [{ const: "a" }, ...]           ← Typebox generates this
    → sanitizeSchemaForAntigravity()
      → anyOf: [{ enum: ["a"] }, ...]      ← const becomes enum
        → OpenAPI 3.03 rejects anyOf        ← 💥 ERROR

Fix

Replaced Type.Union([Type.Literal(...)]) with Type.String({ description: "..." }) which is universally compatible across all providers and schema formats.

Files changed

Extension Field Before After
session-analytics.ts query_type Type.Union([Type.Literal(...)]) Type.String()
governance-profiles.ts action Type.Union([Type.Literal(...)]) Type.String()
safe-boot.ts action Type.Union([Type.Literal(...)]) Type.String()

Testing

  • Verified no remaining Type.Union/Type.Literal patterns in pi-stack extensions
  • Changes only affect tool parameter schemas; runtime validation in execute() is unchanged
  • Compatible with all providers: Anthropic, Google, OpenAI, GitHub Copilot

Prevention

For future tool schemas, prefer:

  • Type.String({ description: "a | b | c" }) — universally safe
  • StringEnum([...] as const) — generates { type: "string", enum: [...] }
  • Type.Union([Type.Literal(...)]) — generates incompatible anyOf + const

…chema 2020-12 compat

Type.Union([Type.Literal(...)]) generates anyOf+const schemas that are
incompatible with OpenAPI 3.03 (used by Cloud Code Assist for Claude
models via google-antigravity provider).

This caused a 400 error on claude-opus-4-6-thinking:
  tools.N.custom.input_schema: JSON schema is invalid.
  It must match JSON Schema draft 2020-12.

Replaced with Type.String({ description }) which is universally
compatible across all providers and schema formats.

Affected extensions:
- session-analytics.ts (query_type field)
- governance-profiles.ts (action field)
- safe-boot.ts (action field)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant