Skip to content

fix(responses)!: keep the proxy's error body on litellm.responses errors from litellm_proxy models - #49073

Merged
mateo-berri merged 6 commits into
BerriAI:mainfrom
mika-lt:litellm_responses_proxy_error_body
Oct 30, 2026
Merged

mateo-berri merged 6 commits into
BerriAI:mainfrom
mika-lt:litellm_responses_proxy_error_body

Conversation

@mika-lt

@mika-lt mika-lt commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

When litellm.responses() on a litellm_proxy/ model hits a proxy error like a guardrail block, the SDK raises a BadRequestError with e.body, e.code and e.type all None, while litellm.completion() has carried the error object since #40994

This 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 Responses

Original

TLDR

Problem this solves:

  • litellm.responses() through litellm_proxy/ leaves e.body, e.code and e.type None
  • A chained proxy's errors drop the downstream's provider_specific_fields

How it solves it:

  • The litellm_proxy Responses config decodes the error JSON into body like the OpenAI SDK
  • The proxy's error answer copies the exception body's provider_specific_fields, redacted

Intentional changes that match chat since #40994 are under Caveats as High

Decisions and their alternatives
  • Scope is the litellm_proxy Responses config only
    • Alternative: the OpenAI Responses config, so every OpenAI-compatible Responses provider gets a body
    • Rejected for now because it changes the message every openai/ Responses error carries, which content policy fallbacks and callers match on
    • Alternative: decode in the shared HTTP error handler for every provider. Rejected for the same reason, with a much wider blast radius
  • What body holds follows the OpenAI SDK, the error member when it is an object, otherwise the whole decoded object
    • When the text is not JSON, or is JSON but not an object, body stays None and the text stays in the message
    • The OpenAI SDK keeps a string error member, or raw text, as body. litellm's exception body is typed as a dict, so the whole object or None it is
  • str(e) changing is a side effect of setting body, since litellm's exception mapping prefers body["message"]. It matches what chat completions already shows, so it stays
    • A provider error the proxy relays as JSON text still shows that JSON in str(e)
  • The proxy relays provider_specific_fields from the exception's body only when the exception carries none of its own
    • Without it, the decoded body made the chained proxy's Responses message drop the guardrail JSON it used to embed, with nothing in its place
    • Alternative: relay the whole downstream body. Rejected, since message, type, param and code already map to their own fields
    • Alternative: relay on Responses only. Rejected, since chat had the same gap at both SHAs and one handler builds both answers
  • The relayed fields are redacted per key, so an api_key or client_secret value becomes REDACTED, numbers included, and internal hostnames, file paths and IPs go too, into nested objects and lists
    • A guardrail can put raw exception text or credentials there, and the front proxy already redacts both when they sit in the message
    • Alternative: redact each value without its key. Rejected, since the key-name patterns only fire with the key
    • Alternative: relay them as the downstream sent them. Rejected, since that leaked what the message redacts
  • The relay reads provider_specific_fields from any upstream's error body, not only litellm_proxy/ models
    • Only a LiteLLM proxy writes that field, so an openai/ deployment pointed at a LiteLLM proxy relays it too
    • Alternative: relay only for the litellm_proxy provider. Rejected, since those deployments would keep losing the fields
  • Streamed requests relay the fields when the error comes before the first byte
    • With sse_keepalive_ping_interval_seconds on, an error after the first ping still ends as a bare Error processing stream start frame at both SHAs. That path is unchanged here

User Flow

Before: the Responses call raises an error with no body, so the app's guardrail handler cannot read it

  1. An app uses the LiteLLM SDK with model="litellm_proxy/claude-haiku-5-5" against a proxy whose guardrail blocks "project bluebird"
  2. litellm.completion(...) sends POST https://litellm-domain/v1/chat/completions, gets 400 with guardrail_name in e.body
  3. litellm.responses(...) with the same prompt sends POST https://litellm-domain/v1/responses and gets the same 400 JSON
  4. The raised BadRequestError has e.body, e.code and e.type all None, the JSON only in str(e)
  5. A second proxy routing here through litellm_proxy/ answers its clients' chat and Responses 400s with no provider_specific_fields

After: the Responses call raises the same error as chat, body included

  1. An app uses the LiteLLM SDK with model="litellm_proxy/claude-haiku-5-5" against a proxy whose guardrail blocks "project bluebird"
  2. litellm.completion(...) sends POST https://litellm-domain/v1/chat/completions, gets 400 with guardrail_name in e.body
  3. litellm.responses(...) with the same prompt sends POST https://litellm-domain/v1/responses and gets the same 400 JSON
  4. The raised BadRequestError carries the same e.body, e.code and e.type as chat, with stream=True and aresponses too
  5. A second proxy routing here through litellm_proxy/ answers its clients' chat and Responses 400s with the same provider_specific_fields

