fix(responses): map Bedrock Mantle context overflow to ContextWindowExceededError - #37862
Conversation
|
|
Greptile SummaryThis PR recognizes Bedrock Mantle token-limit validation responses and maps them to
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/exception_mapping_utils.py | Adds Mantle context-overflow detection and maps matching validation responses to the existing context-window exception type. |
| tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py | Adds regression coverage for Mantle context overflow and strengthens the unrelated-validation-error type assertion. |
Reviews (3): Last reviewed commit: "fix(responses): map Bedrock Mantle conte..." | Re-trigger Greptile
|
@greptileai kept the parsing in exception_mapping_utils.py; reasoning is in the PR body's Review notes section, at head ec59c95. |
|
The reasoning holds up. The implementation looks correct: the early check on |
|
@greptileai thanks, please re-review the current head ec59c95 so the score reflects that. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…xceededError Mantle reports context overflow as a structured 400 validation_error rather than the plain-text patterns Bedrock itself uses, so callers such as Claude Code that key reactive compaction off the phrase "prompt is too long" never see it. Detect the pattern and normalize the message to that phrase.
ec59c95 to
fe8e2ee
Compare
|
@greptileai rebased onto staging to pick up an unrelated lint fix, no code changes here. Please re-review the current head fe8e2ee. |
TLDR
Problem this solves:
How it solves it:
validation_errortoken-count messageContextWindowExceededErrorwith that phrase in the messageUser Flow
Before: a Claude Code user whose prompt exceeds a Bedrock Mantle model's context window gets an ordinary error with no automatic recovery
{"error":{"code":"validation_error","message":"prompt tokens (400007) exceed model maximum (278528) for openai.gpt-5.5",...}}After: the same overflow is recognized and triggers Claude Code's compaction path
Relevant issues
Follow-up to #36580 (comment #36580 (comment))
Linear ticket
Pre-Submission checklist
uv run pytest tests/test_litellm/<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@greptileaito re-request a review after pushing changes)Delays 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
All runs below are live calls against the real
bedrock-mantle.us-east-1.api.awsendpoint with real AWS SigV4 credentials, no mocksSetup:
litellm.responses(model="bedrock_mantle/openai.gpt-5.5", input=..., aws_region_name="us-east-1")Before (c166225)
Context overflow
inputbuilt from 400007 tokens worth of text (model maximum is 278528){"error":{"code":"validation_error","message":"prompt tokens (400007) exceed model maximum (278528) for openai.gpt-5.5","param":null,"type":"invalid_request_error"}}litellm.BadRequestError: BedrockException - {"error":{"code":"validation_error","message":"prompt tokens (400007) exceed model maximum (278528) for openai.gpt-5.5",...}}, an ordinary 400 with no "prompt is too long" phraseUnrelated validation error (must stay unaffected)
inputitem:[{"type": "not_a_real_type", "text": "hi"}]{"error":{"code":"validation_error","message":"invalid request body: Invalid 'input': value did not match any expected variant","param":null,"type":"invalid_request_error"}}litellm.BadRequestError: BedrockException - {"error":{"code":"validation_error","message":"invalid request body: Invalid 'input': ...After (ec59c95, unchanged at current head fe8e2ee — a pure rebase onto staging for an unrelated lint fix, no code delta)
Context overflow
inputbuilt from 400007 tokens worth of textlitellm.ContextWindowExceededError: litellm.BadRequestError: prompt is too long: 400007 tokens > 278528 maximum, status code 400Unrelated validation error (must stay unaffected)
inputitemlitellm.BadRequestError: BedrockException - {"error":{"code":"validation_error","message":"invalid request body: Invalid 'input': ..., unchanged from BeforeTargeted regression tests also passed:
uv run --no-sync pytest tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py tests/test_litellm/llms/bedrock_mantle/ -q-> 232 passedType
Bug Fix
Caveats (if any)
openai.gpt-5.5's real context window, chosen over the largergpt-5.6models to keep the live repro cheapvalidation_errorshape; a differently-worded overflow message would need its own patternReview notes
Greptile's one open finding (P2) asks to move the Mantle regex/parser out of
exception_mapping_utils.pyinto the provider layer. Kept it in place: this file already holds 18 provider-specific_map_<provider>_exceptionfunctions, and_map_bedrock_exceptionitself already does inline Bedrock-specific substring matching (AccessDeniedException,too many tokens, and 5 more) right next to the new Mantle branch. This file is the codebase's established shared home for per-provider error classification, dispatched bycustom_llm_provider; the new code follows that same shape one level down for the Mantle sub-provider that #36580 already routed through this exact function, so moving it out would fragment the pattern rather than isolate itFinal Attestation