Skip to content

fix(bedrock): preserve tool choice for parallel tool calls - #28617

Closed
fuchengwarrenzhu wants to merge 6 commits into
BerriAI:litellm_010626from
fuchengwarrenzhu:fix/bedrock-parallel-tool-choice-type-oss
Closed

fuchengwarrenzhu wants to merge 6 commits into
BerriAI:litellm_010626from
fuchengwarrenzhu:fix/bedrock-parallel-tool-choice-type-oss

Conversation

@fuchengwarrenzhu

@fuchengwarrenzhu fuchengwarrenzhu commented May 22, 2026 •

Copy link
Copy Markdown

Relevant issues

Fixes #22637

Related stale PR: #22638

Replaces #28509, which became unreopenable after the temporary shin_agent_oss_staging_05_21_2026 base branch was deleted.

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added testing in the tests/test_litellm/ directory, adding at least 1 test is a hard requirement - see details
  • My PR passes the focused unit tests for this change
  • This PR scope is isolated to the Bedrock tool-choice bug and the CI compatibility fixes needed for the current LiteLLM test suite
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Screenshots / Proof of Fix

Terminal proof for Bedrock parallel tool choice fix

The terminal proof compares the contribution base (base_*) with this PR head (head_*). The base request is rejected because additionalModelRequestFields.tool_choice.type is missing and toolConfig.toolChoice is still present. The PR head request succeeds with {"disable_parallel_tool_use": false, "name": "get_weather", "type": "tool"} and no duplicate toolConfig.toolChoice entry.

Type

Bug Fix
Test

Changes

This fixes the Bedrock Claude 4.5+ parallel_tool_calls request shape for additionalModelRequestFields.tool_choice.

Current upstream code on the contribution base still creates:

{"tool_choice": {"disable_parallel_tool_use": bool}}

The Anthropic Bedrock extension requires a type discriminator. Without it, Bedrock rejects the request with tool_choice.type: Field required.

This PR:

  • adds the missing Anthropic type for parallel_tool_calls=True and parallel_tool_calls=False;
  • preserves explicit caller tool_choice intent when parallel_tool_calls is also present:
    • tool_choice="auto" -> {"type": "auto", ...};
    • tool_choice="required" -> {"type": "any", ...};
    • named tool choice -> {"type": "tool", "name": "...", ...};
  • removes the duplicate Bedrock-native toolConfig.toolChoice when that explicit choice has been moved into additionalModelRequestFields.tool_choice;
  • adds focused Bedrock Converse transformation tests.

Difference from #22638: that PR adds type: "auto" for the base bug, but it does not preserve explicit tool_choice="required" or named-tool choices when combined with parallel_tool_calls, and it is currently merge-conflicting.

This PR also keeps current LiteLLM CI green by:

  • adding budget_exceeded to the Google Interactions OpenAPI Interaction.status expectation, matching the live spec;
  • adding libatomic to the non-root Dockerfile package lists required by Prisma Node binaries.

Testing

  • UV_CACHE_DIR=/private/tmp/uv-cache-litellm uv run --no-sync pytest tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py -k parallel_tool_calls -q -> 9 passed, 119 deselected
  • UV_CACHE_DIR=/private/tmp/uv-cache-litellm uv run --no-sync pytest tests/test_litellm/interactions/test_openapi_compliance.py -q -> 13 passed
  • UV_CACHE_DIR=/private/tmp/uv-cache-litellm uv run --no-sync black --check litellm/llms/bedrock/chat/converse_transformation.py tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py -> 2 files would be left unchanged
  • UV_CACHE_DIR=/private/tmp/uv-cache-litellm uv run --no-sync ruff check litellm/llms/bedrock/chat/converse_transformation.py -> All checks passed
  • git diff --check -> passed

Preserve explicit Bedrock tool_choice intent when moving parallel_tool_calls
configuration into Anthropic's Bedrock extension.
@fuchengwarrenzhu