Relevant 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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

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

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 calls

Setup (proxy configs and the app script)

Guardrail proxy, litellm --config guardrail_proxy.yaml --port <port> --num_workers 2

model_list:
  - model_name: claude-haiku-5-5
    litellm_params:
      model: anthropic/claude-haiku-5-5
      api_key: os.environ/ANTHROPIC_API_KEY

guardrails:
  - guardrail_name: block-secret-project
    litellm_params:
      guardrail: litellm_content_filter
      mode: pre_call
      default_on: true
      patterns:
        - pattern_type: regex
          pattern: "(?i)project\\s+bluebird"
          name: secret_project_codename
          action: BLOCK
  - guardrail_name: internal-scan
    litellm_params:
      guardrail: internal_guard.InternalDetailGuard
      mode: pre_call
      default_on: true

general_settings:
  master_key: os.environ/LITELLM_QA_MASTER_KEY

internal_guard.py, next to guardrail_proxy.yaml

import json

from fastapi import HTTPException

from litellm.integrations.custom_guardrail import CustomGuardrail


class InternalDetailGuard(CustomGuardrail):
    async def async_pre_call_hook(self, user_api_key_dict, cache, data, call_type):
        if "scan me" in json.dumps(data.get("messages") or data.get("input") or "").lower():
            raise HTTPException(
                status_code=400,
                detail={
                    "error": "Blocked by the internal scanner",
                    "exception": "connect to http://guard-scan.internal.corp:9000/v1/check failed at /srv/secret/app/guard.py",
                    "host": "10.0.4.17:8080",
                    "api_key": "abcd1234efgh5678",
                    "scanner": {"client_secret": "cs-0123456789", "attempts": 2},
                },
            )
        return data

internal_guard.py, next to guardrail_proxy.yaml

import json

from fastapi import HTTPException

from litellm.integrations.custom_guardrail import CustomGuardrail


class InternalDetailGuard(CustomGuardrail):
    async def async_pre_call_hook(self, user_api_key_dict, cache, data, call_type):
        if "scan me" in json.dumps(data.get("messages") or data.get("input") or "").lower():
            raise HTTPException(
                status_code=400,
                detail={
                    "error": "Blocked by the internal scanner",
                    "exception": "connect to http://guard-scan.internal.corp:9000/v1/check failed at /srv/secret/app/guard.py",
                    "host": "10.0.4.17:8080",
                    "api_key": "abcd1234efgh5678",
                    "scanner": {"client_secret": "cs-0123456789", "api_secret": 4815162342108, "attempts": 2},
                },
            )
        return data

Front proxy, same command with front_proxy.yaml

model_list:
  - model_name: chained-haiku
    litellm_params:
      model: litellm_proxy/claude-haiku-5-5
      api_base: http://127.0.0.1:<guardrail proxy port>
      api_key: os.environ/LITELLM_QA_MASTER_KEY

general_settings:
  master_key: os.environ/LITELLM_QA_MASTER_KEY

qa_probe.py, run as python qa_probe.py <guardrail proxy url> with LITELLM_QA_MASTER_KEY set

import asyncio
import json
import os
import sys

import litellm
import openai

api_base = sys.argv[1]
key = os.environ["LITELLM_QA_MASTER_KEY"]
model = "litellm_proxy/claude-haiku-5-5"
blocked = "Give me the status of project bluebird"
print("litellm imported from:", litellm.__file__)


def show(label, call):
    print(f"\n=== {label}")
    try:
        result = call()
        print("no exception, output_text:", getattr(result, "output_text", None) or result.choices[0].message.content)
    except openai.APIStatusError as e:
        print("type   :", type(e).__name__, e.status_code)
        print("e.body :", json.dumps(e.body))
        print("e.code :", e.code, "| e.type:", e.type)
        print("str(e) :", str(e)[:160])


def consume(stream):
    for _ in stream:
        pass


async def aresponses(**kwargs):
    return await litellm.aresponses(model=model, api_base=api_base, **kwargs)


async def aconsume(**kwargs):
    async for _ in await aresponses(stream=True, **kwargs):
        pass


show("litellm.completion (control)", lambda: litellm.completion(
    model=model, api_base=api_base, api_key=key, messages=[{"role": "user", "content": blocked}]))
