Skip to content

fix(bedrock): retry without strict when Bedrock rejects strict tool schemas under drop_params - #47755

Closed
mateo-berri wants to merge 1 commit into
mainfrom
litellm_bedrock_strict_tools_drop_params
Closed

mateo-berri wants to merge 1 commit into
mainfrom
litellm_bedrock_strict_tools_drop_params

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Since v1.90.0, litellm forwards strict on 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.0

With drop_params: true, litellm now sends the request again once without strict when Bedrock rejects the strict tool schemas. Without drop_params, Bedrock's 400 still reaches the caller, so nothing changes for anyone who wants strict enforced

Original

TLDR

Problem this solves:

  • Bedrock Claude rejects big or complex strict tool sets with 400
  • drop_params: true did not help, the 400 still came back
  • Same request works on the Anthropic API and on v1.89.7

How it solves it:

  • On a strict-schema 400, send once more without strict
  • Only under drop_params, otherwise the 400 reaches the caller
  • Reuses the Converse retry that native structured output already has

Decisions

The retry keys on Bedrock's error text, a 400 that says "strict tools", "grammar", or "compilation", or that starts with tools.N.custom: or tools.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 only strict and keeps additionalProperties and every other tool field, since only strict turns these checks on

Turning 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_params was rejected because litellm drops an unsupported param only under drop_params and answers the provider's 400 without it

When 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: true

  1. The proxy admin sets drop_params: true on a bedrock/us.anthropic.claude-sonnet-4-6 deployment
  2. The agent sends POST http://localhost:4000/v1/chat/completions with 25 function tools marked "strict": true
  3. The proxy answers 400 Too many strict tools (25). The maximum number of strict tools supported is 20 (12 bigger tools give The compiled grammar is too large, an untyped property gives Schema type is missing)

After: the same request comes back 200 with a tool call

  1. The proxy admin sets drop_params: true on a bedrock/us.anthropic.claude-sonnet-4-6 deployment
  2. The agent sends POST http://localhost:4000/v1/chat/completions with 25 function tools marked "strict": true
  3. The proxy answers 200 with a lookup_record_0 tool call
  4. On a deployment without drop_params, the same request still answers the same 400

Relevant issues

Fixes #34388 for deployments with drop_params: true

Supersedes #41857, #39115, #35617, and #34609

Affected release

Regression in v1.90.0 (#29814 started forwarding strict to Converse)

Linear ticket

Resolves LIT-8134

Pre-Submission checklist

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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays 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

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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_params is true, a matching 400 triggers one automatic retry with strict stripped from function tools while leaving other tool fields intact. Without drop_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.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@kerry-berri

kerry-berri commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

litellm-stampbot: risk high

Not approved at 2523b71. risk is high, a human reviewer is needed.

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Cursor Bugbot: Medium Risk at 2523b71. 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. Bugbot run requested, finished in 2 min.
Bugbot Low is low, Medium and High are high. The judge model was not called.

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

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.

✅ 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.

@kerry-berri kerry-berri added the risk:high Sensitive, broad, or high-risk change label Oct 21, 2026
@codspeed

codspeed Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 34 untouched benchmarks


Comparing litellm_bedrock_strict_tools_drop_params (2523b71) with main (f768fb3)1

Open in CodSpeed

Footnotes

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

@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor Author

Superseded by #47760, which carries this same fix after a test-only opening commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:high Sensitive, broad, or high-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LiteLLM forwards unsupported strict tool fields to Bedrock Claude models, causing 400 errors and hanging requests

2 participants