fix(responses): preserve Bedrock Mantle validation errors - #36580
Conversation
Greptile SummaryThe PR maps Bedrock Mantle failures through the existing Bedrock exception mapper so upstream validation responses retain their status and message.
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/exception_mapping_utils.py | Extends Bedrock exception mapping to Bedrock Mantle, preserving upstream client-error classification. |
| tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py | Adds a focused regression test asserting that a Mantle HTTP 400 preserves its status and validation message. |
Reviews (2): Last reviewed commit: "fix(responses): preserve Bedrock Mantle ..." | Re-trigger Greptile
| extra_information=extra_information, | ||
| ) | ||
| elif custom_llm_provider == "bedrock": | ||
| elif custom_llm_provider in ("bedrock", "bedrock_mantle"): |
There was a problem hiding this comment.
Provider-specific dispatch in core
Adding bedrock_mantle here places provider-specific behavior outside the provider layer, fragmenting its error handling and increasing the maintenance cost when the Mantle adapter evolves.
Rule Used: What: Avoid writing provider-specific code outside... (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!
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Thanks for fixing the 400 -> 500 masking. There is one related compatibility gap worth covering in this PR (or a linked follow-up). Bedrock Mantle can return this validation error for context overflow: {"error":{"code":"validation_error","message":"prompt tokens (1055489) exceed model maximum (1050000) for openai.gpt-5.6-sol","param":null,"type":"invalid_request_error"}}This PR should preserve it as HTTP 400, but preserving the upstream message verbatim is not sufficient for Claude Code recovery. Claude Code 2.1.234 recognizes context overflow only when a 400/413 message contains a known phrase such as Could the Bedrock Mantle mapping also detect the structured 400 A focused regression test should assert both |
c166225
into
BerriAI:litellm_internal_staging
TLDR
Problem this solves:
How it solves it:
BadRequestError, status 400, and the upstream messageUser Flow
Before: a Responses API caller receives the wrong error class for an invalid request
POST https://bedrock-mantle.us-east-1.api.aws/openai/v1/responseswith a Responses requestinvalid_request_errorbodyAPIConnectionErrorwith status 500 and cannot distinguish validation from connectivityAfter: the same invalid request is reported as a client error
POST https://bedrock-mantle.us-east-1.api.aws/openai/v1/responseswith the same Responses requestinvalid_request_errorbodyBadRequestErrorwith status 400 and the upstream validation messageRelevant issues
Addresses the error-classification portion of #36546
Linear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
The before run was captured against commit
bea31871fcwith a mocked HTTP 400 response. Both sync and asynclitellm.responses()paths raisedAPIConnectionErrorwith status 500The after run was captured against commit
f6f6044e09with the same mocked HTTP 400 response. Both paths raisedBadRequestErrorwith status 400 and preservedInvalid 'input'Targeted regression tests passed:
uv run --no-sync pytest tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py -q-> 63 passeduv run --no-sync pytest tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_responses_transformation.py -q-> 116 passedNo live Bedrock credentials were available in this environment, so I did not include a live provider run
Type
Bug Fix
Caveats (if any)
Live Bedrock verification still needs to run with provider credentials
This PR covers the 400-to-500 error masking. Input-item normalization remains a separate concern
Final Attestation
AI assistance: this patch was prepared and tested with AI coding assistance. The implementation, reproduction, and test scope are included for maintainer review