Skip to content

fix(bedrock): drop native structured output flag for Converse Sonnet 5 - #33495

Closed
larrabee-kor wants to merge 1 commit into
BerriAI:litellm_oss_daily_2026_07_15from
larrabee-kor:bedrock_sonnet5_structured_output
Closed

larrabee-kor wants to merge 1 commit into
BerriAI:litellm_oss_daily_2026_07_15from
larrabee-kor:bedrock_sonnet5_structured_output

Conversation

@larrabee-kor

@larrabee-kor larrabee-kor commented Jul 16, 2026 •

Copy link
Copy Markdown

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

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to 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:

uv run python - <<'PY'
import os, litellm
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
litellm.model_cost = litellm.get_model_cost_map(url="")
from litellm.llms.bedrock.chat.converse_transformation import AmazonConverseConfig
rf = {"type": "json_schema", "json_schema": {"name": "W", "schema": {"type": "object", "properties": {"temp": {"type": "number"}}, "required": ["temp"]}}}
out = AmazonConverseConfig().map_openai_params(
    model="bedrock/converse/us.anthropic.claude-sonnet-5",
    non_default_params={"response_format": rf}, optional_params={}, drop_params=False)
print("outputConfig", "outputConfig" in out, "| tools", "tools" in out, "| tool_choice", "tool_choice" in out)
PY

On the parent commit this prints outputConfig True | tools False | tool_choice False, i.e. the request carries outputConfig.textFormat, which the Sonnet 5 Converse endpoint rejects. After this PR it prints outputConfig False | tools True | tool_choice False, i.e. the synthetic json_tool_call fallback with no forced tool_choice

Live end to end a maintainer can run against a proxy with Bedrock access, real call and real spend:

curl http://localhost:4000/v1/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d '{
  "model": "bedrock/converse/us.anthropic.claude-sonnet-5",
  "messages": [{"role": "user", "content": "Return the temperature in SF as JSON"}],
  "response_format": {"type": "json_schema", "json_schema": {"name": "W", "schema": {"type": "object", "properties": {"temp": {"type": "number"}}, "required": ["temp"], "additionalProperties": false}}}
}'

On the parent commit this returns a Bedrock validation 400 for the unsupported outputConfig; after this PR it returns a normal completion whose message.content holds the JSON. A supported model such as bedrock/converse/us.anthropic.claude-sonnet-4-6 keeps using native outputConfig and is unaffected

Local verification on this branch at commit 1d0a2f37c8: make pre-commit passes, and uv run pytest tests/test_litellm/test_claude_sonnet_5_config.py tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py is green (180 passed), as is the full tests/test_litellm/llms/bedrock/ directory (1088 passed, 1 skipped). I did not run the entire make test-unit across every provider or a live Bedrock request

Type

🐛 Bug Fix

Changes

Two related fixes, both scoped to Bedrock Converse Sonnet 5

The six Bedrock Converse Sonnet 5 entries (anthropic.claude-sonnet-5 plus the global., us., eu., au., jp. inference profiles) advertised supports_native_structured_output: true in both model_prices_and_context_window.json and the bundled backup. AWS's Sonnet 5 model card lists bedrock-runtime structured outputs as unsupported, so that flag made AmazonConverseConfig._translate_response_format_param serialize response_format into outputConfig.textFormat, a wire shape the endpoint rejects. Both maps now set it to false, which routes response_format through the existing synthetic json_tool_call fallback 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 Bedrock

Sonnet 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_params already downgrades an explicit tool_choice to auto. The synthetic fallback only skipped forcing a specific tool_choice when is_thinking_enabled was set, and the base is_thinking_enabled helper only sees an explicit thinking block or reasoning_effort, so a plain Sonnet 5 request would still force the synthetic tool and 400. _translate_response_format_param now also checks AnthropicConfig._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_choice

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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
@CLAassistant

CLAassistant commented Jul 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two related bugs scoped to Bedrock Converse Sonnet 5: an incorrect supports_native_structured_output: true flag in both cost maps (which caused response_format to be serialised into outputConfig.textFormat, a wire shape Bedrock rejects), and a missing guard in the synthetic json_tool_call fallback that could still force a specific tool_choice on always-on adaptive-thinking models (which Bedrock also rejects while reasoning is active).

  • Six Bedrock Converse Sonnet 5 cost-map entries in both model_prices_and_context_window.json and the bundled backup have supports_native_structured_output flipped from true to false; non-Bedrock and Sonnet 4.6 entries are untouched.
  • _translate_response_format_param in converse_transformation.py now also checks AnthropicConfig._is_adaptive_thinking_model before setting a forced tool_choice, matching the pattern used elsewhere in the file.
  • New tests cover both the capability-flag values in both cost maps and the end-to-end request-shape routing for Sonnet 5 and Sonnet 4.6.

Confidence Score: 4/5

Safe 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 converse_transformation.py is the only file worth a second glance — specifically the hardcoded "bedrock" provider string vs self.custom_llm_provider.

Important Files Changed

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

Comment on lines 1049 to 1053
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")
):

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

Suggested change
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

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the stale label Oct 15, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

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

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants