Skip to content

fix(bedrock): drop toolSpec.strict for Haiku 4.5 and Sonnet 4.6 on Converse - #34609

Closed
baiyuxi930826 wants to merge 1 commit into
BerriAI:mainfrom
baiyuxi930826:fix/bedrock-strict-haiku45-sonnet46
Closed

baiyuxi930826 wants to merge 1 commit into
BerriAI:mainfrom
baiyuxi930826:fix/bedrock-strict-haiku45-sonnet46

Conversation

@baiyuxi930826

Copy link
Copy Markdown

Summary

  • Set bedrock_converse_supports_strict_tools: false for all bedrock_converse cost-map entries of Claude Haiku 4.5 and Sonnet 4.6 (regional prefixes included).
  • Extend the existing Bedrock Converse strict-tools regression suite so those models drop toolSpec.strict / additionalProperties like Opus 4.7/4.8 and Sonnet 4.
  • Leaves Sonnet 4.5 / older Opus paths that still accept strict unchanged.

Context

Fixes #34388

PydanticAI/MCP tool definitions often set strict: true. Since LiteLLM began forwarding strict to Bedrock Converse, Haiku 4.5 / Sonnet 4.6 can hit compiled-grammar limits or hang until gateway timeout. The same cost-map gate already exists for Opus 4.7/4.8 (#31923) and Sonnet 4 (#31943). Sonnet 5 is covered by separate open PRs — this change does not re-implement those.

Test plan

  • Local: pytest -q tests/test_litellm/litellm_core_utils/prompt_templates/test_bedrock_converse_strict_tools_opus_47_48.py → 39 passed
  • Helper smoke: bedrock_converse_supports_strict_tools is False for Haiku 4.5 / Sonnet 4.6 and True for Sonnet 4.5
  • CI: full upstream suite on this PR

@greptile-apps

greptile-apps Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Too many files changed for review. (143 files found, 100 file limit)

Bypass the limit by tagging @greptile-apps to review.

@CLAassistant

CLAassistant commented Jul 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

…nverse

Bedrock Converse rejects or mishandles toolSpec.strict for Claude Haiku 4.5
and Sonnet 4.6 (compiled-grammar hangs / invalid fields), matching the
pattern already applied for Opus 4.7/4.8 and Sonnet 4.

Set bedrock_converse_supports_strict_tools: false on all bedrock_converse
cost-map entries for those model IDs and extend the regression suite.

Fixes BerriAI#34388

Why: Keep MCP/PydanticAI strict tool definitions from breaking Bedrock proxy
calls on newly shipped Claude model IDs.
@baiyuxi930826
baiyuxi930826 force-pushed the fix/bedrock-strict-haiku45-sonnet46 branch from 0049359 to 7623032 Compare July 25, 2026 07:23
@baiyuxi930826
baiyuxi930826 changed the base branch from main to litellm_internal_staging July 25, 2026 07:23
if prisma_client is None:
return None
try:
db_file = await ManagedFileRepository(prisma_client).table.find_first(where={"unified_file_id": input_file_id})

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.

High: Managed file ownership bypass

This lookup resolves any supplied unified file ID without checking created_by or team_id. An authenticated user who obtains another tenant's file ID can submit it as batch input; replacing the opaque ID with its storage_url bypasses the managed-files hook where can_user_call_unified_file_id() enforces ownership, allowing the attacker to process that file and retrieve the resulting batch output. Pass user_api_key_dict into this helper and enforce the same user/team/admin access check before returning the URL.

consumed_count = await cache.async_increment_cache(
key=consumed_key, value=1, ttl=SAMLAuthHandler._replay_guard_ttl(auth)
)
if consumed_count is not None and consumed_count > 1:

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.

Medium: SAML replay protection fails open

DualCache.async_increment_cache() returns None when Redis fails, but this condition accepts the assertion. During a Redis outage, an attacker with a captured unsolicited signed assertion can replay it against another worker whose in-memory counter has not seen it and obtain a new UI session; fail closed whenever the shared atomic replay check cannot complete.

Suggested change
if consumed_count is not None and consumed_count > 1:
if consumed_count is None:
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail="SAML replay protection is unavailable.",
)
if consumed_count > 1:

@veria-ai

veria-ai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

PR overview

This PR adjusts Bedrock Converse handling to omit toolSpec.strict for Haiku 4.5 and Sonnet 4.6.

Two security issues remain open. An authenticated user who knows another tenant’s file ID can bypass managed-file ownership checks and process that file, creating a cross-tenant data access risk. SAML assertion replay protection also fails open during Redis outages, potentially allowing a captured signed assertion to create a new UI session.

Open issues (2)

Fixed/addressed: 0 · PR risk: 7/10

@baiyuxi930826

Copy link
Copy Markdown
Author

Response to CI / automated review

Thanks for the automated feedback. Scope check for this PR:

Diff (3 files only)

  • model_prices_and_context_window.json
  • litellm/model_prices_and_context_window_backup.json
  • tests/test_litellm/litellm_core_utils/prompt_templates/test_bedrock_converse_strict_tools_opus_47_48.py

No changes to uv.lock, pyproject.toml, proxy batches, or SAML SSO.

CI failures

Check Assessment
Verify PR source branch Guard workflow only runs for PRs targeting main. This PR targets litellm_internal_staging (fork contribution path).
Block fork dependency changes Fires when lock/pyproject paths are touched. Our PR does not change uv.lock/pyproject.toml (lockfile SHA matches staging). Likely path-filter/base-checkout noise on retarget.
osv-scan Reports pre-existing lockfile CVEs (gitpython in uv.lock, dashboard npm deps). Not introduced by this cost-map/test-only change; fork PRs cannot bump uv.lock by policy.

Veria / Greptile notes

Local verification

pytest -q tests/test_litellm/litellm_core_utils/prompt_templates/test_bedrock_converse_strict_tools_opus_47_48.py
# 39 passed

Happy to adjust further if maintainers want a different staging branch or flag naming.

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing baiyuxi930826:fix/bedrock-strict-haiku45-sonnet46 (7623032) with litellm_internal_staging (b9b27c2)

Open in CodSpeed

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:34
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 15:31
@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 23, 2026 15:31
@github-actions

Copy link
Copy Markdown
Contributor

#34388 was fixed by #48733 on main, so this pull request is closed. Reopen it if something was missed.

@github-actions github-actions Bot closed this Oct 28, 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.

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

3 participants