Skip to content

fix(bedrock): filter unsupported schema fields before Bedrock native structured-outputs API - #29624

Open
VANDRANKI wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
VANDRANKI:fix/bedrock-native-structured-outputs-drop-unsupported-schema-fields
Open

fix(bedrock): filter unsupported schema fields before Bedrock native structured-outputs API#29624
VANDRANKI wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
VANDRANKI:fix/bedrock-native-structured-outputs-drop-unsupported-schema-fields

Conversation

@VANDRANKI

Copy link
Copy Markdown
Contributor

Summary

Closes #29168.

Root cause

Bedrock's native structured-outputs API (the outputConfig.textFormat.type=json_schema path 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 / exclusiveMaximum

The direct-Anthropic path already handles this via AnthropicConfig.filter_anthropic_output_schema(), which strips these fields and appends constraint notes to the description. However, _create_output_config_for_response_format in converse_transformation.py never called this function, so schemas containing these fields were forwarded to Bedrock verbatim and caused a 400 error:

output_config.format.schema: For 'number' type, properties maximum, minimum are not supported

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_format before _add_additional_properties_to_schema. AnthropicConfig is already imported in converse_transformation.py.

Example (before fix)

response_format = {
    "type": "json_schema",
    "json_schema": {
        "name": "Score",
        "schema": {
            "type": "object",
            "properties": {
                "score": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                }
            },
            "required": ["score"],
            "additionalProperties": False
        }
    }
}
# Before: raises BedrockException 400 for minimum/maximum
# After: minimum/maximum are stripped and noted in description; Bedrock succeeds

…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.
@codspeed-hq

codspeed-hq Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing VANDRANKI:fix/bedrock-native-structured-outputs-drop-unsupported-schema-fields (a019e06) with main (5be0797)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a 400 error from Bedrock's native structured-outputs API by calling AnthropicConfig.filter_anthropic_output_schema inside _create_output_config_for_response_format before the schema is serialized into the outputConfig block. The direct-Anthropic path already applied this filter; this change brings the Bedrock Converse path into parity.

  • One-line fix: inserts json_schema = AnthropicConfig.filter_anthropic_output_schema(json_schema) before _add_additional_properties_to_schema, stripping unsupported constraints (minimum, maximum, minItems, maxItems, etc.) and appending constraint notes to description fields.
  • No new test: the specific regression scenario (schema with minimum/maximum passed to _create_output_config_for_response_format) has no dedicated test case, leaving the repaired code path without coverage.

Confidence Score: 4/5

Safe 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.

Important Files Changed

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Sameerlite

Copy link
Copy Markdown
Contributor

@VANDRANKI Can you share a video/ss of this fix working as expected. Also please add a test according to the greptile comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: LiteLLM Proxy doesn't drop 'minimum' or 'maximum' on Bedrock anymore

2 participants