feat(anthropic): sanitize the unsupported JSON schema validation properties#14790
Open
aayush-kapoor wants to merge 3 commits intomainfrom
Open
feat(anthropic): sanitize the unsupported JSON schema validation properties#14790aayush-kapoor wants to merge 3 commits intomainfrom
aayush-kapoor wants to merge 3 commits intomainfrom
Conversation
This was referenced Apr 28, 2026
gr2m
approved these changes
Apr 28, 2026
|
|
||
| return descriptions.length === 0 | ||
| ? undefined | ||
| : `Additional constraints: ${descriptions.join('; ')}.`; |
Collaborator
There was a problem hiding this comment.
I don't think it's a problem in this case, but made me think if this is a form of prompt altering that we are trying to stay out of. Also using English while a the rest of the prompt might be potentially a different language. I'm sure language model can handle it, curious what you think
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.
Background
#13355 & #14342
Anthropic rejects certain schema validation properties (documented here)
When those properties are passed through for structured output definitions (not for tool definitions), Anthropic returns a 400 error.
Summary
Introduce a
sanitize-json-schema.tsfile that strips the rejected properties, defined in a set.However to ensure full validation, the schema is then converted to a simple string and passed through as
description()Manual Verification
verified by running the examples:
examples/ai-functions/src/generate-text/anthropic/output-object-zod-positive-number.tsexamples/ai-functions/src/generate-text/anthropic/output-object-zod.tsfailed before the fix and worked (and respected the constraint if any) after the fix
Checklist
pnpm changesetin the project root)Related Issues
fixes #13355 and #14342