fix(ai): strip non-standard 'optional' keyword from tool JSON schema parameters - #647
fix(ai): strip non-standard 'optional' keyword from tool JSON schema parameters#647Indosaram wants to merge 1 commit into
Conversation
tool JSON schema parameters
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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>
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.
optionalto JSON schema meta declarations to ignore it during validation.optionalfrom normalized tool schema nodes.Written for commit db8d486. Summary will update on new commits.