Copy link
Copy Markdown
Author

@greptileai

@codecov

codecov Bot commented May 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...tellm/llms/bedrock/chat/converse_transformation.py 88.23% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes the Bedrock Converse transformation for parallel_tool_calls by adding the missing Anthropic type discriminator to additionalModelRequestFields.tool_choice and preserving the caller's explicit tool_choice intent when both parameters appear together. It also removes the now-redundant toolConfig.toolChoice in that code path, and includes three unrelated CI fixes (OpenAPI spec enum update, Dockerfile libatomic dependency).

  • converse_transformation.py: Introduces _map_bedrock_tool_choice_to_anthropic_tool_choice to convert the Bedrock ToolChoiceValuesBlock into the Anthropic {"type": "auto|any|tool", ...} shape, then merges it with {"disable_parallel_tool_use": bool} before writing to additionalModelRequestFields.tool_choice. The early inference_params.pop("tool_choice") correctly prevents the same choice from also appearing in toolConfig.toolChoice.
  • test_converse_transformation.py: Extends the existing test to assert type == "auto", adds a parallel_tool_calls=True test, and adds a parametrised matrix covering auto, required, and named-tool choices with both parallel_tool_calls values.
  • docker/Dockerfile.non_root / test_openapi_compliance.py: Two unrelated CI fixes bundled into this replacement PR.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to Claude 4.5+ Bedrock models when parallel_tool_calls is set, the transformation logic is correct, and the new tests cover all branching paths including explicit tool choices.

The core fix correctly pops tool_choice from inference_params before the toolConfig builder runs, preventing the duplicate toolChoice in toolConfig. The _map_bedrock_tool_choice_to_anthropic_tool_choice helper correctly maps all three Bedrock ToolChoiceValuesBlock variants (auto, any, tool) to their Anthropic equivalents, and the merge order {**anthropic_tool_choice, **value} keeps the type/name fields intact while letting disable_parallel_tool_use append cleanly. Models that are not Claude 4.5+ on Bedrock are completely unaffected.

No files require special attention.

Important Files Changed

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; pops tool_choice from inference_params early so it is not redundantly placed in toolConfig.toolChoice.
tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py Strengthens existing test to assert the new type field, and adds two new test cases: one for parallel_tool_calls=True and a parametrised matrix covering all three explicit tool_choice modes with both parallel_tool_calls values.
tests/test_litellm/interactions/test_openapi_compliance.py Adds budget_exceeded to the expected status enum list to match the updated live Google Interactions OpenAPI spec, fixing an unrelated CI failure.
docker/Dockerfile.non_root Adds libatomic to both the builder and runtime apk add stages to satisfy Prisma's Node binary libatomic.so.1 dependency on Wolfi/Alpine.

Reviews (1): Last reviewed commit: "Cover explicit tool choice with parallel..." | Re-trigger Greptile

@greptile-apps

greptile-apps Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes Bedrock Claude 4.5+ requests that were rejected when parallel_tool_calls was combined with an explicit tool_choice, because the additionalModelRequestFields.tool_choice object was missing the type discriminator required by Anthropic's Bedrock extension. It also removes the now-redundant toolConfig.toolChoice entry when the caller's intent has been folded into the Anthropic extension field.

  • Adds _map_bedrock_tool_choice_to_anthropic_tool_choice to translate the Bedrock-native ToolChoiceValuesBlock into Anthropic's {\"type\": ...} shape, covering auto, any/required, and named-tool cases.
  • Merges the resolved Anthropic type into _parallel_tool_use_config's tool_choice dict before writing it to additionalModelRequestFields, and pops tool_choice from inference_params so it does not also appear in toolConfig.toolChoice.
  • Ships focused unit tests for parallel_tool_calls=True/False with and without explicit tool_choice, plus updates the Google Interactions OpenAPI compliance expectation and adds libatomic to the non-root Dockerfile.

Confidence Score: 4/5

