Repository navigation
fix(bedrock): drop native structured output flag for Converse Sonnet 5 - #33495
larrabee-kor wants to merge 1 commit into
Conversation
AWS's Claude Sonnet 5 model card lists bedrock-runtime structured outputs as unsupported, but the six Bedrock Converse Sonnet 5 entries carried supports_native_structured_output: true in both the root and bundled backup cost maps. That flag makes AmazonConverseConfig serialize response_format=json_schema into outputConfig.textFormat, which Bedrock rejects. Setting it to false routes these ids through the existing synthetic json_tool_call fallback, matching every other non-native Bedrock model Sonnet 5 is an always-on adaptive-thinking model and Bedrock rejects forced tool use while reasoning is enabled. The synthetic fallback only skipped forcing a specific tool_choice when is_thinking_enabled was set, which the base helper derives from an explicit thinking block or reasoning_effort, so a plain Sonnet 5 request would still force the tool and fail. _translate_response_format_param now also checks _is_adaptive_thinking_model at the Converse boundary so always-on models never get a forced synthetic tool_choice Scoped to Bedrock Converse; direct Anthropic, Vertex, and Azure Sonnet 5 entries are untouched and Sonnet 4.6 keeps its native outputConfig path
Greptile SummaryThis PR fixes two related bugs scoped to Bedrock Converse Sonnet 5: an incorrect
Confidence Score: 4/5Safe to merge; the bug fix is accurate, scoped only to Bedrock Converse Sonnet 5, and covered by targeted tests that also include a positive control for Sonnet 4.6. The cost-map flag correction and the tool-choice guard are both correct and well-tested. The only notable item is a minor provider-string inconsistency in the new guard ("bedrock" vs self.custom_llm_provider which returns "bedrock_converse"); existing fallback paths in the capability lookup make it harmless today, but it diverges from the pattern used in the same if-condition. The one-line change in
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/chat/converse_transformation.py | Adds _is_adaptive_thinking_model(model, "bedrock") guard to prevent forcing tool_choice for always-on adaptive thinking models; hardcodes "bedrock" rather than using self.custom_llm_provider ("bedrock_converse") that the rest of the block uses |
| model_prices_and_context_window.json | Corrects supports_native_structured_output from true to false for all 6 Bedrock Converse Sonnet 5 entries; Bedrock-only change, non-Bedrock Sonnet 5 entries are untouched |
| litellm/model_prices_and_context_window_backup.json | Mirror of the root cost-map fix; same 6 Bedrock Sonnet 5 entries corrected to supports_native_structured_output: false |
| tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py | Adds two new tests verifying Sonnet 5 routes through synthetic tool fallback (no outputConfig) and that tool_choice is never forced; also includes a positive control confirming Sonnet 4.6 keeps native outputConfig path |
| tests/test_litellm/test_claude_sonnet_5_config.py | Adds three new tests: verifies the flag is false in both cost maps for all 6 Bedrock Sonnet 5 variants, confirms other capabilities remain intact, and checks non-Bedrock Sonnet 5 entries are unchanged |
Reviews (1): Last reviewed commit: "fix(bedrock): drop native structured out..." | Re-trigger Greptile
| if ( | ||
| litellm.utils.supports_tool_choice(model=model, custom_llm_provider=self.custom_llm_provider) | ||
| and not is_thinking_enabled | ||
| and not AnthropicConfig._is_adaptive_thinking_model(model, "bedrock") | ||
| ): |
There was a problem hiding this comment.
The
_is_adaptive_thinking_model call here hardcodes "bedrock", while self.custom_llm_provider returns "bedrock_converse" (line 131) — the same value used for supports_tool_choice two lines above. The capability lookup falls back to a raw model-map walk so this doesn't break anything today, but it's inconsistent and could miss future provider-namespaced capability entries that the cost-map lookup would catch with the correct provider string.
| if ( | |
| litellm.utils.supports_tool_choice(model=model, custom_llm_provider=self.custom_llm_provider) | |
| and not is_thinking_enabled | |
| and not AnthropicConfig._is_adaptive_thinking_model(model, "bedrock") | |
| ): | |
| if ( | |
| litellm.utils.supports_tool_choice(model=model, custom_llm_provider=self.custom_llm_provider) | |
| and not is_thinking_enabled | |
| and not AnthropicConfig._is_adaptive_thinking_model(model, self.custom_llm_provider) | |
| ): |
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! |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
|
Closing in favor of #46870, since live Bedrock calls show Sonnet 5 accepts native output and that PR keeps it while fixing the thinking drop |
Relevant issues
None filed. This corrects a capability flag that shipped alongside Sonnet 5 pricing in #31740
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
I do not have AWS Bedrock credentials for a Sonnet 5 account, so I could not capture a live before/after against a real proxy; the request-shaping below is deterministic and verifiable without a network call, and the curl afterward is the exact end to end check a maintainer with Bedrock access can run
Deterministic check of the emitted request shape, no network, run from the repo root:
On the parent commit this prints
outputConfig True | tools False | tool_choice False, i.e. the request carriesoutputConfig.textFormat, which the Sonnet 5 Converse endpoint rejects. After this PR it printsoutputConfig False | tools True | tool_choice False, i.e. the syntheticjson_tool_callfallback with no forced tool_choiceLive end to end a maintainer can run against a proxy with Bedrock access, real call and real spend:
On the parent commit this returns a Bedrock validation 400 for the unsupported
outputConfig; after this PR it returns a normal completion whosemessage.contentholds the JSON. A supported model such asbedrock/converse/us.anthropic.claude-sonnet-4-6keeps using nativeoutputConfigand is unaffectedLocal verification on this branch at commit
1d0a2f37c8:make pre-commitpasses, anduv run pytest tests/test_litellm/test_claude_sonnet_5_config.py tests/test_litellm/llms/bedrock/chat/test_converse_transformation.pyis green (180 passed), as is the fulltests/test_litellm/llms/bedrock/directory (1088 passed, 1 skipped). I did not run the entiremake test-unitacross every provider or a live Bedrock requestType
🐛 Bug Fix
Changes
Two related fixes, both scoped to Bedrock Converse Sonnet 5
The six Bedrock Converse Sonnet 5 entries (
anthropic.claude-sonnet-5plus theglobal.,us.,eu.,au.,jp.inference profiles) advertisedsupports_native_structured_output: truein bothmodel_prices_and_context_window.jsonand the bundled backup. AWS's Sonnet 5 model card lists bedrock-runtime structured outputs as unsupported, so that flag madeAmazonConverseConfig._translate_response_format_paramserializeresponse_formatintooutputConfig.textFormat, a wire shape the endpoint rejects. Both maps now set it tofalse, which routesresponse_formatthrough the existing syntheticjson_tool_callfallback like every other non-native Bedrock model. The direct Anthropic, Vertex, and Azure Sonnet 5 entries are untouched, and Sonnet 4.6 keeps its native path since it does support structured outputs on BedrockSonnet 5 is an always-on adaptive-thinking model, and Bedrock rejects forced tool use while reasoning is enabled, which is the same reason
map_openai_paramsalready downgrades an explicittool_choiceto auto. The synthetic fallback only skipped forcing a specific tool_choice whenis_thinking_enabledwas set, and the baseis_thinking_enabledhelper only sees an explicitthinkingblock orreasoning_effort, so a plain Sonnet 5 request would still force the synthetic tool and 400._translate_response_format_paramnow also checksAnthropicConfig._is_adaptive_thinking_model(model, "bedrock"), matching how the rest of this file detects always-on thinking, so those models never get a forced synthetic tool_choiceFinal Attestation