Repository navigation
fix(bedrock): stop naming typed tools on Bedrock invoke /v1/messages so toolset entries reach Claude - #51756
Conversation
…so toolset entries reach Claude A computer_toolset or browser_toolset entry carries no name, and Bedrock refuses any name on one, so the placeholder name LiteLLM added for nameless tools turned every toolset request into a 400. Only custom tools get the placeholder now. Typed tools pass through as the caller sent them.
[Medium impact] The PR appears safe to merge, with both previous findings addressed and no new actionable issues.
|
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
bugbot run |
|
bugbot run |
|
Closed to free an open-PR slot. Branch kept, and it reopens for final CI and bot reviews once ready |
…ges_toolset_no_name
…essages transform Main now serves Bedrock invoke /v1/messages from Rust, whose port of ensure_bedrock_anthropic_messages_tool_names still named every unnamed tool, so toolset entries kept getting litellm_unnamed_tool_N and Bedrock answered 400
…ges_toolset_no_name
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 009fe7b. Configure here.
Hand-ported from 310c961 (BerriAI#48893), which is not on lts/1.108.x. Only the _TOOL_ITEMS_ADAPTER and _is_str_keyed_dict helpers and the TypeIs import come over, since the backport of BerriAI#51756 calls them. No behavior changes on its own.
Handwritten 1-3 sentence description
Computer use and browser use with Claude on Bedrock Invoke failed on every request, because the gateway gave those tools a placeholder name that Bedrock refuses. Now only custom tools sent without a name get one, so the same request that works against Anthropic works against Bedrock Invoke too
Details
TLDR
Problem this solves:
/v1/messagesanswer 400How it solves it:
User Flow
Before: a developer running a computer-use agent on Claude through Bedrock gets a 400 on the first request
bedrock/invoke/Claude model with"tools": [{"type": "computer_toolset_20260801"}](or the browser toolset), streaming or notname is not accepted on a toolset entry, and the agent never startsAfter: the same request reaches Claude, and the agent loop runs
tool_useblock namedscreenshotcarryingtoolset_name: computer(orbrowser)tool_resultand get 200 with Claude's answer about the screenPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Last updated: 009fe7b. QA ran on 639b9a2, after main was merged in, since main now sends both Mantle routes through the Invoke Rust transform. Changes since QA: one Rust test attribute. Proof remains valid because no shipped code changed. Verification: the targeted cargo tests pass
Setup shared by both legs. Each leg is a proxy with 2 workers and no database, started with
litellm --config config.yaml --port $PORT --num_workers 2, using AWS credentials for a Bedrock account in us-east-1 andLITELLM_MASTER_KEY. Before runs the merge baseconfig.yaml
blue_screen.b64holds a 64x40 solid blue PNG, which every case uses as the screenshotThe SDK loop case runs the computer toolset helper from
@anthropic-ai/sdk1.13.0, the latest release, on Node 24.19.0, with the tool runner's defaults. Itsscreenshotmember returns the blue PNG. Install the SDK in an emptysdkdirectory, then saveblue_screen.b64andloop.mjstherenpm init -y && npm install @anthropic-ai/sdk@1.13.0loop.mjs
screenshotscreenshotscreenshotscreenshotbedrock/route, computer toolsetscreenshotbedrock/mantle/computer toolsetscreenshotbedrock_mantle/computer toolsetscreenshotbedrock/mantle/second turnbash, unnamed custom tooltool_usebedrock/mantle/custom tool, no namebash_20250124without a nameField requiredsecond_turn.jsonholds the second turn request below, andsecond_turn_mantle.jsonis the same with"model": "mantle-opus"second_turn.json
{"model": "bedrock-claude-sonnet-5-5", "max_tokens": 256, "tools": [{"type": "computer_toolset_20260801"}], "messages": [{"role": "user", "content": "Take a screenshot, then tell me in one sentence what color the screen is."}, {"role": "assistant", "content": [{"type": "tool_use", "id": "toolu_01QaSecondTurnShot0001", "name": "screenshot", "input": {}, "toolset_name": "computer"}]}, {"role": "user", "content": [{"type": "tool_result", "tool_use_id": "toolu_01QaSecondTurnShot0001", "toolset_name": "computer", "content": [{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "iVBORw0KGgoAAAANSUhEUgAAAEAAAAAoCAIAAADBrGu+AAAASElEQVR4nO3PQQ0AIBDAsAP/nkEEj4ZkVbCtmTM/2zrgVQNaA1oDWgNaA1oDWgNaA1oDWgNaA1oDWgNaA1oDWgNaA1oDWgPaBd1BAU+De5MHAAAAAElFTkSuQmCC"}}]}]}]}Sent straight to Bedrock, the same requests get the After answers, and the placeholder name alone causes the 400
Bedrock called directly, results, commands and output
Field requiredbash_20250124without a nameField requiredBefore (b4419fc)
Anthropic SDK computer toolset loop
sdkdirectoryComputer and browser toolsets
Commands and output
Second turn with the screenshot
Commands and output
Other Bedrock routes
Commands and output
bedrock/route, computer toolsetbedrock/mantle/computer toolsetbedrock_mantle/computer toolsetbedrock/mantle/second turnTools that need or keep a name
Commands and output
bashnamedbash, and a custom tool without a namebedrock/mantle/custom tool sent without a namebash_20250124sent without a nameAfter (639b9a2)
Anthropic SDK computer toolset loop
sdkdirectoryComputer and browser toolsets
Commands and output
Second turn with the screenshot
Commands and output
Other Bedrock routes
Commands and output
bedrock/route, computer toolsetbedrock/mantle/computer toolsetbedrock_mantle/computer toolsetbedrock/mantle/second turnTools that need or keep a name
Commands and output
bashnamedbash, and a custom tool without a namebedrock/mantle/custom tool sent without a namebash_20250124sent without a nameNotes from the QA run
bash_20250124still answers 400Field requiredType
🐛 Bug Fix
Caveats (if any)
High
/v1/messagesrequest that goes through a pre-call guardrail, or tobedrock/converse/, still turns a toolset into an empty custom tool namedlitellm_unnamed_tool_NLow
/chat/completionsstill can't take a toolset for Claude on Bedrock InvokeFinal Attestation
Decisions
type, ortype: "custom"). The alternatives were skipping only*_toolset_*types, which would still put a wrong name on a dated tool likebash_20250124(Bedrock wants exactlybashthere), or filling each dated tool's fixed name, which needs a type-to-name map that drifts and is a feature nobody asked for. A typed tool without a name now reaches Bedrock as sent, so Bedrock's own error names the missing field, the same as Anthropic/v1/messagesfrom the Rust transform, and the Python bridge runs the Python helper on the tools first. So both copies change, since either one alone still names the toolset and the route still answers 400. Both Mantle routes share that Rust transform, so the same change fixes themBugbot summary