Safe to merge — the change is narrowly scoped to the Claude 4.5+ parallel-tool-calls path on Bedrock, older models are unaffected, and the transformation logic is covered by new unit tests.

The core transformation is straightforward: a new helper maps the Bedrock ToolChoiceValuesBlock to the Anthropic type discriminator, and the merge order ({**anthropic_tool_choice, **value}) is correct because the parallel_tool_use_config value only carries disable_parallel_tool_use and never a competing type key. The pop at transform time correctly prevents tool_choice from also landing in toolConfig.toolChoice. One minor scenario worth awareness: if a caller somehow constructs a SpecificToolChoiceBlock with an empty name, the mapper returns {"type": "tool"} without a name field, which Anthropic may reject — but that path requires invalid upstream input and is already a latent issue in map_tool_choice_values.

converse_transformation.py deserves a final read-through, specifically the interaction between the new inference_params.pop("tool_choice") at line 1262 and the existing pop at line 1540 — both are correct but easy to misread during future refactors.

Important Files Changed

Filename Overview
litellm/llms/bedrock/chat/converse_transformation.py Adds _map_bedrock_tool_choice_to_anthropic_tool_choice helper and wires it into the parallel_tool_calls path to inject the required Anthropic type discriminator; pops tool_choice from inference_params so it doesn't also land in toolConfig.toolChoice.
tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py Strengthens existing parallel-tool-calls test with a type assertion and adds two new pure unit tests covering parallel_tool_calls=True and all explicit tool_choice/parallel_tool_calls combinations; no real network calls.
tests/test_litellm/interactions/test_openapi_compliance.py Adds budget_exceeded to expected Interaction.status enum to match the upstream Google Interactions OpenAPI spec change; pre-existing test that fetches the live spec.
docker/Dockerfile.non_root Adds libatomic to both the builder and runtime Alpine/Wolfi package lists to satisfy Prisma's Node binary dependency.

Reviews (2): Last reviewed commit: "Cover explicit tool choice with parallel..." | Re-trigger Greptile

@ghost

ghost commented May 22, 2026

Copy link
Copy Markdown

🤖 litellm-agent: This PR is currently BLOCKED from merge.

Score: 3/5 ❌

Why blocked:

  • 1 PR-related CI failure (This PR will be auto-closed as it lacks a screenshot for proof of fix. Please include one in the PR description. Add the screenshot-exempt label if this PR has no visible output (e.g. pure docs, CI config).) (pr_related_failures, -2 pts)

Details: Score docked for: 1 PR-related CI failure (This PR will be auto-closed as it lacks a screenshot for proof of fix. Please include one in the PR description. Add the screenshot-exempt label if this PR has no visible output (e.g. pure docs, CI config).).

Fix the issues above and push an update — the bot will re-review automatically.

Note: This bot is still in beta and might not always work as expected. Please share any feedback via Slack.

@fuchengwarrenzhu

Copy link
Copy Markdown
Author

@litellm-bot review — current head 5e7b39e915262e1a7d98b2b16f1b074a513b99c3 is green on GitHub Actions, mergeStateStatus is CLEAN, Greptile has a 4/5 safe-to-merge review, and the PR body includes PNG proof of fix. The latest Phase B triage appears blocked because coverage_gap timed out waiting for an agent response, not because of a concrete code finding. Please rerun Karpathy / security / coverage-gap review for the current head.

@Sameerlite
Sameerlite changed the base branch from litellm_oss_staging to litellm_010626 June 1, 2026 10:54
done && \
for i in 1 2 3; do \
apk add --no-cache python3 bash openssl tzdata libsndfile nodejs && break || sleep 5; \
apk add --no-cache python3 bash openssl tzdata libsndfile libatomic nodejs && break || sleep 5; \

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.

Why do we need this?

@mateo-berri
mateo-berri deleted the branch BerriAI:litellm_010626 June 2, 2026 04:42
@mateo-berri mateo-berri closed this Jun 2, 2026
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.

3 participants