Repository navigation
fix(bedrock): preserve tool choice for parallel tool calls - #28508
fuchengwarrenzhu wants to merge 1 commit into
Conversation
Preserve explicit Bedrock tool_choice intent when moving parallel_tool_calls configuration into Anthropic's Bedrock extension.
|
Superseded by #28509. LiteLLM's branch guard rejects external fork PRs targeting |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR fixes a bug in Bedrock's Converse transformation where
Confidence Score: 4/5The change is well-scoped: it only activates for Claude 4.5+ on Bedrock and only when The core mapping and merge logic is correct for all combinations covered by the tests. The one gap is that The test file would benefit from an additional parametrized case for
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/chat/converse_transformation.py | Adds _map_bedrock_tool_choice_to_anthropic_tool_choice helper and uses it to inject the required Anthropic type discriminator into additionalModelRequestFields.tool_choice, then pops the Bedrock-native toolChoice from toolConfig to avoid dual-field conflicts. Logic is correct for all mapped cases. |
| tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py | Adds focused Bedrock Converse parallel-tool-calls tests; covers parallel_tool_calls=True (no explicit tool_choice) and parallel_tool_calls=False with auto/required/named-tool choices, but misses the parallel_tool_calls=True + explicit tool_choice combination. |
Reviews (1): Last reviewed commit: "Fix Bedrock parallel tool choice type" | Re-trigger Greptile
| assert "parallel_tool_calls" not in request_data["additionalModelRequestFields"] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("openai_tool_choice", "expected_anthropic_tool_choice"), | ||
| [ | ||
| ( | ||
| "auto", | ||
| {"type": "auto", "disable_parallel_tool_use": True}, | ||
| ), | ||
| ( | ||
| "required", | ||
| {"type": "any", "disable_parallel_tool_use": True}, | ||
| ), | ||
| ( | ||
| {"type": "function", "function": {"name": "get_weather"}}, | ||
| { | ||
| "type": "tool", | ||
| "name": "get_weather", | ||
| "disable_parallel_tool_use": True, | ||
| }, | ||
| ), | ||
| ], | ||
| ids=["auto", "required", "named-tool"], | ||
| ) | ||
| def test_parallel_tool_calls_moves_explicit_tool_choice_into_anthropic_extension( | ||
| openai_tool_choice, | ||
| expected_anthropic_tool_choice, | ||
| ): | ||
| """Explicit tool_choice should not conflict with Anthropic's parallel tool extension.""" | ||
| config = AmazonConverseConfig() | ||
| model = "anthropic.claude-sonnet-4-5-20250929-v1:0" | ||
| messages = [{"role": "user", "content": "What's the weather in SF and NYC?"}] | ||
|
|
||
| optional_params = config.map_openai_params( | ||
| non_default_params={ | ||
| "tools": _TOOL_PARAM, | ||
| "tool_choice": openai_tool_choice, |
There was a problem hiding this comment.
Missing coverage:
parallel_tool_calls=True + explicit tool_choice
The parametrized test exercises every explicit tool_choice value, but only with parallel_tool_calls=False. The complementary case — parallel_tool_calls=True combined with, for example, tool_choice="required" — is not tested. The expected merged output would be {"type": "any", "disable_parallel_tool_use": False} and toolChoice should again be absent from toolConfig. Without this variant, a regression in the {**anthropic_tool_choice, **value} merge when disable_parallel_tool_use is False would go undetected.
test_parallel_tool_calls_true_includes_type_field also does not assert that toolChoice is absent from toolConfig, which is the other half of the contract this PR establishes.
Relevant issues
Fixes #22637
Related stale PR: #22638
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
Focused local checks:
I did not run full
make test-unit.uv run ruff check tests/test_litellm/llms/bedrock/chat/test_converse_transformation.pycurrently reports unrelated pre-existing unused imports / print statements elsewhere in that file, so this PR keeps the lint scope to the changed source file and the focused test run.Type
🐛 Bug Fix
✅ Test
Changes
This fixes the Bedrock Claude 4.5+
parallel_tool_callsrequest shape foradditionalModelRequestFields.tool_choice.Current
mainstill creates:{"tool_choice": {"disable_parallel_tool_use": bool}}Anthropic's Bedrock extension requires a
typediscriminator, otherwise Bedrock/Anthropic rejects the request withtool_choice.type: Field required.This PR:
typeforparallel_tool_calls=Trueandparallel_tool_calls=False;tool_choiceintent whenparallel_tool_callsis also present:tool_choice="auto"->{"type": "auto", ...};tool_choice="required"->{"type": "any", ...};{"type": "tool", "name": "...", ...};toolChoicefromtoolConfigwhen that explicit choice has been moved intoadditionalModelRequestFields.tool_choice;tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py.Difference from #22638: that PR adds
type: "auto"for the base bug, but it does not preserve explicittool_choice="required"or named-tool choices when combined withparallel_tool_calls, and it is currently merge-conflicting.