Repository navigation
fix(bedrock): retry without strict when Bedrock rejects strict tool schemas under drop_params - #47755
mateo-berri wants to merge 1 commit into
Conversation
…chemas under drop_params
|
@litellm-stampbot |
litellm-stampbot: risk highNot approved at Rules (
Cursor Bugbot: Medium Risk at Pushes do not re-run this check. Comment |
|
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 2523b71. Configure here.
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Superseded by #47760, which carries this same fix after a test-only opening commit |
Since v1.90.0, litellm forwards
stricton Bedrock Converse tools, so Bedrock now holds every strict tool to Claude's strict-schema rules. Agents that mark many or complex tools as strict get a 400 on Bedrock (compiled grammar too large, too many strict tools, schema type missing, and similar) for requests that work on the Anthropic API and worked on Bedrock before v1.90.0With
drop_params: true, litellm now sends the request again once withoutstrictwhen Bedrock rejects the strict tool schemas. Withoutdrop_params, Bedrock's 400 still reaches the caller, so nothing changes for anyone who wants strict enforcedOriginal
TLDR
Problem this solves:
drop_params: truedid not help, the 400 still came backHow it solves it:
strictdrop_params, otherwise the 400 reaches the callerDecisions
The retry keys on Bedrock's error text, a 400 that says "strict tools", "grammar", or "compilation", or that starts with
tools.N.custom:ortools.N.custom.strict:. Every strict-only rejection we saw live on Sonnet 4.6 or found quoted in #34388 matches one of those, and each request returned 200 without strict. The retry drops onlystrictand keepsadditionalPropertiesand every other tool field, since onlystrictturns these checks onTurning strict off per model, as #41857 did for Sonnet 4.6, was rejected. Sonnet 4.6 accepts strict up to the limits, and Sonnet 4.5, Haiku 4.5, and Opus 4.6 hit the same limits, so a per-model flag would take working strict away from some users and still miss others. Checking the documented limits (20 strict tools, 24 optional params, 16 union-typed params) before sending was rejected too, since the grammar size limit has no published number and the limits are Anthropic's to change. A retry without
drop_paramswas rejected because litellm drops an unsupported param only underdrop_paramsand answers the provider's 400 without itWhen a request has both, the existing native structured output fallback goes first, so its behavior does not change
User Flow
Before: an agent with many strict tools on a Bedrock Claude deployment gets a 400, even with
drop_params: truedrop_params: trueon abedrock/us.anthropic.claude-sonnet-4-6deployment"strict": trueToo many strict tools (25). The maximum number of strict tools supported is 20(12 bigger tools giveThe compiled grammar is too large, an untyped property givesSchema type is missing)After: the same request comes back 200 with a tool call
drop_params: trueon abedrock/us.anthropic.claude-sonnet-4-6deployment"strict": truelookup_record_0tool calldrop_params, the same request still answers the same 400Relevant issues
Fixes #34388 for deployments with
drop_params: trueSupersedes #41857, #39115, #35617, and #34609
Affected release
Regression in v1.90.0 (#29814 started forwarding
strictto Converse)Linear ticket
Resolves LIT-8134
Pre-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).
Type
🐛 Bug Fix
Final Attestation
Note
Medium Risk
Changes Bedrock Converse request retry behavior for tool-calling under drop_params; wrong error matching could hide real 400s or retry when not intended, though scope is limited to one retry and strict-only param changes.
Overview
Fixes Bedrock Converse failures when Claude rejects strict tool schemas (too many strict tools, grammar/compilation limits, invalid strict schemas) after v1.90.0 started forwarding
strict.When
drop_paramsis true, a matching 400 triggers one automatic retry withstrictstripped from function tools while leaving other tool fields intact. Withoutdrop_params, the provider error is unchanged. The retry plugs into the existing Converse fallback helper alongside native structured-output retry (native output still wins when both apply).Detection keys off Bedrock error text (
strict tools,grammar,compilation,tools.N.custom:patterns). Tests cover fallback building, sync/async retry behavior, and end-to-end Converse requests.Reviewed by Cursor Bugbot for commit 2523b71. Bugbot is set up for automated code reviews on this repo. Configure here.