fix(anthropic): coerce explicit additionalProperties to false in output_format schema - #35811
Merged
mateo-berri merged 1 commit intoAug 6, 2026
Conversation
Contributor
Greptile SummaryThe PR updates Anthropic structured-output schema transformation to force
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains, and the previously reported comment-convention issue is fixed on the current HEAD.
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/chat/transformation.py | Always normalizes object schemas to Anthropic's required additionalProperties: false; the previously flagged production comment expansion has been fully reverted. |
| tests/litellm/llms/anthropic/test_anthropic_schema_filter.py | Adds focused regression tests covering explicit and recursively nested additionalProperties values. |
Reviews (2): Last reviewed commit: "fix(anthropic): coerce explicit addition..." | Re-trigger Greptile
…ut_format schema
Anthropic's structured outputs reject any `additionalProperties` value other
than `false` ("output_format.schema: For 'object' type, 'additionalProperties:
true' is not supported. Please set 'additionalProperties' to false")
`filter_anthropic_output_schema` only added the key when it was absent, so an
explicit `true` (or a sub-schema) was copied verbatim into output_format.schema
and 400'd. Coerce it for object schemas instead, at every recursion depth,
matching what the Anthropic Python/TypeScript SDKs do
The permissive tool-use path (map_response_format_to_anthropic_tool, used for
vertex_ai) is deliberately left alone
Fixes BerriAI#35808
dkindlund
force-pushed
the
fix/anthropic-output-format-additional-properties
branch
from
August 4, 2026 20:21
37607ad to
46751ad
Compare
Contributor
Author
|
@greptileai addressed in 46751ad — comment reverted to the original two lines, plus the other CLAUDE.md violations I'd missed (commit trailer, PR-body attribution, trailing periods). Please re-review |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
mateo-berri
approved these changes
Aug 6, 2026
mateo-berri
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Thanks for the contribution!
mateo-berri
merged commit Aug 6, 2026
c1fa151
into
BerriAI:litellm_internal_staging
77 of 78 checks passed
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.
Relevant issues
Fixes #35808
Pre-Submission checklist
ruff formatclean, target suite greenScreenshots / Proof of Fix
Root cause
Anthropic's structured outputs reject any
additionalPropertiesvalue other thanfalse. Their docs list under Supported features: "requiredandadditionalProperties(must be set tofalsefor objects)", and under Not supported: "additionalPropertiesset to anything other thanfalse"filter_anthropic_output_schemaonly added the key when it was absent:additionalPropertiesisn't in the unsupported/strip set, so an explicit value is copied verbatim by the catch-allelse: result[key] = value, and thenot in resultguard never fires. The explicit value reachesoutput_format.schemaand 400sThis PR coerces the value for object schemas instead. That is what the official SDKs do — anthropic-sdk-python
_parse/_transform.py(pop(...)thenstrict_schema["additionalProperties"] = False) and anthropic-sdk-typescripttransform-json-schema.tsThe permissive tool-use path (
map_response_format_to_anthropic_tool, which sets_input_schema["additionalProperties"] = Trueand is deliberately forced forvertex_aiper #18625 / #19201) is not touchedBefore (on
litellm_internal_staging, v1.96.0)Every explicit form leaked through — top level, nested under
properties, inside arrayitems, and the dict sub-schema form:End-to-end against a real
azure_ai/claude-sonnet-4-6deployment (un-mocked, real API call), sending a schema with"additionalProperties": true:After (commit
46751ad)All five cases clean:
Regression check on the surrounding suites (
tests/litellm/llms/anthropic/+tests/test_litellm/llms/anthropic/): 41 failed / 1218 passed with this change vs 41 failed / 1214 passed on the unmodified branch — identical pre-existing failure set, +4 new passing tests. (The pre-existing failures are unrelatedexperimental_pass_through/context_managementtests; atests/test_litellm/llms/vertex_ai/realtimecollection error is a missing localwebsocketsdep and also reproduces unmodified)Type
🐛 Bug Fix
Changes
litellm/llms/anthropic/chat/transformation.py— infilter_anthropic_output_schema, drop theand "additionalProperties" not in resultguard so object schemas always getadditionalProperties: False(applies at every recursion depth and to the dict sub-schema form)tests/litellm/llms/anthropic/test_anthropic_schema_filter.py— 4 tests: explicittrueat top level, nested (underpropertiesand inside arrayitems), the dict sub-schema form, and an explicitfalsepreservedSemantic caveat (disclosed)
Coercing narrows what the schema permits. For a bare free-form map (
{"type": "object", "additionalProperties": true}with noproperties) this means "object with no allowed keys", so the model can only emit{}— genuine semantic loss. Anthropic has no native encoding for that shape and the official SDKs degrade it identically; the alternative on this path is a guaranteed 400. A more conservative future option would be detecting that shape and routing it to the permissive tool-use path (the one already forced forvertex_ai), but that is a larger change and out of scope herePrior art
uniqueItems/contains/prefixItems/etc. but contain zeroadditionalPropertieschanges