Repository navigation
fix(anthropic_endpoints): serialize dict-detail HTTPExceptions on /v1/messages like sibling surfaces - #38741
Merged
mateo-berri merged 1 commit intoAug 29, 2026
Conversation
…/messages like sibling surfaces
Contributor
Greptile SummaryThe PR extracts the existing HTTPException conversion into a shared helper and applies it to Anthropic Messages errors
Confidence Score: 5/5The PR appears safe to merge No blocking failure remains
|
| Filename | Overview |
|---|---|
| litellm/proxy/anthropic_endpoints/endpoints.py | Routes HTTPException failures through the shared ProxyException serializer while preserving failure-hook execution |
| litellm/proxy/common_request_processing.py | Extracts the established HTTPException conversion into a reusable helper without changing the common processing behavior |
| tests/test_litellm/proxy/anthropic_endpoints/test_endpoints.py | Adds endpoint regression coverage for dictionary-detail HTTPExceptions |
| tests/test_litellm/proxy/test_common_request_processing.py | Covers structured-field merging, header propagation, and plain-string details in the new helper |
Reviews (2): Last reviewed commit: "fix(anthropic_endpoints): serialize dict..." | Re-trigger Greptile
Contributor
Author
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
|
bugbot run |
Contributor
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 817b5f4. Configure here.
mateo-berri
enabled auto-merge
August 29, 2026 08:10
Contributor
tin-berri
approved these changes
Aug 29, 2026
mateo-berri
deleted the
litellm_fix_anthropic_messages_dict_detail_error
branch
August 29, 2026 23:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a developer whose post_call guardrail blocks a request on /v1/messages gets a stringified python dict as the error message instead of the guardrail's clean message
{"model": "claude-sonnet-5", "max_tokens": 128, "messages": [{"role": "user", "content": "Say the word kumquat"}]}while a guardrail that blocks "kumquat" is on"message": "400: {'error': \"Content blocked: keyword 'kumquat' detected\", 'keyword': 'kumquat', 'guardrail': 'keyword-block', ...}", a python-repr blob their client cannot parse, and noprovider_specific_fields"message": "Content blocked: keyword 'kumquat' detected"and the full details underprovider_specific_fields, so the two surfaces disagreeAfter: the same blocked request on /v1/messages returns the same clean error as the other endpoints
"message": "Content blocked: keyword 'kumquat' detected"and the keyword, guardrail name, and mode underprovider_specific_fieldsRelevant issues
Pre-existing bug found during LIT-6410 QA on PR #38721. That PR is in flight on the same subsystem but touches neither of the files changed here, so there is no dependency either way
Linear ticket
Resolves LIT-6466
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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
Live proxy QA, no mocks, real Anthropic API calls costing real money. Both legs ran the same config (a post_call custom guardrail
keyword-block, default_on, raisingHTTPException(status_code=400, detail={"error": "Content blocked: keyword 'kumquat' detected", "keyword": "kumquat", "guardrail": "keyword-block"})when "kumquat" appears in the request) on the same topology, 1 instance x 2 uvicorn workers (--num_workers 2), only the proxy commit differing: before = merge base ae7e50f on port 30846, after = this PR's tip 817b5f4 on port 23226. The blocked /v1/messages request was sent twice per leg to cover both workers and the outputs were byte-identical each timeBefore (ae7e50f)
POST /v1/messages happy path
POST /v1/messages blocked prompt
POST /v1/chat/completions blocked prompt
POST /v1/responses blocked prompt
After (817b5f4)
POST /v1/messages happy path
POST /v1/messages blocked prompt
provider_specific_fields:POST /v1/chat/completions blocked prompt
POST /v1/responses blocked prompt
Type
🐛 Bug Fix
Caveats (if any)
Low
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
817b5f4 passes /live-pr-risk
Note
Low Risk
Narrow error-handling change on the proxy; it improves response shape for guardrail blocks and may change error
messagetext for anyHTTPExceptionon/v1/messages, with no auth or data-path changes.Overview
Fixes inconsistent guardrail error responses on
POST /v1/messages. When a guardrail raisesHTTPExceptionwith a dictdetail, that route used to turn the failure into aProxyExceptionwhosemessagewas essentiallystr(HTTPException)(a Python-repr blob) and omitted structured fields. Chat completions and responses already parsed dict details into a clean message plusprovider_specific_fields.The PR adds shared
proxy_exception_from_http_exceptionincommon_request_processing(using existing_serialize_http_exception_detailand mergingprovider_specific_fieldswith response headers) and wiresanthropic_response’s genericexceptblock to use it forHTTPExceptionbefore the fallbackProxyExceptionpath. The same helper replaces the inlined conversion inside_handle_llm_api_exception, so behavior stays aligned without duplication.Tests cover the Anthropic endpoint path (LIT-6466) and the helper’s message merge and header pass-through.
Reviewed by Cursor Bugbot for commit 817b5f4. Bugbot is set up for automated code reviews on this repo. Configure here.