fix(anthropic): sanitize unsupported JSON Schema keywords in structured output schemas#14372
Open
vigneshakaviki wants to merge 4 commits intovercel:mainfrom
Open
Conversation
Covers stripping of unsupported keywords like exclusiveMinimum, minimum, maximum, pattern, minLength, not, etc. from schemas passed to output_config.format.schema. Ref: vercel#14342
…ed output schemas Anthropic's output_config.format.schema strictly rejects validation-only JSON Schema keywords (exclusiveMinimum, minimum, maximum, not, pattern, etc.), unlike tool schemas where they are silently ignored. This caused valid Zod schemas like z.number().positive() to produce 400 errors. Add sanitizeJsonSchema() that recursively strips unsupported keywords while preserving structural and composition keywords. Fixes: vercel#14342
…ma sanitization Replace custom sanitizer with Anthropic SDK's built-in transformJSONSchema, which handles stripping unsupported keywords, moving them to description, converting oneOf to anyOf, and enforcing additionalProperties: false.
f0b8835 to
e0f5bda
Compare
…dependency Replace the re-export from @anthropic-ai/sdk with a self-contained implementation of the JSON Schema sanitizer. The logic is adapted from the SDK's transformJSONSchema but requires no external dependency. Addresses reviewer feedback to avoid adding external dependencies.
| ); | ||
| } | ||
| result['type'] = type; | ||
| } |
Contributor
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.
Summary
output_config.format.schemastrictly rejects unsupported JSON Schema keywords (exclusiveMinimum,minimum,maximum,not,pattern, etc.), unlike tool schemas where they are silently ignoredtransformJSONSchemato sanitize schemas before passing tooutput_config.format.schemadescriptionas model hints, convertingoneOftoanyOf, enforcingadditionalProperties: false, and filtering stringformatvaluesTest plan
Fixes #14342