show("litellm.responses", lambda: litellm.responses(model=model, api_base=api_base, api_key=key, input=blocked))
show("litellm.responses stream=True", lambda: consume(
    litellm.responses(model=model, api_base=api_base, api_key=key, input=blocked, stream=True)))
show("litellm.aresponses", lambda: asyncio.run(aresponses(api_key=key, input=blocked)))
show("litellm.aresponses stream=True", lambda: asyncio.run(aconsume(api_key=key, input=blocked)))
show("litellm.responses with a key the proxy cannot verify (no DB)", lambda: litellm.responses(
    model=model, api_base=api_base, api_key="sk-not-a-real-key", input="hi"))
show("litellm.responses allowed prompt (real Anthropic call)", lambda: litellm.responses(
    model=model, api_base=api_base, api_key=key, input="Reply with the single word: ok", max_output_tokens=16))
Case Before (c21e576) After (568179d)
litellm.completion control body set body set
responses, sync, stream, async body None same body as chat
DB-less proxy's own 400 body None body set
Front /v1/responses, stream too fields as message text provider_specific_fields
Front /v1/chat/completions no guardrail fields provider_specific_fields
Front /v1/messages no guardrail fields no guardrail fields
Front, error naming hosts and keys REDACTED inside message text provider_specific_fields, values REDACTED
Allowed prompts 200, "ok" 200, "ok"

Before (c21e576)

  1. $ python qa_probe.py http://127.0.0.1:26613
  2. The Responses call raises with no body, unlike the chat control in the full output
