fix(bedrock): filter unsupported schema fields before Bedrock native structured-outputs API - #29624
Conversation
…ve structured outputs API Fixes BerriAI#29168. Bedrock's native structured-outputs API rejects JSON schema properties that Anthropic Claude does not support: minimum, maximum, minItems, maxItems, minLength, maxLength, exclusiveMinimum, exclusiveMaximum. AnthropicConfig.filter_anthropic_output_schema() already implements this filtering for the direct Anthropic API path, but _create_output_config_for_response_format in converse_transformation.py never called it, causing Bedrock to return a 400 for schemas containing these properties. Fix: call filter_anthropic_output_schema before _add_additional_properties_to_schema in _create_output_config_for_response_format so the schema is cleaned before being serialized into the outputConfig block.
Greptile SummaryThis PR fixes a 400 error from Bedrock's native structured-outputs API by calling
Confidence Score: 4/5Safe to merge; the one-line change correctly reuses an existing, well-tested helper and the ordering (filter then normalize) is sound. The change is minimal and correct: filtering unsupported fields before serializing the schema is the right fix, and filter_anthropic_output_schema is already exercised by its own unit tests. The only gap is that no new test covers the specific minimum/maximum case through _create_output_config_for_response_format, so a future refactor could silently break the same path again. litellm/llms/bedrock/chat/converse_transformation.py — the fixed function lacks a dedicated regression test for constrained numeric/array/string schemas.
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/chat/converse_transformation.py | Adds one line calling AnthropicConfig.filter_anthropic_output_schema before schema normalization in _create_output_config_for_response_format; fix is correct but no regression test for the specific minimum/maximum scenario is included. |
Reviews (1): Last reviewed commit: "fix(bedrock): filter unsupported schema ..." | Re-trigger Greptile
| } | ||
| """ | ||
| if json_schema is not None: | ||
| json_schema = AnthropicConfig.filter_anthropic_output_schema(json_schema) |
There was a problem hiding this comment.
Missing test for the fixed regression
The PR fixes a real 400-error path but ships no test for _create_output_config_for_response_format with a schema containing minimum/maximum (or any of the other newly-stripped fields). Existing tests in test_converse_transformation.py only cover clean schemas, so this scenario remains uncovered. A test mirroring the PR's own example (a score property with minimum: 0, maximum: 1) would verify that after the fix the fields are stripped and a Note: description is injected, and prevent future regressions on this path.
Rule Used: What: Ensure that any PR claiming to fix an issue ... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@VANDRANKI Can you share a video/ss of this fix working as expected. Also please add a test according to the greptile comment |
Summary
Closes #29168.
Root cause
Bedrock's native structured-outputs API (the
outputConfig.textFormat.type=json_schemapath introduced for Claude 3.7+) rejects JSON schema properties that Anthropic Claude does not support:minimum/maximum(numeric constraints)minItems/maxItems(array constraints)minLength/maxLength(string constraints)exclusiveMinimum/exclusiveMaximumThe direct-Anthropic path already handles this via
AnthropicConfig.filter_anthropic_output_schema(), which strips these fields and appends constraint notes to thedescription. However,_create_output_config_for_response_formatinconverse_transformation.pynever called this function, so schemas containing these fields were forwarded to Bedrock verbatim and caused a 400 error:This was a regression from v1.81.9, which used a synthetic-tool-call fallback for structured outputs. That path does not pass the schema to the native API, so it silently accepted the fields. After the Bedrock native structured-outputs path was introduced, the schema validation became strict.
Fix
Call
AnthropicConfig.filter_anthropic_output_schema(json_schema)inside_create_output_config_for_response_formatbefore_add_additional_properties_to_schema.AnthropicConfigis already imported inconverse_transformation.py.Example (before fix)