Skip to content

fix(bedrock): accept tool_choice="any" on the Converse adapter - #38047

Open
likalight wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
likalight:fix/bedrock-tool-choice-any
Open

fix(bedrock): accept tool_choice="any" on the Converse adapter#38047
likalight wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
likalight:fix/bedrock-tool-choice-any

Conversation

@likalight

@likalight likalight commented Aug 24, 2026

Copy link
Copy Markdown

Fixes #37980.

The bug

AmazonConverseConfig.map_tool_choice_values already maps "required" onto
Bedrock's native {any: {}}:

elif tool_choice == "required":
    return ToolChoiceValuesBlock(any={})

but the literal string "any" falls through to the terminal else and raises:

litellm.UnsupportedParamsError: Bedrock doesn't support tool_choice=any.
Supported tool_choice values=['auto', 'required', json object].

So the one name Bedrock itself uses for "call some tool" is the one name the
adapter refuses, while "required" — which silently becomes exactly that value
— is accepted. Callers coming from Anthropic's API, where any is the spelling,
hit this immediately.

The fix

Map "any" alongside "required", as suggested in the issue, and add it to the
error message — that string is the only place these accepted values are
discoverable at runtime.

elif tool_choice in ("required", "any"):
    return ToolChoiceValuesBlock(any={})

Verification

Six tests in tests/test_litellm/llms/bedrock/chat/test_bedrock_tool_choice_any.py:

  • "required" and "any" both map to {"any": {}} (parametrized, so the two
    are pinned as equivalent rather than merely both working)
  • "auto" still maps to {"auto": {}}
  • a specific-tool dict still maps to {"tool": {"name": ...}}
  • a genuinely unknown value still raises, and the message now lists 'any'
  • "none" with drop_params=True still returns None

Without the source change the parametrized "any" case fails with the issue's
exact error, so the test is confirmed to be reacting to this and nothing else.

  • tests/test_litellm/llms/bedrock/chat/: 378/378 pass
  • ruff format --check clean; ruff check on the touched source file reports
    the same 13 pre-existing findings as the base commit, none added
  • Type-discipline checker: identical counts to base on every rule (LIT001 132,
    LIT002 92, LIT006 5, LIT010 81, LIT011 43), so no budget delta

On the red code-quality check: it is not from this PR. It fails on every
PR against litellm_internal_staging right now, including ones that touch no
workflow files, because three unit shards in .github/workflows/test-unit.yml
cap the job below the startup-safety invariant. Fixed independently in #38046;
this PR needs no change for it.

`map_tool_choice_values` mapped "required" to Bedrock's native
`{any: {}}` but rejected the literal string "any" with
`UnsupportedParamsError`, so the one name Bedrock itself uses for "call
some tool" was the one name the adapter refused.

Map "any" alongside "required" and list it in the error message, which is
the only place these values are discoverable.

Fixes BerriAI#37980

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes the Bedrock Converse adapter accept tool_choice="any" as an alias of "required" and updates its supported-values error message.

  • Maps both literals to Bedrock’s native {"any": {}} tool-choice block.
  • Adds regression coverage for accepted, rejected, specific-tool, and dropped tool choices.

Confidence Score: 4/5

The PR appears safe to merge after optionally removing the redundant source comments.

The new literal follows the existing "required" mapping through the Converse request transformation, and the only accepted concern is non-blocking comment cleanup.

Files Needing Attention: litellm/llms/bedrock/chat/converse_transformation.py; tests/test_litellm/llms/bedrock/chat/test_bedrock_tool_choice_any.py

Important Files Changed

Filename Overview
litellm/llms/bedrock/chat/converse_transformation.py Correctly adds the native "any" alias and updates validation messaging, with only redundant explanatory comments needing cleanup.
tests/test_litellm/llms/bedrock/chat/test_bedrock_tool_choice_any.py Adds focused regression tests covering the changed mapping and adjacent behavior; one redundant assertion comment follows the same minor pattern.

Reviews (1): Last reviewed commit: "fix(bedrock): accept tool_choice="any" o..." | Re-trigger Greptile

Comment on lines +595 to +596
# Bedrock's native value for "call some tool" is literally `any`,
# so accepting "required" while rejecting "any" was incoherent.

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 Remove redundant mapping comments

The comments here and beside the error-message assertion in the new test restate straightforward code rather than explaining complex behavior, adding maintenance noise that can drift from the implementation.

Context Used: CLAUDE.md (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!

@codspeed-hq

codspeed-hq Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing likalight:fix/bedrock-tool-choice-any (f336bad) with litellm_internal_staging (d447be1)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (f005afa) during the generation of this report, so d447be1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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]: Bedrock adapter rejects tool_choice="any" despite Bedrock Converse API supporting it

1 participant