=== litellm.responses
type   : BadRequestError 400
e.body : null
e.code : None | e.type: None
str(e) : litellm.BadRequestError: Litellm_proxyException - {"error":{"message":"Content blocked: secret_project_codename pattern detected","type":"invalid_request_error"
Full before leg output, every case, front proxy curls included
tree /home/mateo/Development/litellm-worktrees/work-88112bae-base at c21e576a07 refactor(types): replace Any with proven types in 14 files (#48928)
guardrail proxy port 26613, front proxy port 25614, each --num_workers 2, no database

##### case: guardrail proxy wire response
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:26613/v1/responses -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"claude-haiku-5-5","input":"Give me the status of project bluebird"}'
{"error":{"message":"Content blocked: secret_project_codename pattern detected","type":"invalid_request_error","param":null,"code":"400","provider_specific_fields":{"error":"Content blocked: secret_project_codename pattern detected","pattern":"secret_project_codename","guardrail_name":"block-secret-project","guardrail_mode":"pre_call"}}}
HTTP 400

##### case: SDK app calling the guardrail proxy
$ python qa_probe.py http://127.0.0.1:26613
litellm imported from: /home/mateo/Development/litellm-worktrees/work-88112bae-base/litellm/__init__.py
=== litellm.completion (control)
type   : BadRequestError 400
e.body : {"message": "Content blocked: secret_project_codename pattern detected", "type": "invalid_request_error", "param": null, "code": "400", "provider_specific_fields": {"error": "Content blocked: secret_project_codename pattern detected", "pattern": "secret_project_codename", "guardrail_name": "block-secret-project", "guardrail_mode": "pre_call"}}
e.code : 400 | e.type: invalid_request_error
str(e) : litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected
=== litellm.responses
type   : BadRequestError 400
e.body : null
e.code : None | e.type: None
str(e) : litellm.BadRequestError: Litellm_proxyException - {"error":{"message":"Content blocked: secret_project_codename pattern detected","type":"invalid_request_error"
=== litellm.responses stream=True
type   : BadRequestError 400
e.body : null
e.code : None | e.type: None
str(e) : litellm.BadRequestError: Litellm_proxyException - {"error":{"message":"Content blocked: secret_project_codename pattern detected","type":"invalid_request_error"
=== litellm.aresponses
type   : BadRequestError 400
e.body : null
e.code : None | e.type: None
str(e) : litellm.BadRequestError: Litellm_proxyException - {"error":{"message":"Content blocked: secret_project_codename pattern detected","type":"invalid_request_error"
=== litellm.aresponses stream=True
type   : BadRequestError 400
e.body : null
e.code : None | e.type: None
str(e) : litellm.BadRequestError: Litellm_proxyException - {"error":{"message":"Content blocked: secret_project_codename pattern detected","type":"invalid_request_error"
=== litellm.responses with a key the proxy cannot verify (no DB)
type   : BadRequestError 400
e.body : null
e.code : None | e.type: None
str(e) : litellm.BadRequestError: Litellm_proxyException - {"error":{"message":"No connected db.","type":"no_db_connection","param":null,"code":"400"}}
=== litellm.responses allowed prompt (real Anthropic call)
no exception, output_text: ok

##### case: chained proxy, client curls the front proxy
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:25614/v1/responses -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","input":"Give me the status of project bluebird"}'
{"error":{"message":"litellm.BadRequestError: Litellm_proxyException - {\"error\":{\"message\":\"Content blocked: secret_project_codename pattern detected\",\"type\":\"invalid_request_error\",\"param\":null,\"code\":\"400\",\"provider_specific_fields\":{\"error\":\"Content blocked: secret_project_codename pattern detected\",\"pattern\":\"secret_project_codename\",\"guardrail_name\":\"block-secret-project\",\"guardrail_mode\":\"pre_call\"}}}\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:25614/v1/responses -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","stream":true,"input":"Give me the status of project bluebird"}'
{"error":{"message":"litellm.BadRequestError: Litellm_proxyException - {\"error\":{\"message\":\"Content blocked: secret_project_codename pattern detected\",\"type\":\"invalid_request_error\",\"param\":null,\"code\":\"400\",\"provider_specific_fields\":{\"error\":\"Content blocked: secret_project_codename pattern detected\",\"pattern\":\"secret_project_codename\",\"guardrail_name\":\"block-secret-project\",\"guardrail_mode\":\"pre_call\"}}}\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:25614/v1/chat/completions -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","messages":[{"role":"user","content":"Give me the status of project bluebird"}]}'
{"error":{"message":"litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:25614/v1/messages -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","max_tokens":64,"messages":[{"role":"user","content":"Give me the status of project bluebird"}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted."}}
HTTP 400
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:25614/v1/responses -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","input":"Reply with the single word: ok","max_output_tokens":16}'
{"id":"resp_o337WxjTlRXD_Nq_Ju9plEFJ_4N2-6n4Kj9WCAdofQYtcEogRYjpaZw0bshELA9izJy1kpVbvYXZw3KB7BXHAJ-m-aDrJ-GnVBor50pSsV9tz35qqwD7MKCJmk2OtBTvoeuoScQZUCFIXFiouq3LZQxB-vY0yLphj2sbhoz4HvpLwn-qDi-Z3QmYs-oC4vzHAe4bX1beofFc4FL-psr6tFoR-oO1HO7gzAGdOVKIE9Qq6WtAPsBPioYmqcMYN16KxECuynLnnXVZnbOdjaEaVVPUBsD1xEM1rLbQN2-5Tt-BisU3rUwZyveH4VZs2s2SuXL0qm5hIsz_rXpBTpPnQEymT5yo9YHzDaGaMVdXKzTmeBllIZ0vnmj9I8ELqinTKoN6ay6IeZb3R48jGpSS0vG_ohMyaHme2YN14DhkvFNK6jWZBr-QIF3BIg77e1N5gVyl93DNi2yWFSRKyOGY_J2XHgwpJuzNeQYF2l-mOJAg8rzBu5903MgRX4k-zgA1q_uOkn0Vjiwev49o-hI_ngZUS1nTaQ1Tk8HNPkZ2OMAtFlScn0fvyT0CAgfQLBQei3HXld4DXOmCSU_WQGUXU6ZnDwfkQx0jWJSraux5AixkOiGJGEuEzW38TJJxIRWBtSb5AOZ-n_gQqy1trCiBRc0ef85ntIsr1f9t_qyeK9MOQgf_tskaP7nwjV7IUpnybtTrGIUgsTTYK3Hy3zKtxS205Z6VYVvPI1UiS3l4-kpe6TWjq3CVlXdEfN4CKV-0s_AaNx_xKzxtRMkRsvLzMIFmHYQ1znO7egx5FfFlfmiAo3uBi1z8IeWORFpO_GYbjWLrhzj5mpfa2YS0mj0qGLQUdM3Ebiq66zqUH2jzFekd0yriPpM6hxd5L41gj7UAzKntjP6IxrdBsrNbfrXEc6WKxaYKTrerwOTKZseOVUvDDBdgvgaMasgrE9nZpapqv6sH_00cGEnI-PHa_WbPwrBHj_jQiinFX6XpB7gFmFF7fPf0EUtH_IoEFqwZhaC9S9ZzGDrhljhKsU2HlZAg9Tmrwe6xvnDgiE7L-QIZmyk-NkvlzijPXUWIqnr2C-h5hb9sbCqfSfzw4C6wGPD7CRKqMbb3OtYKdaxaXs0cW2oBZP_RWnbfXU3D63hZFtkuuA3LL_kyhABzwKTrJAPUOImoiziG_3oud5H-HNlQRUMNN7ZZE9nDKZmZR0eP_MrOO1o=","created_at":1793307350,"error":null,"incomplete_details":null,"instructions":null,"metadata":{},"model":"chained-haiku","object":"response","output":[{"id":"msg_6b8e7926-ca63-4fe6-96ef-7d6baa4340a7","content":[{"annotations":[],"text":"ok","type":"output_text","logprobs":null}],"role":"assistant","status":"completed","type":"message","phase":null}],"parallel_tool_calls":false,"temperature":null,"tool_choice":"auto","tools":[],"top_p":null,"max_output_tokens":16,"previous_response_id":null,"reasoning":null,"status":"completed","text":{},"truncation":null,"usage":{"input_tokens":18,"input_tokens_details":{"audio_tokens":null,"cached_tokens":0,"cached_tokens_details":null,"cache_write_tokens":0,"image_tokens":null,"text_tokens":18,"video_tokens":null},"output_tokens":4,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":0,"text_tokens":4},"total_tokens":22,"cost":null},"user":null,"store":null,"provider_specific_fields":{"citations":null,"thinking_blocks":null}}
HTTP 200

##### case: chained proxy, downstream guardrail error naming internal hosts and credentials
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:25614/v1/responses -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","input":"scan me please"}'
{"error":{"message":"litellm.BadRequestError: Litellm_proxyException - {\"error\":{\"message\":\"Blocked by the internal scanner\",\"type\":\"invalid_request_error\",\"param\":null,\"code\":\"400\",\"provider_specific_fields\":{\"error\":\"Blocked by the internal scanner\",\"exception\":\"connect to http://REDACTED:9000/v1/check failed at REDACTED\",\"host\":\"REDACTED:8080\",\"REDACTED\",\"scanner\":{\"REDACTED\",\"REDACTED,\"attempts\":2},\"guardrail_name\":\"internal-scan\",\"guardrail_mode\":\"pre_call\"}}}\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:25614/v1/chat/completions -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","messages":[{"role":"user","content":"scan me please"}]}'
{"error":{"message":"litellm.BadRequestError: Litellm_proxyException - Blocked by the internal scanner\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400
leg done

After (568179d)

  1. $ python qa_probe.py http://127.0.0.1:24371
  2. The Responses call carries the same body, code, type, and message as the chat control
=== litellm.responses
type   : BadRequestError 400
e.body : {"message": "Content blocked: secret_project_codename pattern detected", "type": "invalid_request_error", "param": null, "code": "400", "provider_specific_fields": {"error": "Content blocked: secret_project_codename pattern detected", "pattern": "secret_project_codename", "guardrail_name": "block-secret-project", "guardrail_mode": "pre_call"}}
e.code : 400 | e.type: invalid_request_error
str(e) : litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected
Full after leg output, every case, front proxy curls included
tree /home/mateo/Development/litellm-worktrees/work-88112bae-head at 568179d316 fix(proxy): redact numeric credentials in relayed provider_specific_fields
guardrail proxy port 24371, front proxy port 23572, each --num_workers 2, no database

##### case: guardrail proxy wire response
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:24371/v1/responses -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"claude-haiku-5-5","input":"Give me the status of project bluebird"}'
{"error":{"message":"Content blocked: secret_project_codename pattern detected","type":"invalid_request_error","param":null,"code":"400","provider_specific_fields":{"error":"Content blocked: secret_project_codename pattern detected","pattern":"secret_project_codename","guardrail_name":"block-secret-project","guardrail_mode":"pre_call"}}}
HTTP 400

##### case: SDK app calling the guardrail proxy
$ python qa_probe.py http://127.0.0.1:24371
litellm imported from: /home/mateo/Development/litellm-worktrees/work-88112bae-head/litellm/__init__.py
=== litellm.completion (control)
type   : BadRequestError 400
e.body : {"message": "Content blocked: secret_project_codename pattern detected", "type": "invalid_request_error", "param": null, "code": "400", "provider_specific_fields": {"error": "Content blocked: secret_project_codename pattern detected", "pattern": "secret_project_codename", "guardrail_name": "block-secret-project", "guardrail_mode": "pre_call"}}
e.code : 400 | e.type: invalid_request_error
str(e) : litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected
=== litellm.responses
type   : BadRequestError 400
e.body : {"message": "Content blocked: secret_project_codename pattern detected", "type": "invalid_request_error", "param": null, "code": "400", "provider_specific_fields": {"error": "Content blocked: secret_project_codename pattern detected", "pattern": "secret_project_codename", "guardrail_name": "block-secret-project", "guardrail_mode": "pre_call"}}
e.code : 400 | e.type: invalid_request_error
str(e) : litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected
=== litellm.responses stream=True
type   : BadRequestError 400
e.body : {"message": "Content blocked: secret_project_codename pattern detected", "type": "invalid_request_error", "param": null, "code": "400", "provider_specific_fields": {"error": "Content blocked: secret_project_codename pattern detected", "pattern": "secret_project_codename", "guardrail_name": "block-secret-project", "guardrail_mode": "pre_call"}}
e.code : 400 | e.type: invalid_request_error
str(e) : litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected
=== litellm.aresponses
type   : BadRequestError 400
e.body : {"message": "Content blocked: secret_project_codename pattern detected", "type": "invalid_request_error", "param": null, "code": "400", "provider_specific_fields": {"error": "Content blocked: secret_project_codename pattern detected", "pattern": "secret_project_codename", "guardrail_name": "block-secret-project", "guardrail_mode": "pre_call"}}
e.code : 400 | e.type: invalid_request_error
str(e) : litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected
=== litellm.aresponses stream=True
type   : BadRequestError 400
e.body : {"message": "Content blocked: secret_project_codename pattern detected", "type": "invalid_request_error", "param": null, "code": "400", "provider_specific_fields": {"error": "Content blocked: secret_project_codename pattern detected", "pattern": "secret_project_codename", "guardrail_name": "block-secret-project", "guardrail_mode": "pre_call"}}
e.code : 400 | e.type: invalid_request_error
str(e) : litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected
=== litellm.responses with a key the proxy cannot verify (no DB)
type   : BadRequestError 400
e.body : {"message": "No connected db.", "type": "no_db_connection", "param": null, "code": "400"}
e.code : 400 | e.type: no_db_connection
str(e) : litellm.BadRequestError: Litellm_proxyException - No connected db.
=== litellm.responses allowed prompt (real Anthropic call)
no exception, output_text: ok

##### case: chained proxy, client curls the front proxy
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:23572/v1/responses -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","input":"Give me the status of project bluebird"}'
{"error":{"message":"litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400","provider_specific_fields":{"error":"Content blocked: secret_project_codename pattern detected","pattern":"secret_project_codename","guardrail_name":"block-secret-project","guardrail_mode":"pre_call"}}}
HTTP 400
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:23572/v1/responses -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","stream":true,"input":"Give me the status of project bluebird"}'
{"error":{"message":"litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400","provider_specific_fields":{"error":"Content blocked: secret_project_codename pattern detected","pattern":"secret_project_codename","guardrail_name":"block-secret-project","guardrail_mode":"pre_call"}}}
HTTP 400
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:23572/v1/chat/completions -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","messages":[{"role":"user","content":"Give me the status of project bluebird"}]}'
{"error":{"message":"litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400","provider_specific_fields":{"error":"Content blocked: secret_project_codename pattern detected","pattern":"secret_project_codename","guardrail_name":"block-secret-project","guardrail_mode":"pre_call"}}}
HTTP 400
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:23572/v1/messages -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","max_tokens":64,"messages":[{"role":"user","content":"Give me the status of project bluebird"}]}'
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: Litellm_proxyException - Content blocked: secret_project_codename pattern detected\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted."}}
HTTP 400
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:23572/v1/responses -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","input":"Reply with the single word: ok","max_output_tokens":16}'
{"id":"resp_8xVWqhjIO7TepJekkt49MTNTJxQ-Ofv90jNgMa2xWELpMummv1Dmh2IFVw2pwri33QszNtslXNqs-LUUC-enYPooChZ5kWi0of09VCDVWH3hRZGW0TK8GYBNh26WDhBuaJLMMTMfb-pi2r6bszsgBPQvDkFpzaxdAt2O4D2BOgJeSscR7XijIZckDWOggU6g1DJvHe3of50AhX8tXn0vSA57FQd9olxgjWSWChEVhm9OV8dlzddI4Azow_7Hzuvkq56rkrGhkhzXYegwV_wvvcQrkue0QFVhxJzQao_6_yOa_jBIQRNKXTJrel1wKQQHfdGUqxRteu_NV9XNuYT765Qbzqu_kD79h_xFDUq1zS3WIHqzzKloy5YeBrvoWOSrH91rZUDjL6A59I556o-amB2-eqAapGXVDDcVo_yH5N-d8VF_3GuevS75sCOB7iqknWMjYVCm0vQHfPCPkGwzFabSLtYZIr33BgCeL5IbHjTXphX1tBhRjwAtVp-P0p8_9fettqIzUMZcTjkGiekzPSptDVf8fVJKihLm224_hYsL_IcMUhstMUDl29PE8e-l_LZ1p5nmVKN0wyQ2v5FQczs_2HdY4Fj8CYH4X-IALe8Q337H9ipCtojibYvzS6SR2lC6_MQwH2cZ2OoAHv4wu6nUTVN8geXfcGE9LHPR14X-Uu7k5p6-dDYvCX70y3u6Ne9vzaXXxGo3dL7N5HxyCqJOMV8ffewxfm6POBYY_8meREkuQJqU2EdJuJSvszCTvUP14Ld74L0GdgXNV1fCm_XswFcM0G3Z5uJoFJ8Or_umqi_6TdHApRQsnlBWqw6phaDA625ibaaVQ5iTBTm8TX32G4JYhd2pbeE_v_qfIiAXDO6IC5BFe8hIG7SqlWnlB9dkvtOGiiPzBOiswX0WdlrnZeoPkZw4XbYLCZzA4fNXjLdhA3QRwDfkRK9ivcBK1BZF93iqpI4S65xuGvCu3ZItiS_eAeEh46_qPCH5HO1Y_LRNVxWqWsTD7cxMMLNI04KvkjrCcv9bP8MLVW3WQlY80kt5oGmYzOYmDxfE_YUrDvSs5-C4loEZn5hmeTgg5w9pdQMgfnt6TrTBJap0IEZforuIEfVlIwFbT3B4U2W20Zbt0auFKkpifN4XhgiPqlbL4FvgEjq2HgMuW59_BLaL1Mf1dbR0hPDZL8pqLVt9SlGKwmBXW0m6yGVxQAbfuUo=","created_at":1793309919,"error":null,"incomplete_details":null,"instructions":null,"metadata":{},"model":"chained-haiku","object":"response","output":[{"id":"msg_db209fee-809f-4081-a951-dea1423e34e8","content":[{"annotations":[],"text":"ok","type":"output_text","logprobs":null}],"role":"assistant","status":"completed","type":"message","phase":null}],"parallel_tool_calls":false,"temperature":null,"tool_choice":"auto","tools":[],"top_p":null,"max_output_tokens":16,"previous_response_id":null,"reasoning":null,"status":"completed","text":{},"truncation":null,"usage":{"input_tokens":18,"input_tokens_details":{"audio_tokens":null,"cached_tokens":0,"cached_tokens_details":null,"cache_write_tokens":0,"image_tokens":null,"text_tokens":18,"video_tokens":null},"output_tokens":4,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":0,"text_tokens":4},"total_tokens":22,"cost":null},"user":null,"store":null,"provider_specific_fields":{"citations":null,"thinking_blocks":null}}
HTTP 200

##### case: chained proxy, downstream guardrail error naming internal hosts and credentials
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:23572/v1/responses -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","input":"scan me please"}'
{"error":{"message":"litellm.BadRequestError: Litellm_proxyException - Blocked by the internal scanner\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400","provider_specific_fields":{"error":"Blocked by the internal scanner","exception":"connect to http://REDACTED:9000/v1/check failed at REDACTED","host":"REDACTED:8080","api_key":"REDACTED","scanner":{"client_secret":"REDACTED","api_secret":"REDACTED","attempts":2},"guardrail_name":"internal-scan","guardrail_mode":"pre_call"}}}
HTTP 400
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:23572/v1/chat/completions -H "Authorization: Bearer $LITELLM_QA_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"chained-haiku","messages":[{"role":"user","content":"scan me please"}]}'
{"error":{"message":"litellm.BadRequestError: Litellm_proxyException - Blocked by the internal scanner\n\nLiteLLM: model group 'chained-haiku' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400","provider_specific_fields":{"error":"Blocked by the internal scanner","exception":"connect to http://REDACTED:9000/v1/check failed at REDACTED","host":"REDACTED:8080","api_key":"REDACTED","scanner":{"client_secret":"REDACTED","api_secret":"REDACTED","attempts":2},"guardrail_name":"internal-scan","guardrail_mode":"pre_call"}}}
HTTP 400
leg done
/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 from litellm_proxy models now carry the proxy's error object as e.body, and str(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)
  • A chained proxy's 400 on /v1/responses and /v1/chat/completions (streaming too, and after a failed fallback) now carries the downstream's error.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 it
  • Those relayed fields are redacted per key. Fixed in 844ccdc, ba0f79e and 568179d. A guardrail error that names an internal URL, file path, IP, api_key, client_secret and a numeric api_secret reaches the client with each value as REDACTED, while a plain number like attempts stays a number, on Responses and chat alike
  • A Responses error from a chained proxy keeps the downstream's type. With a wrong downstream key it answers no_db_connection where the merge base said invalid_request_error. Chat already answers no_db_connection at 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 #40994
  • The front proxy's spend-log error_message for those Responses failures holds the error text instead of the escaped JSON. Chat failure rows are unchanged

Regression risk

  • handle_llm_api_exception also 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 dict provider_specific_fields, which only a LiteLLM proxy's error answer has. No such route was driven through a chained proxy in this run
  • /v1/messages changes the error into the Anthropic shape and drops the fields, at both SHAs

Dependency graph

Dependent Entry State
responses error body SDK litellm.responses verified live
responses 400 /v1/responses verified live
responses 400 stream /v1/responses verified live
chat 400 /v1/chat/completions verified live
chat 400 stream /v1/chat/completions verified live
fallback then 400 responses and chat verified live
redacted fields responses and chat verified live
wrong downstream key responses and chat verified live
text completion 400 /v1/completions verified live, unchanged
messages 400 /v1/messages verified live, unchanged
401, 500, missing model /v1/responses verified live
spend logs front proxy verified live
other route groups files, vector stores, more untested

Not verified

  • The other route groups above, which need a model on a downstream proxy that fails with a guardrail error on those routes

Type

🐛 Bug Fix

Caveats (if any)

High

Medium

  • Errors after the first streamed byte still lose the guardrail fields
    • A mid-stream response.failed event gives a body with only message, type and code, at both SHAs
    • OpenAI's response.failed error has no slot for them, so it waits for a follow-up

Low

  • A string error member gives a different e.body on Responses than on chat
    • Responses keeps the whole {"error": "text"} object, and chat keeps the string

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
Bugbot summary

[!NOTE]
Medium Risk
Changes client-visible error shape for litellm_proxy Responses and adds structured relay of downstream error fields, with redaction applied but still expanding what leaves the proxy on 400s.

Overview
litellm.responses() on litellm_proxy/ models now surfaces proxy errors like chat completions — the Responses config parses the proxy’s JSON error into BaseLLMException.body (nested error object when present), so callers get e.body, e.code, and e.type on sync, async, and streaming paths instead of leaving them empty while the raw JSON sits in str(e).

Chained proxies forward downstream guardrail metadata on HTTP error answers. When the raised exception has no provider_specific_fields, the proxy handler pulls them from the decoded error body, runs them through new redact_internal_details_from_client_fields (key-aware secret redaction plus internal host/path scrubbing on nested dicts, lists, and sensitive numeric fields), and attaches the result to the OpenAI-shaped ProxyException for both chat and Responses.

Unit tests cover litellm_proxy Responses vs chat error parity, non-JSON error bodies, and chained-proxy relay with and without leaky guardrail payloads.

Reviewed by Cursor Bugbot for commit 568179d. Bugbot is set up for automated code reviews on this repo. Configure here.

…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
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no outstanding findings

Summary

Preserves the proxy’s error body on litellm_proxy Responses errors and forwards redacted provider_specific_fields through chained proxies

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

  • Responses errors from proxy models include a readable error body.
  • Chained proxy errors carry redacted downstream guardrail details.

Reviews (6) · Last reviewed commit: "fix(proxy): redact numeric credentials i..." · Reviewed by Greptile

@codspeed

codspeed Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 38 untouched benchmarks


Comparing mika-lt:litellm_responses_proxy_error_body (568179d) with main (68b5a73)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (e93e01c) during the generation of this report, so 68b5a73 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/_logging.py 88.23% 2 Missing ⚠️

📢 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.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

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.

✅ 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.

@mateo-berri mateo-berri left a comment

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.

LGTM

@mateo-berri
mateo-berri merged commit ea51e77 into BerriAI:main Oct 30, 2026
90 checks passed
mateo-berri added a commit to edvinsq/litellm that referenced this pull request Nov 24, 2026
…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
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.

2 participants