Skip to content

fix(ai): strip non-standard 'optional' keyword from tool JSON schema parameters - #647

Open
Indosaram wants to merge 1 commit into
code-yeongyu:mainfrom
Indosaram:main
Open

fix(ai): strip non-standard 'optional' keyword from tool JSON schema parameters#647
Indosaram wants to merge 1 commit into
code-yeongyu:mainfrom
Indosaram:main

Conversation

@Indosaram

@Indosaram Indosaram commented Aug 2, 2026

Copy link
Copy Markdown

Fixes 400 Bad Request error on Gemini API and proxies (e.g. Quotio) caused by non- standard 'optional' fields inside tool parameter JSON schemas.


Summary by cubic

Strips the non-standard 'optional' field from tool parameter JSON schemas to prevent 400 Bad Request errors on Gemini API and proxies like Quotio.

  • Bug Fixes
    • Add optional to JSON schema meta declarations to ignore it during validation.
    • Remove optional from normalized tool schema nodes.

Written for commit db8d486. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/ai/src/api/google-shared.ts">

<violation number="1" location="packages/ai/src/api/google-shared.ts:285">
P2: This addition doesn't reach the code path that returns the reported 400. JSON_SCHEMA_META_DECLARATIONS is only consumed by sanitizeForOpenApi(), which is applied exclusively to the legacy `parameters` branch (useParameters=true) of convertTools(); the default Gemini path sends `parametersJsonSchema: tool.parameters` unmodified, and google-generative-ai.ts/google-vertex.ts both call convertTools(context.tools) with the default useParameters=false (no caller passes true). So an 'optional' keyword inside a Gemini tool schema is still forwarded as-is and the 400 persists. Apply the stripping to the parametersJsonSchema path (or at schema construction) to actually fix the reported issue.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

"$comment",
"$defs",
"definitions", // pre-draft-2019-09 equivalent of $defs
"optional",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This addition doesn't reach the code path that returns the reported 400. JSON_SCHEMA_META_DECLARATIONS is only consumed by sanitizeForOpenApi(), which is applied exclusively to the legacy parameters branch (useParameters=true) of convertTools(); the default Gemini path sends parametersJsonSchema: tool.parameters unmodified, and google-generative-ai.ts/google-vertex.ts both call convertTools(context.tools) with the default useParameters=false (no caller passes true). So an 'optional' keyword inside a Gemini tool schema is still forwarded as-is and the 400 persists. Apply the stripping to the parametersJsonSchema path (or at schema construction) to actually fix the reported issue.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/ai/src/api/google-shared.ts, line 285:

<comment>This addition doesn't reach the code path that returns the reported 400. JSON_SCHEMA_META_DECLARATIONS is only consumed by sanitizeForOpenApi(), which is applied exclusively to the legacy `parameters` branch (useParameters=true) of convertTools(); the default Gemini path sends `parametersJsonSchema: tool.parameters` unmodified, and google-generative-ai.ts/google-vertex.ts both call convertTools(context.tools) with the default useParameters=false (no caller passes true). So an 'optional' keyword inside a Gemini tool schema is still forwarded as-is and the 400 persists. Apply the stripping to the parametersJsonSchema path (or at schema construction) to actually fix the reported issue.</comment>

<file context>
@@ -282,6 +282,7 @@ const JSON_SCHEMA_META_DECLARATIONS = new Set([
 	"$comment",
 	"$defs",
 	"definitions", // pre-draft-2019-09 equivalent of $defs
+	"optional",
 ]);
 
</file context>

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