fix: sanitize tool schemas for strict JSON Schema validators (#13737)#13823
Open
echoVic wants to merge 1 commit intoanomalyco:devfrom
Open
fix: sanitize tool schemas for strict JSON Schema validators (#13737)#13823echoVic wants to merge 1 commit intoanomalyco:devfrom
echoVic wants to merge 1 commit intoanomalyco:devfrom
Conversation
…co#13737) Built-in tool schemas (like `question`) break on providers with strict JSON Schema validation (Codex, Vertex AI, SGLang) due to two issues: 1. Zod `.meta()` injects `$schema` and `ref` keywords that are invalid in OpenAI function parameter schemas 2. When `additionalProperties: false` is set, strict validators require ALL property keys to be in the `required` array Fix: Add universal schema sanitization in `ProviderTransform.schema()` that runs before provider-specific transforms: - Strip Zod meta fields (`$schema`, `ref`) - For strict mode objects, ensure all properties are in `required` and wrap optional ones with `anyOf: [original, {type: 'null'}]` Closes anomalyco#13737
Contributor
|
The following comment was made by an LLM, it may be inaccurate: I found a potential related PR: PR #13738: fix(provider): sanitize tool schemas for strict validators This appears to be addressing the same issue - sanitizing tool schemas for strict JSON Schema validators. Since PR #13823 is the current PR and PR #13738 has a similar title and purpose, these are likely duplicate efforts on the same problem. You may want to check if one of these PRs should be closed or if they're being developed in parallel with different approaches. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Built-in tool schemas (like
question) break on providers with strict JSON Schema validation — Codex, Vertex AI OpenAI-compatible, SGLang, etc.Two issues:
.meta()pollution: Injects$schemaandrefkeywords that are invalid in OpenAI function parameter schemasrequiredfields: WhenadditionalProperties: falseis set, strict validators require ALL property keys to be in therequiredarray. Optional fields likemultipleare missing.Error from Codex:
Fix
Add universal schema sanitization in
ProviderTransform.schema()that runs before any provider-specific transforms:$schema,ref) recursively from all schemasadditionalProperties: falseis set, ensure all property keys are inrequired. Optional properties are wrapped withanyOf: [original, {type: 'null'}]so they remain nullable while satisfying strict validators.Changes
packages/opencode/src/provider/transform.ts: AddsanitizeStrict()pass inschema()functionCloses #13737
Related: #13618, #11413, #8184