Repository navigation
fix(responses)!: keep the proxy's error body on litellm.responses errors from litellm_proxy models - #49073
Conversation
…rs from litellm_proxy models litellm.responses() with a litellm_proxy/ model raised BadRequestError with body None when the proxy answered a 4xx, while litellm.completion() on the same proxy carries the decoded error object. The litellm_proxy Responses config now decodes the error JSON into the exception body the way the OpenAI SDK does, so body, code, type and the message match chat completions on sync, async and streaming calls.
…xy_error_body # Conflicts: # tests/unit/llms/litellm_proxy/responses/test_transformation.py
[Medium impact] The PR appears safe to merge, with no outstanding findings SummaryPreserves the proxy’s error body on The latest change also redacts numeric credentials while keeping ordinary numbers unchanged. No new actionable issues were found. The earlier, unnumbered QA finding was addressed by the supplied live proof and conceded in the thread
Reviews (6) · Last reviewed commit: "fix(proxy): redact numeric credentials i..." · Reviewed by Greptile |
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…ror responses A LiteLLM proxy routing to another LiteLLM proxy now copies the downstream's provider_specific_fields (which guardrail fired) from the exception body into its own error answer, on chat and Responses alike. Adds tests for the two _openai_sdk_error_body branches the existing tests left open.
…tial-named values stay hidden
|
bugbot run |
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 568179d. Configure here.
…nAI-compatible backends Picks BerriAI#51809's change onto lts/1.108.x on top of the BerriAI#53217 pick LTS adaptations: - Carries the part of BerriAI#49073 this builds on: relayed_provider_specific_fields, client-field redaction, the relay in handle_llm_api_exception, its recursion ignore entry and the two chained-proxy tests - core_helpers gains http_error_status, which main has as a private helper behind its error_status_code. This line keeps its own error_status_code - /v1/completions answers type and param through openai_error_type and openai_error_param, as main does through route_failure_proxy_exception, so a decoded vLLM BadRequestError type falls back to invalid_request_error - No verbosity -> text.verbosity rename, since this line's chat bridge never forwards text.verbosity (main does since BerriAI#49049) - No LiteLLM Proxy get_error_class move or S3 golden update, since neither exists on this line
When
litellm.responses()on alitellm_proxy/model hits a proxy error like a guardrail block, the SDK raises aBadRequestErrorwithe.body,e.codeande.typeall None, whilelitellm.completion()has carried the error object since #40994This decodes the proxy's error JSON into the exception body on sync, async and streaming litellm_proxy Responses calls. A proxy routing to another LiteLLM proxy also passes on the downstream's redacted
provider_specific_fields(which guardrail fired), on chat and ResponsesOriginal
TLDR
Problem this solves:
litellm.responses()throughlitellm_proxy/leavese.body,e.codeande.typeNoneprovider_specific_fieldsHow it solves it:
bodylike the OpenAI SDKprovider_specific_fields, redactedIntentional changes that match chat since #40994 are under Caveats as High
Decisions and their alternatives
openai/Responses error carries, which content policy fallbacks and callers match onbodyholds follows the OpenAI SDK, theerrormember when it is an object, otherwise the whole decoded objectbodystays None and the text stays in the messageerrormember, or raw text, asbody. litellm's exception body is typed as a dict, so the whole object or None it isstr(e)changing is a side effect of settingbody, since litellm's exception mapping prefersbody["message"]. It matches what chat completions already shows, so it staysstr(e)provider_specific_fieldsfrom the exception'sbodyonly when the exception carries none of its ownmessage,type,paramandcodealready map to their own fieldsapi_keyorclient_secretvalue becomesREDACTED, numbers included, and internal hostnames, file paths and IPs go too, into nested objects and listsprovider_specific_fieldsfrom any upstream's error body, not onlylitellm_proxy/modelsopenai/deployment pointed at a LiteLLM proxy relays it toolitellm_proxyprovider. Rejected, since those deployments would keep losing the fieldssse_keepalive_ping_interval_secondson, an error after the first ping still ends as a bareError processing stream startframe at both SHAs. That path is unchanged hereUser Flow
Before: the Responses call raises an error with no body, so the app's guardrail handler cannot read it
model="litellm_proxy/claude-haiku-5-5"against a proxy whose guardrail blocks "project bluebird"litellm.completion(...)sendsPOST https://litellm-domain/v1/chat/completions, gets 400 withguardrail_nameine.bodylitellm.responses(...)with the same prompt sendsPOST https://litellm-domain/v1/responsesand gets the same 400 JSONBadRequestErrorhase.body,e.codeande.typeall None, the JSON only instr(e)litellm_proxy/answers its clients' chat and Responses 400s with noprovider_specific_fieldsAfter: the Responses call raises the same error as chat, body included
model="litellm_proxy/claude-haiku-5-5"against a proxy whose guardrail blocks "project bluebird"litellm.completion(...)sendsPOST https://litellm-domain/v1/chat/completions, gets 400 withguardrail_nameine.bodylitellm.responses(...)with the same prompt sendsPOST https://litellm-domain/v1/responsesand gets the same 400 JSONBadRequestErrorcarries the samee.body,e.codeande.typeas chat, withstream=Trueandaresponsestoolitellm_proxy/answers its clients' chat and Responses 400s with the sameprovider_specific_fieldsRelevant issues
Follow-up to #40994, which fixed the same thing for chat completions
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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 moreDelays 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
Both legs run two DB-less proxies with 2 uvicorn workers each, the front one routing to the guardrail proxy through
litellm_proxy/. Allowed prompts are real Anthropic callsSetup (proxy configs and the app script)
Guardrail proxy,
litellm --config guardrail_proxy.yaml --port <port> --num_workers 2internal_guard.py, next toguardrail_proxy.yamlinternal_guard.py, next toguardrail_proxy.yamlFront proxy, same command with
front_proxy.yamlqa_probe.py, run aspython qa_probe.py <guardrail proxy url>withLITELLM_QA_MASTER_KEYsetlitellm.completioncontrolresponses, sync, stream, async/v1/responses, stream tooprovider_specific_fields/v1/chat/completionsprovider_specific_fields/v1/messagesREDACTEDinside message textprovider_specific_fields, valuesREDACTEDBefore (c21e576)
$ python qa_probe.py http://127.0.0.1:26613Full before leg output, every case, front proxy curls included
After (568179d)
$ python qa_probe.py http://127.0.0.1:24371Full after leg output, every case, front proxy curls included
/live-pr-risk at 568179d
Nothing breaks. The A/B ran a front proxy (2 workers, Postgres) in front of a recorder and a downstream LiteLLM proxy with two pre_call guardrails, at the merge base c21e576 and at 568179d, on 21 cells. Status codes, downstream attempt counts, the 26 recorded downstream requests (same paths, body keys, models, and headers on each side), and the spend row key sets all match. The only differences are the ones this PR names
Breaking
None observed
Backward incompatible
litellm.responses()errors fromlitellm_proxymodels now carry the proxy's error object ase.body, andstr(e)shows the error message instead of the escaped JSON. This is fixed behavior, and it matches chat completions, which has worked this way since fix(sdk): keep body and proxy headers on BadRequestError mapped from a litellm_proxy 400 #40994 (approved by mateo-berri there)/v1/responsesand/v1/chat/completions(streaming too, and after a failed fallback) now carries the downstream'serror.provider_specific_fields, which names the guardrail that blocked the request. Fixed in 7b4e6dd. Before, Responses showed it only as escaped JSON inside the message and chat dropped itapi_key,client_secretand a numericapi_secretreaches the client with each value asREDACTED, while a plain number likeattemptsstays a number, on Responses and chat aliketype. With a wrong downstream key it answersno_db_connectionwhere the merge base saidinvalid_request_error. Chat already answersno_db_connectionat the merge base, the parity approved by mateo-berri in fix(sdk): keep body and proxy headers on BadRequestError mapped from a litellm_proxy 400 #40994error_messagefor those Responses failures holds the error text instead of the escaped JSON. Chat failure rows are unchangedRegression risk
handle_llm_api_exceptionalso serves many other route groups (files, vector stores, videos, containers, evals, and others). The relay fires there only when the exception body is a dict with a dictprovider_specific_fields, which only a LiteLLM proxy's error answer has. No such route was driven through a chained proxy in this run/v1/messageschanges the error into the Anthropic shape and drops the fields, at both SHAsDependency graph
litellm.responses/v1/responses/v1/responses/v1/chat/completions/v1/chat/completions/v1/completions/v1/messages/v1/responsesNot verified
Type
🐛 Bug Fix
Caveats (if any)
High
str(e)and the loggederror_messageon Responses errors no longer name the guardraile.body["provider_specific_fields"]HTTPExceptiondetail reaches them, redacted, where the merge base sent only the message/v1/responseserrors now carry the downstream'stypeandparamno_db_connectioninstead ofinvalid_request_error, as chat has since fix(sdk): keep body and proxy headers on BadRequestError mapped from a litellm_proxy 400 #40994Medium
response.failedevent gives abodywith only message, type and code, at both SHAsresponse.failederror has no slot for them, so it waits for a follow-upLow
errormember gives a differente.bodyon Responses than on chat{"error": "text"}object, and chat keeps the stringFinal Attestation
Bugbot summary