Skip to content

feat(guardrails): run legacy post-call hooks as streaming pipeline steps - #40284

Merged
mateo-berri merged 15 commits into
litellm_internal_stagingfrom
litellm_legacy_hook_streaming_pipeline_step
Sep 10, 2026
Merged

mateo-berri merged 15 commits into
litellm_internal_stagingfrom
litellm_legacy_hook_streaming_pipeline_step

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • The streaming step assembles the buffered stream into the response the hook expects
  • The hook runs on it; a raise ends the stream like a block does
  • Its rewrite goes out through the same event write-back unified guardrails use
  • Chat, Responses, and Messages streams all carry the rewrite
  • Messages hooks get the Anthropic response shape, same as non-streamed calls
  • A stream the pipeline gated no longer reruns the same hook after it ends; a stream it could not gate still gets the hook's after-the-fact run
  • Each step's hook sees the stream as the steps before it left it, so chained rewrites and blocks line up
  • A replacement that changes or drops a tool call cannot go out on a stream yet, so the original stream is released with a warning
  • A guardrail with neither hook nor unified interface still fails open with a warning

User Flow

Before: a team whose post-call guardrail was written against the older hook gets its rewrite and its block on non-streamed replies only, while every stream goes out untouched

  1. The proxy admin attaches a post_call pipeline policy whose step names a guardrail written against the older post-call hook (it prefixes every reply with [REWRITTEN BY LEGACY HOOK]) to gpt-5.4-mini-legacy and claude-haiku-4-5-legacy, attaches a second such policy whose hook rejects the word kumquat to gpt-5.4-mini-legacy-block, and restarts the proxy
  2. A developer sends POST https://litellm-domain/v1/chat/completions with "model": "gpt-5.4-mini-legacy" asking for the word persimmon and gets HTTP 200 with "content": "[REWRITTEN BY LEGACY HOOK] persimmon"
  3. They send the same request with "stream": true and the SSE chunks spell pers, im, mon, with no rewrite anywhere in the stream
  4. They send POST https://litellm-domain/v1/messages with "model": "claude-haiku-4-5-legacy" and "stream": true, and the content_block_delta events spell pers, immon, untouched
  5. They send POST https://litellm-domain/v1/responses with "model": "gpt-5.4-mini-legacy" and "stream": true, and the response.output_text.delta events spell pers, im, mon, with response.output_text.done reading persimmon
  6. They send POST https://litellm-domain/v1/chat/completions with "model": "gpt-5.4-mini-legacy-block" asking for the word kumquat and get HTTP 400 Violated legacy blocker policy: kumquat
  7. They send that kumquat request with "stream": true and get HTTP 200 with chunks spelling kum, quat, so the block holds for non-streamed calls only

After: the same streams carry the hook's rewrite, and the hook's rejection ends the stream with its error

  1. The proxy admin attaches a post_call pipeline policy whose step names a guardrail written against the older post-call hook (it prefixes every reply with [REWRITTEN BY LEGACY HOOK]) to gpt-5.4-mini-legacy and claude-haiku-4-5-legacy, attaches a second such policy whose hook rejects the word kumquat to gpt-5.4-mini-legacy-block, and restarts the proxy
  2. A developer sends POST https://litellm-domain/v1/chat/completions with "model": "gpt-5.4-mini-legacy" asking for the word persimmon and gets HTTP 200 with "content": "[REWRITTEN BY LEGACY HOOK] persimmon"
  3. They send the same request with "stream": true and the first content chunk reads [REWRITTEN BY LEGACY HOOK] persimmon, followed by empty deltas and "finish_reason": "stop"
  4. They send POST https://litellm-domain/v1/messages with "model": "claude-haiku-4-5-legacy" and "stream": true, and the first content_block_delta reads [REWRITTEN BY LEGACY HOOK] persimmon, followed by an empty delta and the usual content_block_stop, message_delta, message_stop
  5. They send POST https://litellm-domain/v1/responses with "model": "gpt-5.4-mini-legacy" and "stream": true, and the first response.output_text.delta reads [REWRITTEN BY LEGACY HOOK] persimmon, with response.output_text.done and response.completed carrying the same text
  6. They send POST https://litellm-domain/v1/chat/completions with "model": "gpt-5.4-mini-legacy-block" asking for the word kumquat and get HTTP 400 Violated legacy blocker policy: kumquat
  7. They send that kumquat request with "stream": true and get HTTP 400 whose only SSE frame is data: {"error": {"message": "Violated legacy blocker policy: kumquat", ...}} followed by data: [DONE], with no content chunk

Relevant issues

Follow-up to #38721

Linear ticket

Resolves LIT-7176

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/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
  • 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
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to 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

Both legs: the proxy booted from the worktree with --num_workers 2 on port 37779, no database, real OpenAI (gpt-5.4-mini) and Anthropic (claude-haiku-4-5) spend. legacy_hook.py sits on PYTHONPATH. Same config, same hook, same nine requests on both legs; only the commit the proxy booted from differs. The Before leg is the merge base with litellm_internal_staging. The booted config also carried the extra models, guardrails, and policies of the /live-pr-risk probes further down; they attach only to their own models, so none of the nine requests here touches them

Boot: python litellm/proxy/proxy_cli.py --config config.yaml --port 37779 --num_workers 2 --detailed_debug

config.yaml (the model_list maps gpt-5.4-mini, gpt-5.4-mini-legacy, and gpt-5.4-mini-legacy-block to openai/gpt-5.4-mini, and claude-haiku-4-5 and claude-haiku-4-5-legacy to anthropic/claude-haiku-4-5):

guardrails:
  - guardrail_name: output-word-filter
    litellm_params:
      guardrail: litellm_content_filter
      mode: post_call
      blocked_words:
        - keyword: kumquat
          action: BLOCK
        - keyword: persimmon
          action: MASK
  - guardrail_name: legacy-rewriter
    litellm_params:
      guardrail: legacy_hook.legacyRewriter
      mode: post_call
  - guardrail_name: legacy-blocker
    litellm_params:
      guardrail: legacy_hook.legacyBlocker
      mode: post_call

policies:
  response-governance:
    guardrails:
      add: [output-word-filter]
    pipeline:
      mode: post_call
      steps:
        - guardrail: output-word-filter
          on_pass: allow
          on_fail: block
  legacy-governance:
    guardrails:
      add: [legacy-rewriter]
    pipeline:
      mode: post_call
      steps:
        - guardrail: legacy-rewriter
          on_pass: allow
          on_fail: block
  legacy-block-governance:
    guardrails:
      add: [legacy-blocker]
    pipeline:
      mode: post_call
      steps:
        - guardrail: legacy-blocker
          on_pass: allow
          on_fail: block

policy_attachments:
  - policy: response-governance
    models: [gpt-5.4-mini, gpt-4.1-mini, claude-haiku-4-5]
  - policy: legacy-governance
    models: [gpt-5.4-mini-legacy, claude-haiku-4-5-legacy]
  - policy: legacy-block-governance
    models: [gpt-5.4-mini-legacy-block]

legacy_hook.py, two guardrails that only implement the older post-call hook (no apply_guardrail); the rewriter handles the chat, Messages, and Responses shapes, the blocker handles chat:

from fastapi import HTTPException

from litellm.integrations.custom_guardrail import CustomGuardrail
from litellm.types.utils import ModelResponse

PREFIX = "[REWRITTEN BY LEGACY HOOK] "


def _rewrite_responses_api(response):
    is_model = hasattr(response, "model_dump")
    payload = response.model_dump() if is_model else dict(response)
    for item in payload.get("output") or []:
        for block in item.get("content") or []:
            if block.get("type") == "output_text" and block.get("text"):
                block["text"] = PREFIX + block["text"]
    return type(response)(**payload) if is_model else payload


class legacyRewriter(CustomGuardrail):
    async def async_post_call_success_hook(self, data, user_api_key_dict, response):
        if isinstance(response, dict) and response.get("type") == "message":
            payload = dict(response)
            payload["content"] = [
                {**block, "text": PREFIX + block["text"]}
                if block.get("type") == "text" and block.get("text")
                else block
                for block in response.get("content", [])
            ]
            return payload
        if isinstance(response, ModelResponse):
            payload = response.model_dump()
            for choice in payload.get("choices", []):
                message = choice.get("message") or {}
                if message.get("content"):
                    message["content"] = PREFIX + message["content"]
            return ModelResponse(**payload)
        if getattr(response, "object", None) == "response" or (isinstance(response, dict) and response.get("object") == "response"):
            return _rewrite_responses_api(response)
        return None


class legacyBlocker(CustomGuardrail):
    async def async_post_call_success_hook(self, data, user_api_key_dict, response):
        if not isinstance(response, ModelResponse):
            return None
        text = " ".join(
            str((choice.get("message") or {}).get("content") or "")
            for choice in response.model_dump().get("choices", [])
        )
        if "kumquat" in text.lower():
            raise HTTPException(status_code=400, detail={"error": "Violated legacy blocker policy: kumquat"})
        return None

The 16 Risk probe cases on each side are the /live-pr-risk run. risk_hooks.py sits on PYTHONPATH and adds 5 guardrails that exist only to observe the paths this diff changes: legacyUnguarded is an older hook that reads response.choices[0].message.content without checking the shape and raises ValueError on the word coffee, legacyRecorder is an older hook that appends what it was handed to $LIT7176_RECORD_FILE, neitherHook only has a pre-call hook so a stream has nothing to run, and unifiedRaiser is the control, an apply_guardrail that raises ValueError on coffee, and legacyToolMasker is an older hook that masks the arguments of every tool call in place and returns None. The tool-only Messages probe reuses claude-haiku-4-5-legacy and the legacyRewriter hook from the requests above, since that hook prefixes text blocks and leaves tool_use blocks alone, and the chained probe runs 2 instances of that same hook in one pipeline. The last 5 probes cover the routes and guardrails the pipeline step keeps off (/v1/completions and the Gemini stream route through legacy-governance, and the built-in tool_permission guardrail, which has both a post-call hook and its own streaming hook, on a chat tool call), the response headers of a rewritten chat stream, and the blocking hook on a Messages stream, where it only knows the chat shape

import json
import os
import time

import litellm
from litellm.integrations.custom_guardrail import CustomGuardrail
from litellm.types.utils import ModelResponse

with open(os.environ["LIT7176_RECORD_FILE"], "a") as _handle:
    _handle.write(json.dumps({"litellm_file": litellm.__file__, "pid": os.getpid()}) + "\n")


class legacyUnguarded(CustomGuardrail):
    async def async_post_call_success_hook(self, data, user_api_key_dict, response):
        content = response.choices[0].message.content or ""
        if "coffee" in content.lower():
            raise ValueError("Guardrail failed: coffee detected")
        return None


class legacyRecorder(CustomGuardrail):
    async def async_post_call_success_hook(self, data, user_api_key_dict, response):
        record = {
            "model": data.get("model"),
            "stream": data.get("stream"),
            "response_type": type(response).__name__,
            "ts": round(time.time(), 3),
        }
        with open(os.environ["LIT7176_RECORD_FILE"], "a") as handle:
            handle.write(json.dumps(record) + "\n")
        return None


class neitherHook(CustomGuardrail):
    async def async_pre_call_hook(self, user_api_key_dict, cache, data, call_type):
        return data


class unifiedRaiser(CustomGuardrail):
    async def apply_guardrail(self, inputs, request_data, input_type, logging_obj=None):
        if "coffee" in json.dumps(inputs).lower():
            raise ValueError("Guardrail failed: coffee detected (unified)")
        return inputs


class legacyToolMasker(CustomGuardrail):
    async def async_post_call_success_hook(self, data, user_api_key_dict, response):
        if not isinstance(response, ModelResponse):
            return None
        for choice in response.choices:
            for tool_call in getattr(choice.message, "tool_calls", None) or []:
                tool_call.function.arguments = json.dumps({"city": "***"})
        return None

The config for the probes is the one above plus these entries, so the probes only attach to their own models

  - model_name: gpt-5.4-mini-unguarded
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: claude-haiku-4-5-unguarded
    litellm_params:
      model: anthropic/claude-haiku-4-5
      api_key: os.environ/ANTHROPIC_API_KEY
  - model_name: gpt-5.4-mini-unguarded-allow
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: gpt-5.4-mini-mixed
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: gpt-5.4-mini-unified-raiser
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: gpt-5.4-mini-chained
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: gpt-5.4-mini-toolmask
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: gemini-flash-legacy
    litellm_params:
      model: gemini/gemini-3.8-flash
      api_key: os.environ/GEMINI_API_KEY
  - model_name: gpt-5.4-mini-toolperm
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: claude-haiku-4-5-legacy-block
    litellm_params:
      model: anthropic/claude-haiku-4-5
      api_key: os.environ/ANTHROPIC_API_KEY
  - guardrail_name: legacy-unguarded
    litellm_params:
      guardrail: risk_hooks.legacyUnguarded
      mode: post_call
  - guardrail_name: legacy-recorder
    litellm_params:
      guardrail: risk_hooks.legacyRecorder
      mode: post_call
  - guardrail_name: neither-hook
    litellm_params:
      guardrail: risk_hooks.neitherHook
      mode: post_call
  - guardrail_name: unified-raiser
    litellm_params:
      guardrail: risk_hooks.unifiedRaiser
      mode: post_call
  - guardrail_name: legacy-rewriter-second
    litellm_params:
      guardrail: legacy_hook.legacyRewriter
      mode: post_call
  - guardrail_name: legacy-tool-masker
    litellm_params:
      guardrail: risk_hooks.legacyToolMasker
      mode: post_call
  - guardrail_name: tool-permission-builtin
    litellm_params:
      guardrail: tool_permission
      mode: post_call
      default_action: allow
      on_disallowed_action: block
      rules:
        - id: deny_weather
          tool_name: get_weather
          decision: deny

          on_pass: allow
          on_fail: block

  unguarded-governance:
    guardrails:
      add: [legacy-unguarded]
    pipeline:
      mode: post_call
      steps:
        - guardrail: legacy-unguarded
          on_pass: allow
          on_fail: block
  unguarded-allow-governance:
    guardrails:
      add: [legacy-unguarded]
    pipeline:
      mode: post_call
      steps:
        - guardrail: legacy-unguarded
          on_pass: allow
          on_fail: block
          on_error: allow
  mixed-governance:
    guardrails:
      add: [legacy-recorder, neither-hook]
    pipeline:
      mode: post_call
      steps:
        - guardrail: legacy-recorder
          on_pass: next
          on_fail: next
        - guardrail: neither-hook
          on_pass: allow
          on_fail: block
  unified-raiser-governance:
    guardrails:
      add: [unified-raiser]
    pipeline:
      mode: post_call
      steps:
        - guardrail: unified-raiser
          on_pass: allow
          on_fail: block
  chained-governance:
    guardrails:
      add: [legacy-rewriter, legacy-rewriter-second]
    pipeline:
      mode: post_call
      steps:
        - guardrail: legacy-rewriter
          on_pass: next
          on_fail: block
        - guardrail: legacy-rewriter-second
          on_pass: allow
          on_fail: block
  tool-mask-governance:
    guardrails:
      add: [legacy-tool-masker]
    pipeline:
      mode: post_call
      steps:
        - guardrail: legacy-tool-masker
          on_pass: allow
          on_fail: block
  tool-permission-governance:
    guardrails:
      add: [tool-permission-builtin]
    pipeline:
      mode: post_call
      steps:
        - guardrail: tool-permission-builtin
    models: [gpt-5.4-mini-legacy, claude-haiku-4-5-legacy, gemini-flash-legacy]
    models: [gpt-5.4-mini-legacy-block, claude-haiku-4-5-legacy-block]

  - policy: unguarded-governance
    models: [gpt-5.4-mini-unguarded, claude-haiku-4-5-unguarded]
  - policy: unguarded-allow-governance
    models: [gpt-5.4-mini-unguarded-allow]
  - policy: mixed-governance
    models: [gpt-5.4-mini-mixed]
  - policy: unified-raiser-governance
    models: [gpt-5.4-mini-unified-raiser]
  - policy: chained-governance
    models: [gpt-5.4-mini-chained]
  - policy: tool-mask-governance
    models: [gpt-5.4-mini-toolmask]
  - policy: tool-permission-governance
    models: [gpt-5.4-mini-toolperm]

Before (2b2e6cf)

Chat stream, legacy rewriter (/v1/chat/completions)

  1. curl -sS -N -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLSUcYSjUtLF55brnkHMcYpbZj0m","object":"chat.completion.chunk","created":1788994410,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-EMLSUcYSjUtLF55brnkHMcYpbZj0m","object":"chat.completion.chunk","created":1788994410,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":"pers"}}]}

data: {"id":"chatcmpl-EMLSUcYSjUtLF55brnkHMcYpbZj0m","object":"chat.completion.chunk","created":1788994410,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":"im"}}]}

data: {"id":"chatcmpl-EMLSUcYSjUtLF55brnkHMcYpbZj0m","object":"chat.completion.chunk","created":1788994410,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":"mon"}}]}

data: {"id":"chatcmpl-EMLSUcYSjUtLF55brnkHMcYpbZj0m","object":"chat.completion.chunk","created":1788994410,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Chat non-stream, legacy rewriter (/v1/chat/completions)

  1. curl -sS -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy","messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
{"id":"chatcmpl-EMLSVyppaw3eIkDRToT90oULpxDV3","created":1788994411,"model":"gpt-5.4-mini-legacy","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"[REWRITTEN BY LEGACY HOOK] persimmon","role":"assistant","provider_specific_fields":{"refusal":null},"annotations":[]},"provider_specific_fields":{}}],"usage":{"completion_tokens":6,"prompt_tokens":18,"total_tokens":24,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0},"prompt_tokens_details":{"audio_tokens":0,"cached_tokens":0}},"service_tier":"default"}```

#### Messages stream, legacy rewriter (/v1/messages)

1. `curl -sS -N -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":32,"stream":true,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'`
2. Observed:

```text
event: message_start
data: {"type":"message_start","message":{"model":"claude-haiku-4-5-legacy","id":"msg_011CetgpuwNPz3dMn8vcR6z9","type":"message","role":"assistant","content":[],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}          }

event: ping
data: {"type": "ping"}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"pers"}         }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"immon"}      }

event: content_block_stop
data: {"type":"content_block_stop","index":0     }

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null},"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":6}              }

event: message_stop
data: {"type":"message_stop"         }

Messages non-stream, legacy rewriter (/v1/messages)

  1. curl -sS -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":32,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
{"model":"claude-haiku-4-5-legacy","id":"msg_011Cetgpym4TNvKaFkax9Xrv","type":"message","role":"assistant","content":[{"type":"text","text":"[REWRITTEN BY LEGACY HOOK] persimmon"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"service_tier":"standard","inference_geo":"not_available"}}```

#### Responses stream, legacy rewriter (/v1/responses), text events only

1. `curl -sS -N -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/responses -d '{"model":"gpt-5.4-mini-legacy","stream":true,"input":"Reply with exactly the word persimmon and nothing else."}' | grep -E 'output_text\.(delta|done)'`
2. Observed:

```text
data: {"type":"response.output_text.delta","item_id":"msg_0bc72276e9495c01006aa1e36dd32087d0afe4e85c90879402","output_index":0,"content_index":0,"delta":"pers","logprobs":[],"obfuscation":"PNriizXRPofY","sequence_number":4,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.delta","item_id":"msg_0bc72276e9495c01006aa1e36dd32087d0afe4e85c90879402","output_index":0,"content_index":0,"delta":"im","logprobs":[],"obfuscation":"kZpCr18iTcaE7S","sequence_number":5,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.delta","item_id":"msg_0bc72276e9495c01006aa1e36dd32087d0afe4e85c90879402","output_index":0,"content_index":0,"delta":"mon","logprobs":[],"obfuscation":"FfLXuaCTaYbBy","sequence_number":6,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.done","item_id":"msg_0bc72276e9495c01006aa1e36dd32087d0afe4e85c90879402","output_index":0,"content_index":0,"text":"persimmon","logprobs":[],"sequence_number":7,"model":"gpt-5.4-mini-legacy"}

Responses non-stream, legacy rewriter (/v1/responses)

  1. curl -sS -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/responses -d '{"model":"gpt-5.4-mini-legacy","input":"Reply with exactly the word persimmon and nothing else."}' | jq -c '{status, output: [.output[] | {type, content}]}'
  2. Observed:
{"status":"completed","output":[{"type":"message","content":[{"annotations":[],"text":"[REWRITTEN BY LEGACY HOOK] persimmon","type":"output_text","logprobs":[]}]}]}

Chat stream, legacy blocker (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy-block","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLSZP71ysuAnOhL5xSRaD4GUQtuZ","object":"chat.completion.chunk","created":1788994416,"model":"gpt-5.4-mini-legacy-block","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-EMLSZP71ysuAnOhL5xSRaD4GUQtuZ","object":"chat.completion.chunk","created":1788994416,"model":"gpt-5.4-mini-legacy-block","choices":[{"index":0,"delta":{"content":"kum"}}]}

data: {"id":"chatcmpl-EMLSZP71ysuAnOhL5xSRaD4GUQtuZ","object":"chat.completion.chunk","created":1788994416,"model":"gpt-5.4-mini-legacy-block","choices":[{"index":0,"delta":{"content":"quat"}}]}

data: {"id":"chatcmpl-EMLSZP71ysuAnOhL5xSRaD4GUQtuZ","object":"chat.completion.chunk","created":1788994416,"model":"gpt-5.4-mini-legacy-block","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]


HTTP 200

Chat non-stream, legacy blocker (/v1/chat/completions)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy-block","messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
{"error":{"message":"Violated legacy blocker policy: kumquat","type":"invalid_request_error","param":null,"code":"400","provider_specific_fields":{"error":"Violated legacy blocker policy: kumquat","guardrail_name":"legacy-blocker","guardrail_mode":"post_call"}}}
HTTP 400

Control: chat stream, unified content filter with MASK (/v1/chat/completions)

  1. curl -sS -N -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLSbJArWTtTOMohcMpWPzcdZlAx1","object":"chat.completion.chunk","created":1788994418,"model":"gpt-5.4-mini","choices":[{"index":0,"delta":{"role":"assistant","content":"[KEYWORD_REDACTED]"}}]}

data: {"id":"chatcmpl-EMLSbJArWTtTOMohcMpWPzcdZlAx1","object":"chat.completion.chunk","created":1788994418,"model":"gpt-5.4-mini","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-EMLSbJArWTtTOMohcMpWPzcdZlAx1","object":"chat.completion.chunk","created":1788994418,"model":"gpt-5.4-mini","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-EMLSbJArWTtTOMohcMpWPzcdZlAx1","object":"chat.completion.chunk","created":1788994418,"model":"gpt-5.4-mini","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-EMLSbJArWTtTOMohcMpWPzcdZlAx1","object":"chat.completion.chunk","created":1788994418,"model":"gpt-5.4-mini","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Risk probe: chat stream, older hook raising ValueError (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-unguarded","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word coffee and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLScD6g0jUzrzrP06AX5z6c64yFq","object":"chat.completion.chunk","created":1788994418,"model":"gpt-5.4-mini-unguarded","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-EMLScD6g0jUzrzrP06AX5z6c64yFq","object":"chat.completion.chunk","created":1788994418,"model":"gpt-5.4-mini-unguarded","choices":[{"index":0,"delta":{"content":"coffee"}}]}

data: {"id":"chatcmpl-EMLScD6g0jUzrzrP06AX5z6c64yFq","object":"chat.completion.chunk","created":1788994418,"model":"gpt-5.4-mini-unguarded","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]


HTTP 200

Risk probe: chat non-stream, same raising hook (/v1/chat/completions)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-unguarded","messages":[{"role":"user","content":"Reply with exactly the word coffee and nothing else."}]}'
  2. Observed:
{"error":{"message":"Guardrail failed: coffee detected","type":"internal_server_error","param":null,"code":"500"}}
HTTP 500

Risk probe: Responses stream, older hook that only knows the chat shape (/v1/responses), text events only

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/responses -d '{"model":"gpt-5.4-mini-unguarded","stream":true,"input":"Reply with exactly the word tea and nothing else."}'
  2. Observed:
data: {"type":"response.output_text.delta","item_id":"msg_0a282a0fd8404b09006aa1e374cfe887d0a9c24773e3a9ae65","output_index":0,"content_index":0,"delta":"tea","logprobs":[],"obfuscation":"96k8v85HjoLG3","sequence_number":4,"model":"gpt-5.4-mini-unguarded"}
data: {"type":"response.output_text.done","item_id":"msg_0a282a0fd8404b09006aa1e374cfe887d0a9c24773e3a9ae65","output_index":0,"content_index":0,"text":"tea","logprobs":[],"sequence_number":5,"model":"gpt-5.4-mini-unguarded"}
HTTP 200

Risk probe: Responses non-stream, same hook (/v1/responses)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/responses -d '{"model":"gpt-5.4-mini-unguarded","input":"Reply with exactly the word tea and nothing else."}'
  2. Observed:
{"error":{"message":"Invalid request format: 'ResponsesAPIResponse' object has no attribute 'choices'","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

Risk probe: Messages stream, older hook that only knows the chat shape (/v1/messages)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-unguarded","max_tokens":32,"stream":true,"messages":[{"role":"user","content":"Reply with exactly the word tea and nothing else."}]}'
  2. Observed:
event: message_start
data: {"type":"message_start","message":{"model":"claude-haiku-4-5-unguarded","id":"msg_011CetgqceLcUVr97x32gP7W","type":"message","role":"assistant","content":[],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":17,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}              }

event: ping
data: {"type": "ping"}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"tea"}  }

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null},"usage":{"input_tokens":17,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":4}     }

event: message_stop
data: {"type":"message_stop"       }


HTTP 200

Risk probe: chat stream, same raising hook under on_error: allow (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-unguarded-allow","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word coffee and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLSh50SqWCaXx4ojDtKnaNNbQfum","object":"chat.completion.chunk","created":1788994423,"model":"gpt-5.4-mini-unguarded-allow","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-EMLSh50SqWCaXx4ojDtKnaNNbQfum","object":"chat.completion.chunk","created":1788994423,"model":"gpt-5.4-mini-unguarded-allow","choices":[{"index":0,"delta":{"content":"coffee"}}]}

data: {"id":"chatcmpl-EMLSh50SqWCaXx4ojDtKnaNNbQfum","object":"chat.completion.chunk","created":1788994423,"model":"gpt-5.4-mini-unguarded-allow","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]


HTTP 200

Risk probe: chat stream and non-stream on a pipeline the stream cannot gate (/v1/chat/completions), recorder file

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-mixed","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word tea and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLShKkLELQQGYb5pMbo8h0ObMdLn","object":"chat.completion.chunk","created":1788994424,"model":"gpt-5.4-mini-mixed","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-EMLShKkLELQQGYb5pMbo8h0ObMdLn","object":"chat.completion.chunk","created":1788994424,"model":"gpt-5.4-mini-mixed","choices":[{"index":0,"delta":{"content":"tea"}}]}

data: {"id":"chatcmpl-EMLShKkLELQQGYb5pMbo8h0ObMdLn","object":"chat.completion.chunk","created":1788994424,"model":"gpt-5.4-mini-mixed","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]


HTTP 200
  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-mixed","messages":[{"role":"user","content":"Reply with exactly the word tea and nothing else."}]}'
  2. Observed:
{"id":"chatcmpl-EMLSifh1PDbikq8LEu5R7ERPhFoOc","created":1788994424,"model":"gpt-5.4-mini-mixed","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"tea","role":"assistant","provider_specific_fields":{"refusal":null},"annotations":[]},"provider_specific_fields":{}}],"usage":{"completion_tokens":4,"prompt_tokens":16,"total_tokens":20,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0},"prompt_tokens_details":{"audio_tokens":0,"cached_tokens":0}},"service_tier":"default"}
HTTP 200
  1. cat "$LIT7176_RECORD_FILE"
  2. Observed (the first line is the streamed request, the second the non-streamed one):
{"model": "gpt-5.4-mini-mixed", "stream": true, "response_type": "ModelResponse", "ts": 1788994424.147}
{"model": "gpt-5.4-mini-mixed", "stream": null, "response_type": "ModelResponse", "ts": 1788994424.921}

Risk probe: Messages stream and non-stream on a tool-only reply, older hook that leaves tool calls alone (/v1/messages), proxy log

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":64,"stream":true,"tools":[{"name":"get_weather","description":"Get the weather for a city","input_schema":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}],"tool_choice":{"type":"tool","name":"get_weather"},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
event: message_start
data: {"type":"message_start","message":{"model":"claude-haiku-4-5-legacy","id":"msg_011CetgqtsQPMxgJZuaNqLLK","type":"message","role":"assistant","content":[],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":661,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":12,"service_tier":"standard","inference_geo":"not_available"}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"tool_use","id":"toolu_01Lkoqf4KT634SVDxfAmLJ5j","name":"get_weather","input":{},"caller":{"type":"direct"}}       }

event: ping
data: {"type": "ping"}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":""}               }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"{\"city\": \"P"}          }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"aris\"}"}          }

event: content_block_stop
data: {"type":"content_block_stop","index":0       }

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"tool_use","stop_sequence":null,"stop_details":null,"container":null},"usage":{"input_tokens":661,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":33}          }

event: message_stop
data: {"type":"message_stop" }


HTTP 200
  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":64,"tools":[{"name":"get_weather","description":"Get the weather for a city","input_schema":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}],"tool_choice":{"type":"tool","name":"get_weather"},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
{"model":"claude-haiku-4-5-legacy","id":"msg_011CetgqxqXMxRb7AY8iwZqH","type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_01F8e8ie6BVYyss3Uo1uz3ry","name":"get_weather","input":{"city":"Paris"},"caller":{"type":"direct"}}],"container":null,"stop_reason":"tool_use","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":661,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":33,"service_tier":"standard","inference_geo":"not_available"}}
HTTP 200

Risk probe: chat stream through 2 rewriting hooks in one pipeline (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-chained","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word tea and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLSlcSj2D5HmzG4cobAdmg72lDbd","object":"chat.completion.chunk","created":1788994427,"model":"gpt-5.4-mini-chained","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-EMLSlcSj2D5HmzG4cobAdmg72lDbd","object":"chat.completion.chunk","created":1788994427,"model":"gpt-5.4-mini-chained","choices":[{"index":0,"delta":{"content":"tea"}}]}

data: {"id":"chatcmpl-EMLSlcSj2D5HmzG4cobAdmg72lDbd","object":"chat.completion.chunk","created":1788994427,"model":"gpt-5.4-mini-chained","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]


HTTP 200

Risk probe: chat stream and non-stream on a tool call, older hook that masks the arguments in place (/v1/chat/completions), proxy log

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-toolmask","stream":true,"tools":[{"type":"function","function":{"name":"get_weather","description":"Get the weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}],"tool_choice":{"type":"function","function":{"name":"get_weather"}},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
data: {"id":"resp_010c3024da6f54a1006aa1e37c307c87d0b1e357adedd398e1","created":1788994428,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","tool_calls":[{"id":"call_zbfYB8nVeCVmmTmbfDuROVU4","function":{"arguments":"","name":"get_weather"},"type":"function","index":0}]}}]}

data: {"id":"resp_010c3024da6f54a1006aa1e37c307c87d0b1e357adedd398e1","created":1788994428,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"tool_calls":[{"function":{"arguments":"{\""},"type":"function","index":0}]}}]}

data: {"id":"resp_010c3024da6f54a1006aa1e37c307c87d0b1e357adedd398e1","created":1788994428,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"tool_calls":[{"function":{"arguments":"city"},"type":"function","index":0}]}}]}

data: {"id":"resp_010c3024da6f54a1006aa1e37c307c87d0b1e357adedd398e1","created":1788994428,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"tool_calls":[{"function":{"arguments":"\":\""},"type":"function","index":0}]}}]}

data: {"id":"resp_010c3024da6f54a1006aa1e37c307c87d0b1e357adedd398e1","created":1788994428,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"tool_calls":[{"function":{"arguments":"Paris"},"type":"function","index":0}]}}]}

data: {"id":"resp_010c3024da6f54a1006aa1e37c307c87d0b1e357adedd398e1","created":1788994428,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"tool_calls":[{"function":{"arguments":"\"}"},"type":"function","index":0}]}}]}

data: {"id":"resp_010c3024da6f54a1006aa1e37c307c87d0b1e357adedd398e1","created":1788994428,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"finish_reason":"tool_calls","index":0,"delta":{}}],"provider_specific_fields":{"frequency_penalty":0.0,"presence_penalty":0.0,"service_tier":"default","tool_usage":{"image_gen":{"input_tokens":0,"input_tokens_details":{"image_tokens":0,"text_tokens":0},"output_tokens":0,"output_tokens_details":{"image_tokens":0,"text_tokens":0},"total_tokens":0},"web_search":{"num_requests":0}}},"frequency_penalty":0.0,"presence_penalty":0.0,"service_tier":"default","tool_usage":{"image_gen":{"input_tokens":0,"input_tokens_details":{"image_tokens":0,"text_tokens":0},"output_tokens":0,"output_tokens_details":{"image_tokens":0,"text_tokens":0},"total_tokens":0},"web_search":{"num_requests":0}}}

data: [DONE]


HTTP 200
  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-toolmask","tools":[{"type":"function","function":{"name":"get_weather","description":"Get the weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}],"tool_choice":{"type":"function","function":{"name":"get_weather"}},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
{"id":"resp_03061e86d1228e28006aa1e37d19b887d0af383333abafb6d6","created":1788994428,"model":"gpt-5.4-mini-toolmask","object":"chat.completion","choices":[{"finish_reason":"tool_calls","index":0,"message":{"role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"{\"city\": \"***\"}","name":"get_weather"},"id":"call_dP5xmO0JOpXr6a2WQxAdPkOX","type":"function"}],"content":null}}],"usage":{"completion_tokens":18,"prompt_tokens":50,"total_tokens":68,"completion_tokens_details":{"reasoning_tokens":0},"prompt_tokens_details":{"cached_tokens":0,"cache_write_tokens":0,"cache_creation_tokens":0}},"billing":{"payer":"developer"},"frequency_penalty":0.0,"presence_penalty":0.0,"service_tier":"default","tool_usage":{"image_gen":{"input_tokens":0,"input_tokens_details":{"image_tokens":0,"text_tokens":0},"output_tokens":0,"output_tokens_details":{"image_tokens":0,"text_tokens":0},"total_tokens":0},"web_search":{"num_requests":0}}}
HTTP 200
  1. grep discarded litellm.log
  2. Observed (every proxy log line that says a rewrite was discarded and the original stream released, across all the requests above):
(no output)

Risk probe control: chat stream, unified guardrail raising ValueError (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-unified-raiser","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word coffee and nothing else."}]}'
  2. Observed:
{"error":{"message":"Guardrail failed: coffee detected (unified)","type":"None","param":"None","code":"500"}}
HTTP 500

Risk probe: text completion stream through the rewriting hook's pipeline (/v1/completions), headers included

  1. curl -sS -N -i -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/completions -d '{"model":"gpt-5.4-mini-legacy","stream":true,"prompt":"Reply with exactly the word tea and nothing else."}'
  2. Observed:
HTTP/1.1 200 OK
date: Wed, 09 Sep 2026 22:53:48 GMT
x-litellm-call-id: 622019c1-1da4-4e64-8e9a-a4c25d90138b
x-litellm-model-name: openai/gpt-5.4-mini
x-litellm-version: 1.102.0
x-litellm-key-spend: 0.0
x-litellm-response-duration-ms: 539.7149999999999
x-litellm-overhead-duration-ms: 3.344
x-litellm-model-group: gpt-5.4-mini-legacy
x-litellm-attempted-retries: 0
x-litellm-attempted-fallbacks: 0
x-litellm-applied-guardrails: legacy-rewriter
x-litellm-applied-policies: legacy-governance
x-litellm-policy-sources: legacy-governance=model:gpt-5.4-mini-legacy
cache-control: no-cache
x-accel-buffering: no
content-type: text/event-stream; charset=utf-8
x-frame-options: DENY
content-security-policy: frame-ancestors 'none'
x-content-type-options: nosniff
Transfer-Encoding: chunked

data: {"id":"chatcmpl-EMLSoqejSF2Hmg39lGQFn8WNcRRDE","object":"text_completion","created":1788994430,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"text":""}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}

data: {"id":"chatcmpl-EMLSoqejSF2Hmg39lGQFn8WNcRRDE","object":"text_completion","created":1788994430,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"text":"tea"}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}

data: {"id":"chatcmpl-EMLSoqejSF2Hmg39lGQFn8WNcRRDE","object":"text_completion","created":1788994430,"model":"gpt-5.4-mini-legacy","choices":[{"finish_reason":"stop","index":0}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}

data: {"id":"chatcmpl-EMLSoqejSF2Hmg39lGQFn8WNcRRDE","object":"text_completion","created":1788994430,"model":"gpt-5.4-mini-legacy","choices":[{"index":0}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}

data: [DONE]

Risk probe: chat stream and non-stream on a tool call through the built-in tool_permission guardrail, which has its own streaming hook (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-toolperm","stream":true,"tools":[{"type":"function","function":{"name":"get_weather","description":"Get the weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}],"tool_choice":{"type":"function","function":{"name":"get_weather"}},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
{"error":{"message":"Guardrail raised an exception, Guardrail: tool-permission-builtin, Message: Tool 'get_weather' denied by rule 'deny_weather'","type":"None","param":"None","code":"400"}}
HTTP 400
  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-toolperm","tools":[{"type":"function","function":{"name":"get_weather","description":"Get the weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}],"tool_choice":{"type":"function","function":{"name":"get_weather"}},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
{"error":{"message":"Guardrail raised an exception, Guardrail: tool-permission-builtin, Message: Tool 'get_weather' denied by rule 'deny_weather'","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

Risk probe: chat stream through the rewriting hook's pipeline with the response headers (/v1/chat/completions)

  1. curl -sS -N -i -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word tea and nothing else."}]}'
  2. Observed:
HTTP/1.1 200 OK
date: Wed, 09 Sep 2026 22:53:53 GMT
x-litellm-call-id: 73292edc-429b-411a-a6c5-f5295a920874
x-litellm-model-id: 609874a8bca5ce1a12dcbacf2231ab8865b002eece228fee13c8963cc2c93828
x-litellm-model-name: openai/gpt-5.4-mini
x-litellm-model-api-base: https://api.openai.com
x-litellm-version: 1.102.0
x-litellm-response-cost-original: 0.0
x-litellm-response-cost-discount-amount: 0.0
x-litellm-response-cost-margin-amount: 0.0
x-litellm-response-cost-margin-percent: 0.0
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
x-litellm-response-cost-tool-usage: 0.0
x-litellm-key-spend: 0.0
x-litellm-response-duration-ms: 488.82
x-litellm-overhead-duration-ms: 11.353
x-litellm-callback-duration-ms: 0.0
x-ratelimit-limit-requests: 30000
x-ratelimit-limit-tokens: 180000000
x-ratelimit-remaining-requests: 29999
x-ratelimit-remaining-tokens: 179999985
x-ratelimit-reset-requests: 2ms
x-ratelimit-reset-tokens: 0s
llm_provider-date: Wed, 09 Sep 2026 22:53:54 GMT
llm_provider-content-type: text/event-stream; charset=utf-8
llm_provider-transfer-encoding: chunked
llm_provider-connection: keep-alive
llm_provider-cf-ray: a389c58c1aa6cf12-SJC
llm_provider-cf-cache-status: DYNAMIC
llm_provider-server: cloudflare
llm_provider-strict-transport-security: max-age=31536000; includeSubDomains; preload
llm_provider-x-content-type-options: nosniff
llm_provider-access-control-expose-headers: X-Request-ID, CF-Ray, CF-Ray
llm_provider-openai-organization: personal-1e898z
llm_provider-openai-processing-ms: 406
llm_provider-openai-project: proj_WG9WJ3ACNqlcabNE2emRzoqT
llm_provider-openai-version: 2020-10-01
llm_provider-x-openai-proxy-wasm: v0.1
llm_provider-x-ratelimit-limit-requests: 30000
llm_provider-x-ratelimit-limit-tokens: 180000000
llm_provider-x-ratelimit-remaining-requests: 29999
llm_provider-x-ratelimit-remaining-tokens: 179999985
llm_provider-x-ratelimit-reset-requests: 2ms
llm_provider-x-ratelimit-reset-tokens: 0s
llm_provider-x-request-id: req_e3edb88e3a804b85a8de770050c51fde
llm_provider-alt-svc: h3=":443"; ma=86400
x-litellm-model-group: gpt-5.4-mini-legacy
x-litellm-attempted-retries: 0
x-litellm-attempted-fallbacks: 0
x-litellm-applied-guardrails: legacy-rewriter
x-litellm-applied-policies: legacy-governance
x-litellm-policy-sources: legacy-governance=model:gpt-5.4-mini-legacy
cache-control: no-cache
x-accel-buffering: no
content-type: text/event-stream; charset=utf-8
x-frame-options: DENY
content-security-policy: frame-ancestors 'none'
x-content-type-options: nosniff
Transfer-Encoding: chunked

data: {"id":"chatcmpl-EMLSsMeD1lVgFBfkdgUcTonQCqDs9","object":"chat.completion.chunk","created":1788994434,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-EMLSsMeD1lVgFBfkdgUcTonQCqDs9","object":"chat.completion.chunk","created":1788994434,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":"tea"}}]}

data: {"id":"chatcmpl-EMLSsMeD1lVgFBfkdgUcTonQCqDs9","object":"chat.completion.chunk","created":1788994434,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Risk probe: Messages stream and non-stream through the blocking hook, which only reads the chat shape (/v1/messages)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy-block","max_tokens":32,"stream":true,"messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
event: message_start
data: {"type":"message_start","message":{"model":"claude-haiku-4-5-legacy-block","id":"msg_011Cetgrbn2nV7jBEnKVN8mh","type":"message","role":"assistant","content":[],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}             }

event: ping
data: {"type": "ping"}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"kum"}        }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"quat"}       }

event: content_block_stop
data: {"type":"content_block_stop","index":0              }

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null},"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":6}     }

event: message_stop
data: {"type":"message_stop"           }


HTTP 200
  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy-block","max_tokens":32,"messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
{"model":"claude-haiku-4-5-legacy-block","id":"msg_011CetgreVjqo93Fd1ycxwKz","type":"message","role":"assistant","content":[{"type":"text","text":"kumquat"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"service_tier":"standard","inference_geo":"not_available"}}
HTTP 200

Risk probe: Gemini stream through the rewriting hook's pipeline (/v1beta/models/{model}:streamGenerateContent), headers included

  1. curl -sS -N -i -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" 'http://localhost:37779/v1beta/models/gemini-flash-legacy:streamGenerateContent?alt=sse' -d '{"contents":[{"role":"user","parts":[{"text":"Reply with exactly the word tea and nothing else."}]}]}'
  2. Observed:
HTTP/1.1 200 OK
date: Wed, 09 Sep 2026 22:53:51 GMT
x-litellm-call-id: 3c57e59b-5699-42b8-b160-be5bc572da9f
x-litellm-model-id: 4ad4824c0e902119eeac6910c499b9cd59ec76825ef577d48cad516d204632ee
x-litellm-model-name: gemini/gemini-3.8-flash
x-litellm-model-api-base: https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent
x-litellm-version: 1.102.0
x-litellm-response-cost-original: 0.0
x-litellm-response-cost-discount-amount: 0.0
x-litellm-response-cost-margin-amount: 0.0
x-litellm-response-cost-margin-percent: 0.0
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
x-litellm-response-cost-tool-usage: 0.0
x-litellm-key-spend: 0.0
x-litellm-response-duration-ms: 1594.126
x-litellm-callback-duration-ms: 0.0
llm_provider-content-type: text/event-stream
llm_provider-content-disposition: attachment
llm_provider-vary: Origin, X-Origin, Referer
llm_provider-transfer-encoding: chunked
llm_provider-date: Wed, 09 Sep 2026 22:53:53 GMT
llm_provider-server: scaffolding on HTTPServer2
llm_provider-x-xss-protection: 0
llm_provider-x-frame-options: SAMEORIGIN
llm_provider-x-content-type-options: nosniff
llm_provider-server-timing: gfet4t7; dur=1530
llm_provider-alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
x-litellm-model-group: gemini-flash-legacy
x-ratelimit-remaining-tokens: 800000
x-ratelimit-limit-tokens: 800000
x-ratelimit-remaining-requests: 1999
x-ratelimit-limit-requests: 2000
x-litellm-attempted-retries: 0
x-litellm-attempted-fallbacks: 0
x-litellm-applied-guardrails: legacy-rewriter
x-litellm-applied-policies: legacy-governance
x-litellm-policy-sources: legacy-governance=model:gemini-flash-legacy
cache-control: no-cache
x-accel-buffering: no
content-type: text/event-stream; charset=utf-8
x-frame-options: DENY
content-security-policy: frame-ancestors 'none'
x-content-type-options: nosniff
Transfer-Encoding: chunked

data: {"candidates": [{"content": {"parts": [{"text": "tea"}],"role": "model"},"index": 0}],"usageMetadata": {"promptTokenCount": 11,"candidatesTokenCount": 1,"totalTokenCount": 141,"promptTokensDetails": [{"modality": "TEXT","tokenCount": 11}],"thoughtsTokenCount": 129,"serviceTier": "standard"},"modelVersion": "gemini-3.8-flash","responseId": "gOOhaue2GMeo1MkP57ihUQ"}

data: {"candidates": [{"content": {"parts": [{"text": "","thoughtSignature": "EqUFCqIFARFNMg/wzozCzJgHnNOiotXj3Vh0mXixXVyngqrjG7Nv4m9mxbmjtj5DKbtnCyxzuqqHxzjrlxrzTwCUrLYrzaMvlv0pJ8D1XGi3vRsVuLnEvCwntFxldBsTQVVxKTDA4FIXIbWIf6fWQRuTiRk3P7AVZ0N5LCT53jXb1tE+VNJ6KDp8pt5OunAOeF77Husiua7hg9uUEkC6kqqvRwvLwOHZdpkmXMvN0i0LoG1bLWnQyuNQTkMfVHwlxE8JhGjVJL7dDWMhzoWx1ITA+nNIb6Mr+fh1xfeU5T2V9WTfvn1yVqeLTDDoKfK9VMR0ihrth3clL88/sZpqp+nNpjCEJv2DYReSL89Ge+vCoB7zrWfNld3VW5poKFG5G/wKGRvcJlN4lfnGuwQMLVO/yPYbBJd42e841xr6H9cy5+ErZwwfwhMEehGumhNEG3+KchbKmmfmEayZLmLNZ4Z7SG4PAeaQZwVHGjN/+kSDwjowg9rAfifUNoXVGRVskOu7zY8HW5n8lhsmDEORwhzDskmAqZFxwTP1OdBvOR27XW9Wo2O4D+RypYaIUK3GaC1FIKgKyFvjazgQ4dORJSBpI52/bO1aKTBqRBIC1zkFKc9DqqXE+z5Swme22n7Nw+rtBJ1IirSKbqLGgSdwhIdNVdHwc77ResfLyN9hnahy2e75Ywek63vVGmRGlel6+TX5rDTnCtrV2AzLkzb1+rzzlgy8hhOm0ykF1Jsw8ZicL6tq9GDDXA9R1GntfTYBQFkG7E249j7KiuHyFulV7aN7p6YWBcUAWwMlCXx5rNJtX/wcGLE7/KiQbTRoS+cNg+JLLTksryoHF6/wWnEBcalLfk3Uio7eioEWzGZADgg/1DOFjm4vUGsgUPf1Llbfr5m6Ribp8eg="}],"role": "model"},"finishReason": "STOP","index": 0}],"usageMetadata": {"promptTokenCount": 11,"candidatesTokenCount": 1,"totalTokenCount": 141,"promptTokensDetails": [{"modality": "TEXT","tokenCount": 11}],"thoughtsTokenCount": 129,"serviceTier": "standard"},"modelVersion": "gemini-3.8-flash","responseId": "gOOhaue2GMeo1MkP57ihUQ"}

After (5fdbb2a)

Chat stream, legacy rewriter (/v1/chat/completions)

  1. curl -sS -N -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLTErb5UrpBEPZwfqqZe2iScDbHY","object":"chat.completion.chunk","created":1788994457,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"role":"assistant","content":"[REWRITTEN BY LEGACY HOOK] persimmon"}}]}

data: {"id":"chatcmpl-EMLTErb5UrpBEPZwfqqZe2iScDbHY","object":"chat.completion.chunk","created":1788994457,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-EMLTErb5UrpBEPZwfqqZe2iScDbHY","object":"chat.completion.chunk","created":1788994457,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-EMLTErb5UrpBEPZwfqqZe2iScDbHY","object":"chat.completion.chunk","created":1788994457,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-EMLTErb5UrpBEPZwfqqZe2iScDbHY","object":"chat.completion.chunk","created":1788994457,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Chat non-stream, legacy rewriter (/v1/chat/completions)

  1. curl -sS -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy","messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
{"id":"chatcmpl-EMLTGDjMwAmq02WeicFrSTUb07kFT","created":1788994458,"model":"gpt-5.4-mini-legacy","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"[REWRITTEN BY LEGACY HOOK] persimmon","role":"assistant","provider_specific_fields":{"refusal":null},"annotations":[]},"provider_specific_fields":{}}],"usage":{"completion_tokens":6,"prompt_tokens":18,"total_tokens":24,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0},"prompt_tokens_details":{"audio_tokens":0,"cached_tokens":0}},"service_tier":"default"}```

#### Messages stream, legacy rewriter (/v1/messages)

1. `curl -sS -N -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":32,"stream":true,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'`
2. Observed:

```text
event: message_start
data: {"type":"message_start","message":{"model":"claude-haiku-4-5-legacy","id":"msg_011CetgtR3RL64ThEuxuEhSJ","type":"message","role":"assistant","content":[],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}      }

event: ping
data: {"type": "ping"}

event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "[REWRITTEN BY LEGACY HOOK] persimmon"}}

event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": ""}}

event: content_block_stop
data: {"type":"content_block_stop","index":0              }

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null},"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":6}              }

event: message_stop
data: {"type":"message_stop"       }

Messages non-stream, legacy rewriter (/v1/messages)

  1. curl -sS -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":32,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
{"model":"claude-haiku-4-5-legacy","id":"msg_011CetgtTyHFUeY3aBKtC4RW","type":"message","role":"assistant","content":[{"type":"text","text":"[REWRITTEN BY LEGACY HOOK] persimmon"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"service_tier":"standard","inference_geo":"not_available"}}```

#### Responses stream, legacy rewriter (/v1/responses), text events only

1. `curl -sS -N -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/responses -d '{"model":"gpt-5.4-mini-legacy","stream":true,"input":"Reply with exactly the word persimmon and nothing else."}' | grep -E 'output_text\.(delta|done)'`
2. Observed:

```text
data: {"type":"response.output_text.delta","item_id":"msg_0aba791895ccf4df006aa1e39d177887d08274326fc3deb39d","output_index":0,"content_index":0,"delta":"[REWRITTEN BY LEGACY HOOK] persimmon","logprobs":[],"obfuscation":"Bc8Ggbagzqio","sequence_number":4,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.delta","item_id":"msg_0aba791895ccf4df006aa1e39d177887d08274326fc3deb39d","output_index":0,"content_index":0,"delta":"","logprobs":[],"obfuscation":"gnTuuuri10hTmD","sequence_number":5,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.delta","item_id":"msg_0aba791895ccf4df006aa1e39d177887d08274326fc3deb39d","output_index":0,"content_index":0,"delta":"","logprobs":[],"obfuscation":"5RgCfnO7DG7i3","sequence_number":6,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.done","item_id":"msg_0aba791895ccf4df006aa1e39d177887d08274326fc3deb39d","output_index":0,"content_index":0,"text":"[REWRITTEN BY LEGACY HOOK] persimmon","logprobs":[],"sequence_number":7,"model":"gpt-5.4-mini-legacy"}

Responses non-stream, legacy rewriter (/v1/responses)

  1. curl -sS -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/responses -d '{"model":"gpt-5.4-mini-legacy","input":"Reply with exactly the word persimmon and nothing else."}' | jq -c '{status, output: [.output[] | {type, content}]}'
  2. Observed:
{"status":"completed","output":[{"type":"message","content":[{"annotations":[],"text":"[REWRITTEN BY LEGACY HOOK] persimmon","type":"output_text","logprobs":[]}]}]}

Chat stream, legacy blocker (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy-block","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
data: {"error": {"message": "Violated legacy blocker policy: kumquat", "type": "invalid_request_error", "param": null, "code": "400", "provider_specific_fields": {"error": "Violated legacy blocker policy: kumquat", "guardrail_name": "legacy-blocker", "guardrail_mode": "post_call"}}}

data: [DONE]


HTTP 400

Chat non-stream, legacy blocker (/v1/chat/completions)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy-block","messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
{"error":{"message":"Violated legacy blocker policy: kumquat","type":"invalid_request_error","param":null,"code":"400","provider_specific_fields":{"error":"Violated legacy blocker policy: kumquat","guardrail_name":"legacy-blocker","guardrail_mode":"post_call"}}}
HTTP 400

Control: chat stream, unified content filter with MASK (/v1/chat/completions)

  1. curl -sS -N -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLTMKqlM2A6SMiH5Ze0DMni1Zoyv","object":"chat.completion.chunk","created":1788994464,"model":"gpt-5.4-mini","choices":[{"index":0,"delta":{"role":"assistant","content":"[KEYWORD_REDACTED]"}}]}

data: {"id":"chatcmpl-EMLTMKqlM2A6SMiH5Ze0DMni1Zoyv","object":"chat.completion.chunk","created":1788994464,"model":"gpt-5.4-mini","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-EMLTMKqlM2A6SMiH5Ze0DMni1Zoyv","object":"chat.completion.chunk","created":1788994464,"model":"gpt-5.4-mini","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-EMLTMKqlM2A6SMiH5Ze0DMni1Zoyv","object":"chat.completion.chunk","created":1788994464,"model":"gpt-5.4-mini","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-EMLTMKqlM2A6SMiH5Ze0DMni1Zoyv","object":"chat.completion.chunk","created":1788994464,"model":"gpt-5.4-mini","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Risk probe: chat stream, older hook raising ValueError (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-unguarded","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word coffee and nothing else."}]}'
  2. Observed:
{"error":{"message":"Guardrail failed: coffee detected","type":"None","param":"None","code":"500"}}
HTTP 500

Risk probe: chat non-stream, same raising hook (/v1/chat/completions)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-unguarded","messages":[{"role":"user","content":"Reply with exactly the word coffee and nothing else."}]}'
  2. Observed:
{"error":{"message":"Guardrail failed: coffee detected","type":"internal_server_error","param":null,"code":"500"}}
HTTP 500

Risk probe: Responses stream, older hook that only knows the chat shape (/v1/responses), text events only

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/responses -d '{"model":"gpt-5.4-mini-unguarded","stream":true,"input":"Reply with exactly the word tea and nothing else."}'
  2. Observed:
{"error":{"message":"'ResponsesAPIResponse' object has no attribute 'choices'","type":"None","param":"None","code":"500"}}
HTTP 500

Risk probe: Responses non-stream, same hook (/v1/responses)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/responses -d '{"model":"gpt-5.4-mini-unguarded","input":"Reply with exactly the word tea and nothing else."}'
  2. Observed:
{"error":{"message":"Invalid request format: 'ResponsesAPIResponse' object has no attribute 'choices'","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

Risk probe: Messages stream, older hook that only knows the chat shape (/v1/messages)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-unguarded","max_tokens":32,"stream":true,"messages":[{"role":"user","content":"Reply with exactly the word tea and nothing else."}]}'
  2. Observed:
{"error":{"message":"'dict' object has no attribute 'choices'","type":"internal_server_error","param":null,"code":"500"}}
HTTP 500

Risk probe: chat stream, same raising hook under on_error: allow (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-unguarded-allow","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word coffee and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLTTuN2RVdRG5PeTx8CYwgtJCo8M","object":"chat.completion.chunk","created":1788994471,"model":"gpt-5.4-mini-unguarded-allow","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-EMLTTuN2RVdRG5PeTx8CYwgtJCo8M","object":"chat.completion.chunk","created":1788994471,"model":"gpt-5.4-mini-unguarded-allow","choices":[{"index":0,"delta":{"content":"coffee"}}]}

data: {"id":"chatcmpl-EMLTTuN2RVdRG5PeTx8CYwgtJCo8M","object":"chat.completion.chunk","created":1788994471,"model":"gpt-5.4-mini-unguarded-allow","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]


HTTP 200

Risk probe: chat stream and non-stream on a pipeline the stream cannot gate (/v1/chat/completions), recorder file

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-mixed","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word tea and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLTUPbJX7IbzeJCfedmqNFBMFAAa","object":"chat.completion.chunk","created":1788994472,"model":"gpt-5.4-mini-mixed","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-EMLTUPbJX7IbzeJCfedmqNFBMFAAa","object":"chat.completion.chunk","created":1788994472,"model":"gpt-5.4-mini-mixed","choices":[{"index":0,"delta":{"content":"tea"}}]}

data: {"id":"chatcmpl-EMLTUPbJX7IbzeJCfedmqNFBMFAAa","object":"chat.completion.chunk","created":1788994472,"model":"gpt-5.4-mini-mixed","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]


HTTP 200
  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-mixed","messages":[{"role":"user","content":"Reply with exactly the word tea and nothing else."}]}'
  2. Observed:
{"id":"chatcmpl-EMLTVXwgQJbXY0rp73Q48r8cXnFsu","created":1788994473,"model":"gpt-5.4-mini-mixed","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"tea","role":"assistant","provider_specific_fields":{"refusal":null},"annotations":[]},"provider_specific_fields":{}}],"usage":{"completion_tokens":4,"prompt_tokens":16,"total_tokens":20,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0},"prompt_tokens_details":{"audio_tokens":0,"cached_tokens":0}},"service_tier":"default"}
HTTP 200
  1. cat "$LIT7176_RECORD_FILE"
  2. Observed (the first line is the streamed request, the second the non-streamed one):
{"model": "gpt-5.4-mini-mixed", "stream": true, "response_type": "ModelResponse", "ts": 1788994472.597}
{"model": "gpt-5.4-mini-mixed", "stream": null, "response_type": "ModelResponse", "ts": 1788994473.405}

Risk probe: Messages stream and non-stream on a tool-only reply, older hook that leaves tool calls alone (/v1/messages), proxy log

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":64,"stream":true,"tools":[{"name":"get_weather","description":"Get the weather for a city","input_schema":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}],"tool_choice":{"type":"tool","name":"get_weather"},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
event: message_start
data: {"type":"message_start","message":{"model":"claude-haiku-4-5-legacy","id":"msg_011CetguU234ZYjnBLh5PWGu","type":"message","role":"assistant","content":[],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":661,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":12,"service_tier":"standard","inference_geo":"not_available"}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"tool_use","id":"toolu_01ThhCoCpBLqnuM7an4XsEC8","name":"get_weather","input":{},"caller":{"type":"direct"}}               }

event: ping
data: {"type": "ping"}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":""}              }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"{\"city\""}         }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":": \"Pari"}  }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"s\"}"}      }

event: content_block_stop
data: {"type":"content_block_stop","index":0       }

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"tool_use","stop_sequence":null,"stop_details":null,"container":null},"usage":{"input_tokens":661,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":33}       }

event: message_stop
data: {"type":"message_stop"             }


HTTP 200
  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":64,"tools":[{"name":"get_weather","description":"Get the weather for a city","input_schema":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}],"tool_choice":{"type":"tool","name":"get_weather"},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
{"model":"claude-haiku-4-5-legacy","id":"msg_011CetguXDXUyXFCCt4FBHE1","type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_01YPsU5Gjpic9roVQbx4a65i","name":"get_weather","input":{"city":"Paris"},"caller":{"type":"direct"}}],"container":null,"stop_reason":"tool_use","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":661,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":33,"service_tier":"standard","inference_geo":"not_available"}}
HTTP 200

Risk probe: chat stream through 2 rewriting hooks in one pipeline (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-chained","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word tea and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-EMLTXIZlZ5WCUByDWi5S6xThCE70k","object":"chat.completion.chunk","created":1788994475,"model":"gpt-5.4-mini-chained","choices":[{"index":0,"delta":{"role":"assistant","content":"[REWRITTEN BY LEGACY HOOK] [REWRITTEN BY LEGACY HOOK] tea"}}]}

data: {"id":"chatcmpl-EMLTXIZlZ5WCUByDWi5S6xThCE70k","object":"chat.completion.chunk","created":1788994475,"model":"gpt-5.4-mini-chained","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-EMLTXIZlZ5WCUByDWi5S6xThCE70k","object":"chat.completion.chunk","created":1788994475,"model":"gpt-5.4-mini-chained","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]


HTTP 200

Risk probe: chat stream and non-stream on a tool call, older hook that masks the arguments in place (/v1/chat/completions), proxy log

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-toolmask","stream":true,"tools":[{"type":"function","function":{"name":"get_weather","description":"Get the weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}],"tool_choice":{"type":"function","function":{"name":"get_weather"}},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
data: {"id":"resp_08bd933323814b7f006aa1e3abec5487d0af203ed54af45816","created":1788994476,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","tool_calls":[{"id":"call_w0EBNfEOxmN3pbpy6j3BUTrt","function":{"arguments":"","name":"get_weather"},"type":"function","index":0}]}}]}

data: {"id":"resp_08bd933323814b7f006aa1e3abec5487d0af203ed54af45816","created":1788994476,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"tool_calls":[{"function":{"arguments":"{\""},"type":"function","index":0}]}}]}

data: {"id":"resp_08bd933323814b7f006aa1e3abec5487d0af203ed54af45816","created":1788994476,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"tool_calls":[{"function":{"arguments":"city"},"type":"function","index":0}]}}]}

data: {"id":"resp_08bd933323814b7f006aa1e3abec5487d0af203ed54af45816","created":1788994476,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"tool_calls":[{"function":{"arguments":"\":\""},"type":"function","index":0}]}}]}

data: {"id":"resp_08bd933323814b7f006aa1e3abec5487d0af203ed54af45816","created":1788994476,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"tool_calls":[{"function":{"arguments":"Paris"},"type":"function","index":0}]}}]}

data: {"id":"resp_08bd933323814b7f006aa1e3abec5487d0af203ed54af45816","created":1788994476,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"tool_calls":[{"function":{"arguments":"\"}"},"type":"function","index":0}]}}]}

data: {"id":"resp_08bd933323814b7f006aa1e3abec5487d0af203ed54af45816","created":1788994476,"model":"gpt-5.4-mini-toolmask","object":"chat.completion.chunk","choices":[{"finish_reason":"tool_calls","index":0,"delta":{}}],"provider_specific_fields":{"frequency_penalty":0.0,"presence_penalty":0.0,"service_tier":"default","tool_usage":{"image_gen":{"input_tokens":0,"input_tokens_details":{"image_tokens":0,"text_tokens":0},"output_tokens":0,"output_tokens_details":{"image_tokens":0,"text_tokens":0},"total_tokens":0},"web_search":{"num_requests":0}}},"frequency_penalty":0.0,"presence_penalty":0.0,"service_tier":"default","tool_usage":{"image_gen":{"input_tokens":0,"input_tokens_details":{"image_tokens":0,"text_tokens":0},"output_tokens":0,"output_tokens_details":{"image_tokens":0,"text_tokens":0},"total_tokens":0},"web_search":{"num_requests":0}}}

data: [DONE]


HTTP 200
  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-toolmask","tools":[{"type":"function","function":{"name":"get_weather","description":"Get the weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}],"tool_choice":{"type":"function","function":{"name":"get_weather"}},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
{"id":"resp_06516a2699f23f81006aa1e3ace69c87d08094acec8be87f69","created":1788994476,"model":"gpt-5.4-mini-toolmask","object":"chat.completion","choices":[{"finish_reason":"tool_calls","index":0,"message":{"role":"assistant","tool_calls":[{"index":0,"function":{"arguments":"{\"city\": \"***\"}","name":"get_weather"},"id":"call_4wUmFTSth4Xvs6ojLOWbAU0y","type":"function"}],"content":null}}],"usage":{"completion_tokens":18,"prompt_tokens":50,"total_tokens":68,"completion_tokens_details":{"reasoning_tokens":0},"prompt_tokens_details":{"cached_tokens":0,"cache_write_tokens":0,"cache_creation_tokens":0}},"billing":{"payer":"developer"},"frequency_penalty":0.0,"presence_penalty":0.0,"service_tier":"default","tool_usage":{"image_gen":{"input_tokens":0,"input_tokens_details":{"image_tokens":0,"text_tokens":0},"output_tokens":0,"output_tokens_details":{"image_tokens":0,"text_tokens":0},"total_tokens":0},"web_search":{"num_requests":0}}}
HTTP 200
  1. grep discarded litellm.log
  2. Observed (every proxy log line that says a rewrite was discarded and the original stream released, across all the requests above):
15:54:36 - LiteLLM Proxy:WARNING: pipeline_executor.py:260 - Pipeline: guardrail 'legacy-tool-masker' rewrote the streamed response in a way this endpoint's streaming pipeline cannot deliver yet; the rewrite was discarded and the original stream released

Risk probe control: chat stream, unified guardrail raising ValueError (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-unified-raiser","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word coffee and nothing else."}]}'
  2. Observed:
{"error":{"message":"Guardrail failed: coffee detected (unified)","type":"None","param":"None","code":"500"}}
HTTP 500

Risk probe: text completion stream through the rewriting hook's pipeline (/v1/completions), headers included

  1. curl -sS -N -i -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/completions -d '{"model":"gpt-5.4-mini-legacy","stream":true,"prompt":"Reply with exactly the word tea and nothing else."}'
  2. Observed:
HTTP/1.1 200 OK
date: Wed, 09 Sep 2026 22:54:37 GMT
x-litellm-call-id: 31c137d7-7907-4e42-9a11-7de5e56fac6b
x-litellm-model-name: openai/gpt-5.4-mini
x-litellm-version: 1.102.0
x-litellm-key-spend: 0.0
x-litellm-response-duration-ms: 510.783
x-litellm-overhead-duration-ms: 4.322
x-litellm-model-group: gpt-5.4-mini-legacy
x-litellm-attempted-retries: 0
x-litellm-attempted-fallbacks: 0
x-litellm-applied-guardrails: legacy-rewriter
x-litellm-applied-policies: legacy-governance
x-litellm-policy-sources: legacy-governance=model:gpt-5.4-mini-legacy
cache-control: no-cache
x-accel-buffering: no
content-type: text/event-stream; charset=utf-8
x-frame-options: DENY
content-security-policy: frame-ancestors 'none'
x-content-type-options: nosniff
Transfer-Encoding: chunked

data: {"id":"chatcmpl-EMLTZAmYc6eVaERAnokfsNtsOOIeR","object":"text_completion","created":1788994478,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"text":""}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}

data: {"id":"chatcmpl-EMLTZAmYc6eVaERAnokfsNtsOOIeR","object":"text_completion","created":1788994478,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"text":"tea"}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}

data: {"id":"chatcmpl-EMLTZAmYc6eVaERAnokfsNtsOOIeR","object":"text_completion","created":1788994478,"model":"gpt-5.4-mini-legacy","choices":[{"finish_reason":"stop","index":0}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}

data: {"id":"chatcmpl-EMLTZAmYc6eVaERAnokfsNtsOOIeR","object":"text_completion","created":1788994478,"model":"gpt-5.4-mini-legacy","choices":[{"index":0}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}

data: [DONE]

Risk probe: chat stream and non-stream on a tool call through the built-in tool_permission guardrail, which has its own streaming hook (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-toolperm","stream":true,"tools":[{"type":"function","function":{"name":"get_weather","description":"Get the weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}],"tool_choice":{"type":"function","function":{"name":"get_weather"}},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
{"error":{"message":"Guardrail raised an exception, Guardrail: tool-permission-builtin, Message: Tool 'get_weather' denied by rule 'deny_weather'","type":"None","param":"None","code":"400"}}
HTTP 400
  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-toolperm","tools":[{"type":"function","function":{"name":"get_weather","description":"Get the weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}],"tool_choice":{"type":"function","function":{"name":"get_weather"}},"messages":[{"role":"user","content":"What is the weather in Paris?"}]}'
  2. Observed:
{"error":{"message":"Guardrail raised an exception, Guardrail: tool-permission-builtin, Message: Tool 'get_weather' denied by rule 'deny_weather'","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

Risk probe: chat stream through the rewriting hook's pipeline with the response headers (/v1/chat/completions)

  1. curl -sS -N -i -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:37779/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word tea and nothing else."}]}'
  2. Observed:
HTTP/1.1 200 OK
date: Wed, 09 Sep 2026 22:54:40 GMT
x-litellm-call-id: 19043623-e8c4-4e9a-9572-374fe9489388
x-litellm-model-id: 609874a8bca5ce1a12dcbacf2231ab8865b002eece228fee13c8963cc2c93828
x-litellm-model-name: openai/gpt-5.4-mini
x-litellm-model-api-base: https://api.openai.com
x-litellm-version: 1.102.0
x-litellm-response-cost-original: 0.0
x-litellm-response-cost-discount-amount: 0.0
x-litellm-response-cost-margin-amount: 0.0
x-litellm-response-cost-margin-percent: 0.0
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
x-litellm-response-cost-tool-usage: 0.0
x-litellm-key-spend: 0.0
x-litellm-response-duration-ms: 852.3770000000001
x-litellm-overhead-duration-ms: 5.093
x-litellm-callback-duration-ms: 0.0
x-ratelimit-limit-requests: 30000
x-ratelimit-limit-tokens: 180000000
x-ratelimit-remaining-requests: 29999
x-ratelimit-remaining-tokens: 179999985
x-ratelimit-reset-requests: 2ms
x-ratelimit-reset-tokens: 0s
llm_provider-date: Wed, 09 Sep 2026 22:54:42 GMT
llm_provider-content-type: text/event-stream; charset=utf-8
llm_provider-transfer-encoding: chunked
llm_provider-connection: keep-alive
llm_provider-cf-ray: a389c6b50f2f2db6-SJC
llm_provider-cf-cache-status: DYNAMIC
llm_provider-server: cloudflare
llm_provider-strict-transport-security: max-age=31536000; includeSubDomains; preload
llm_provider-x-content-type-options: nosniff
llm_provider-access-control-expose-headers: X-Request-ID, CF-Ray, CF-Ray
llm_provider-openai-organization: personal-1e898z
llm_provider-openai-processing-ms: 771
llm_provider-openai-project: proj_WG9WJ3ACNqlcabNE2emRzoqT
llm_provider-openai-version: 2020-10-01
llm_provider-x-openai-proxy-wasm: v0.1
llm_provider-x-ratelimit-limit-requests: 30000
llm_provider-x-ratelimit-limit-tokens: 180000000
llm_provider-x-ratelimit-remaining-requests: 29999
llm_provider-x-ratelimit-remaining-tokens: 179999985
llm_provider-x-ratelimit-reset-requests: 2ms
llm_provider-x-ratelimit-reset-tokens: 0s
llm_provider-x-request-id: req_a82aacc9bb514b919345f3ad820a95c0
llm_provider-alt-svc: h3=":443"; ma=86400
x-litellm-model-group: gpt-5.4-mini-legacy
x-litellm-attempted-retries: 0
x-litellm-attempted-fallbacks: 0
x-litellm-applied-guardrails: legacy-rewriter
x-litellm-applied-policies: legacy-governance
x-litellm-policy-sources: legacy-governance=model:gpt-5.4-mini-legacy
cache-control: no-cache
x-accel-buffering: no
content-type: text/event-stream; charset=utf-8
x-frame-options: DENY
content-security-policy: frame-ancestors 'none'
x-content-type-options: nosniff
Transfer-Encoding: chunked

data: {"id":"chatcmpl-EMLTdoCXgcOYz3JKmWPM4MxLSgNuU","object":"chat.completion.chunk","created":1788994482,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"role":"assistant","content":"[REWRITTEN BY LEGACY HOOK] tea"}}]}

data: {"id":"chatcmpl-EMLTdoCXgcOYz3JKmWPM4MxLSgNuU","object":"chat.completion.chunk","created":1788994482,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-EMLTdoCXgcOYz3JKmWPM4MxLSgNuU","object":"chat.completion.chunk","created":1788994482,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Risk probe: Messages stream and non-stream through the blocking hook, which only reads the chat shape (/v1/messages)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy-block","max_tokens":32,"stream":true,"messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
event: message_start
data: {"type":"message_start","message":{"model":"claude-haiku-4-5-legacy-block","id":"msg_011Cetgv8zpiHKTrcHJb5WpH","type":"message","role":"assistant","content":[],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}

event: ping
data: {"type": "ping"}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"kum"}     }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"quat"}       }

event: content_block_stop
data: {"type":"content_block_stop","index":0       }

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null},"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":6}    }

event: message_stop
data: {"type":"message_stop"             }


HTTP 200
  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:37779/v1/messages -d '{"model":"claude-haiku-4-5-legacy-block","max_tokens":32,"messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
{"model":"claude-haiku-4-5-legacy-block","id":"msg_011CetgvBqEDvt9vWBcYdziJ","type":"message","role":"assistant","content":[{"type":"text","text":"kumquat"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"service_tier":"standard","inference_geo":"not_available"}}
HTTP 200

Risk probe: Gemini stream through the rewriting hook's pipeline (/v1beta/models/{model}:streamGenerateContent), headers included

  1. curl -sS -N -i -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" 'http://localhost:37779/v1beta/models/gemini-flash-legacy:streamGenerateContent?alt=sse' -d '{"contents":[{"role":"user","parts":[{"text":"Reply with exactly the word tea and nothing else."}]}]}'
  2. Observed:
HTTP/1.1 200 OK
date: Wed, 09 Sep 2026 22:54:39 GMT
x-litellm-call-id: 46245105-c436-49c0-b17d-3988f71071bc
x-litellm-model-id: 4ad4824c0e902119eeac6910c499b9cd59ec76825ef577d48cad516d204632ee
x-litellm-model-name: gemini/gemini-3.8-flash
x-litellm-model-api-base: https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent
x-litellm-version: 1.102.0
x-litellm-response-cost-original: 0.0
x-litellm-response-cost-discount-amount: 0.0
x-litellm-response-cost-margin-amount: 0.0
x-litellm-response-cost-margin-percent: 0.0
x-litellm-response-cost-input: 0.0
x-litellm-response-cost-output: 0.0
x-litellm-response-cost-tool-usage: 0.0
x-litellm-key-spend: 0.0
x-litellm-response-duration-ms: 1310.1009999999999
x-litellm-callback-duration-ms: 0.0
llm_provider-content-type: text/event-stream
llm_provider-content-disposition: attachment
llm_provider-vary: Origin, X-Origin, Referer
llm_provider-transfer-encoding: chunked
llm_provider-date: Wed, 09 Sep 2026 22:54:41 GMT
llm_provider-server: scaffolding on HTTPServer2
llm_provider-x-xss-protection: 0
llm_provider-x-frame-options: SAMEORIGIN
llm_provider-x-content-type-options: nosniff
llm_provider-server-timing: gfet4t7; dur=1173
llm_provider-alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
x-litellm-model-group: gemini-flash-legacy
x-ratelimit-remaining-tokens: 800000
x-ratelimit-limit-tokens: 800000
x-ratelimit-remaining-requests: 1999
x-ratelimit-limit-requests: 2000
x-litellm-attempted-retries: 0
x-litellm-attempted-fallbacks: 0
x-litellm-applied-guardrails: legacy-rewriter
x-litellm-applied-policies: legacy-governance
x-litellm-policy-sources: legacy-governance=model:gemini-flash-legacy
cache-control: no-cache
x-accel-buffering: no
content-type: text/event-stream; charset=utf-8
x-frame-options: DENY
content-security-policy: frame-ancestors 'none'
x-content-type-options: nosniff
Transfer-Encoding: chunked

data: {"candidates": [{"content": {"parts": [{"text": "tea"}],"role": "model"},"index": 0}],"usageMetadata": {"promptTokenCount": 11,"candidatesTokenCount": 1,"totalTokenCount": 113,"promptTokensDetails": [{"modality": "TEXT","tokenCount": 11}],"thoughtsTokenCount": 101,"serviceTier": "standard"},"modelVersion": "gemini-3.8-flash","responseId": "sOOhat23Ear-jrEPwrSn4Ac"}

data: {"candidates": [{"content": {"parts": [{"text": "","thoughtSignature": "ErcECrQEARFNMg9wretiY/QxanEHDC2TopVMVFWIJW+LU6e/Q5q5iA5fDTVx1PF3IOha5a1eJ2CUxTH/ZMk6Tl/KAiWGl3QLI8E/7V6e8qx3eUcS+MuJRKiPO6z0uLm/7P3bzhEGW+HgJ9Z/GWQaL+A8Z1FXPvU6/MXJvbPczwcErXOLM3sKOLnQb4ZY5e7OUDk2vQcI2o8d1PWSGDhTE1Y7T5wgtHJaArGXRK9J2kwEh9lL1K64pF2MPXEwwD6l/p0r7ABx3DFgvlWDfaWeQFapE2n16Z+RdUEREcbad96VAM2tpP+3TQvKBJMbCWjhuepMrdqTOJyb65KLmPyol2BvoXt7MDcsXy8dT3E4dv3K//im/z5vz6mcP1NxByV6KbsOTymLEBV8el2uBD0GMVILqMvxHkQycUV0Vr4zQkgdG1Me0P20Um+vyoBK5lWdvhRbhbW9c0J3KrDZai631Ug+cxkoNzKYosjDumOv+a3w9VQ2MXIu7XRodEqcjPp8jmEZU0aEfQdFTtbx1vS1cGZhz6lFqjae10o/WoqsNpp2XWOyijK+O62K8XY3Dz4cR6siwANbajwlD1S7nHVOTO/ErOpgAMgP1gR9XaFVjqzE0UmsbWBmdYv1GWKF66iIFLcwg2cPhjKPcpkYLS5Ea6llaz/7fkmafVe1zXvuyeoKypfRH2fa2RAlZtIBlQnddbkzidNDpAJRekEwg32sLJ294doEqsJ23vaAChEyvUWhQprLbTCvRRWB"}],"role": "model"},"finishReason": "STOP","index": 0}],"usageMetadata": {"promptTokenCount": 11,"candidatesTokenCount": 1,"totalTokenCount": 113,"promptTokensDetails": [{"modality": "TEXT","tokenCount": 11}],"thoughtsTokenCount": 101,"serviceTier": "standard"},"modelVersion": "gemini-3.8-flash","responseId": "sOOhat23Ear-jrEPwrSn4Ac"}

Observations from the run:

  • Rewrites arrive as one full delta then empties, like MASK
  • response.completed and output_item.done also carry the rewrite
  • A hook returning None without changing the response leaves the stream untouched
  • Non-streamed replies are identical on both legs
  • Non-intervention hook errors now end streams with HTTP 500
  • Non-streamed calls already returned 500 for the same hook
  • The unified control gets the same 500 on both legs
  • on_error: allow keeps the stream on a hook error
  • Pipelines the stream cannot gate still run their hook afterwards
  • A tool-only Messages stream the older hook leaves alone goes out unchanged and adds no discarded-rewrite warning
  • 2 rewriting hooks in one pipeline stack their rewrites on the stream
  • A tool-call mask goes out as the original stream with 1 warning, while the non-streamed call is masked
  • /v1/completions and Gemini streams stay unrewritten on both legs
  • tool_permission denies the streamed tool call the same on both legs
  • A rewritten chat stream carries the applied-guardrails header
  • The chat-only blocker passes the Messages stream on both legs

Type

🆕 New Feature

Caveats (if any)

Medium

  • A legacy hook that reads response.choices without checking the shape now ends /v1/responses and /v1/messages streams with HTTP 500 on a pipeline whose on_error is left at its default of block. At the merge base those streams went out unscanned with a warning; the non-streamed calls on the same routes and unified guardrails on streams already returned that 500. on_error: allow keeps the stream, and every in-repo hook with a post-call hook guards the shape, so this reaches only custom hooks without a guard
  • A pipeline that holds a hook without apply_guardrail now gates streams the way every other pipeline step does since fix(policy_engine): execute post_call guardrail pipelines on responses and streams #38721: the whole stream is buffered and released once the hook allows it, so time to first token becomes the full generation time on /v1/chat/completions, /v1/responses, and /v1/messages. At the merge base those streams flowed as generated and the hook never gated them

Low

  • The step only takes a legacy hook on routes whose translation assembles the streamed response (/v1/chat/completions, /v1/responses, /v1/messages). On /v1/completions, the Gemini streamGenerateContent route, and A2A streams the pipeline is skipped with the merge-base warning and the hook runs on its own afterwards, as before this PR
  • A guardrail with its own async_post_call_streaming_iterator_hook next to its post-call hook (the built-in tool_permission, aim, model_armor, and 7 others) is left on that streaming hook, so a pipeline holding one of them is skipped on streams exactly as at the merge base
  • Stream errors from a hook use the existing streaming error envelope ("type":"None", "code":"500") while the non-streamed call returns internal_server_error, since the stream path reuses emit_streaming_http_error as it stands
  • When auth leaves request_route unset, no translation resolves, so the pipeline is skipped with the merge-base warning and the hook runs on its own after the stream, the same as any route without a translation since 9cb5d9b; no real route was found leaving the route unset
  • A hook that only knows the chat shape and returns None on a Messages or Responses stream counts as a pass, so the step lists it in x-litellm-applied-guardrails although it scanned nothing. That covers the built-in GuardrailsAI, Lakera v2, Pillar, Lasso, Aporia, Pangea, Semantic Guard, and Azure text moderation hooks, which all check for the chat shape first and skip the Anthropic or Responses payload the way they already do on the non-streamed call. The executor cannot tell a skip from an allow, and this is the same header rule every passing streaming step has had since 91fc1b2, with _process_guardrail_metadata already listing requested guardrails before any of them runs
  • Pangea sets response.choices to plain dicts, which the chat translation does not rescan, so a Pangea redaction on a chat stream is released as the original stream with a warning while Pangea's own header write still lists it. At the merge base the same stream went out unredacted with the same header. The chat translation's handling of dict choices is tracked separately
  • A hook on a Messages stream receives the Anthropic message rebuilt from the assembled ModelResponse, so id, model, and cache usage come from that rebuild rather than the upstream message_start; type, content, stop reason, and token usage match the non-streamed call

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

Link to Devin session: https://app.devin.ai/sessions/3c28a0fd69c04912809a941324c9a338
Open in Devin Desktop: https://app.devin.ai/desktop/session/3c28a0fd69c04912809a941324c9a338?variant=devin
Requested by: @mateo-berri

A post_call pipeline step whose guardrail only implements the older
async_post_call_success_hook used to skip the stream entirely: PR #38721
fails that shape open with a warning. The streaming step now assembles the
buffered stream into the response the hook expects, runs the hook, ends the
stream with the hook's exception when it raises, and delivers the hook's
rewrite through the same event write-back the unified guardrails use on
chat, Responses, and Messages streams (Messages gets the Anthropic shape).
A stream a pipeline manages no longer runs the same hook again after the
stream ends. A guardrail with neither the unified interface nor a post-call
hook keeps the fail-open, as does a rewrite the buffer cannot be patched
with.
…eline' into litellm_legacy_hook_streaming_pipeline_step
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@greptile-apps

greptile-apps Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR runs legacy post-call guardrail hooks against buffered Chat Completions, Responses, and Anthropic Messages streams, then writes supported response rewrites back into each endpoint’s stream format. It also prevents gated hooks from running again after stream completion and preserves deferred execution for pipelines that cannot gate a route.

  • Legacy hook blocks and text rewrites now affect supported streaming endpoints
  • Chained pipeline steps receive the output produced by earlier steps
  • Tool-call rewrites are synchronized across supported stream event formats or rejected as undeliverable
  • Unsupported routes and guardrail shapes retain deferred, fail-open behavior with warnings
  • Tests cover route-native hook shapes, chained rewrites, errors, unsupported rewrites, tool calls, and deferred execution

Confidence Score: 5/5

The PR appears safe to merge, with no outstanding previous findings or accepted new issues

The prior stale-output and partially lost replacement findings are resolved in the current implementation, and the remaining previous thread was withdrawn after confirming the existing control-flow contract. Streaming eligibility, chained response refresh, route-native hook shapes, deferred execution, and supported text and tool-call write-back are covered without a confirmed merge-blocking failure

Important Files Changed

Filename Overview
litellm/proxy/policy_engine/pipeline_executor.py Adapts legacy post-call hooks into streaming pipeline steps, refreshes assembled responses between steps, and rejects undeliverable rewrites
litellm/proxy/utils.py Selects streamable pipelines based on callback capabilities and endpoint response-assembly support
litellm/proxy/common_request_processing.py Prevents successfully gated legacy hooks from running again during deferred post-stream processing
litellm/llms/openai/chat/guardrail_translation/handler.py Writes buffered Chat Completions text and function-call rewrites back into stream chunks
litellm/llms/openai/responses/guardrail_translation/handler.py Synchronizes rewritten text and function calls across Responses API stream events and terminal envelopes
litellm/llms/anthropic/chat/guardrail_translation/handler.py Converts assembled responses to Messages hook shape and writes text and tool-use rewrites into Anthropic SSE events

Reviews (8): Last reviewed commit: "Merge remote-tracking branch 'origin/lit..." | Re-trigger Greptile

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Devin e2e QA

Tested at: fe836e8
Session: https://app.devin.ai/sessions/3c28a0fd69c04912809a941324c9a338

Both legs booted from a git worktree of the named commit with --num_workers 2 on port 25238 (picked at random, confirmed free), no database, real OpenAI (openai/gpt-5.4-mini) and Anthropic (anthropic/claude-haiku-4-5) spend. legacy_hook.py from the PR description sits on PYTHONPATH. Same config, same hook, same eight requests on both legs; only the commit differs

Boot: python litellm/proxy/proxy_cli.py --config config.yaml --port 25238 --num_workers 2 --detailed_debug

config.yaml:

model_list:
  - model_name: gpt-5.4-mini-legacy
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: gpt-5.4-mini-legacy-block
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: claude-haiku-4-5-legacy
    litellm_params:
      model: anthropic/claude-haiku-4-5
      api_key: os.environ/ANTHROPIC_API_KEY

guardrails:
  - guardrail_name: legacy-rewriter
    litellm_params:
      guardrail: legacy_hook.legacyRewriter
      mode: post_call
  - guardrail_name: legacy-blocker
    litellm_params:
      guardrail: legacy_hook.legacyBlocker
      mode: post_call

policies:
  legacy-governance:
    guardrails:
      add: [legacy-rewriter]
    pipeline:
      mode: post_call
      steps:
        - guardrail: legacy-rewriter
          on_pass: allow
          on_fail: block
  legacy-block-governance:
    guardrails:
      add: [legacy-blocker]
    pipeline:
      mode: post_call
      steps:
        - guardrail: legacy-blocker
          on_pass: allow
          on_fail: block

policy_attachments:
  - policy: legacy-governance
    models: [gpt-5.4-mini-legacy, claude-haiku-4-5-legacy]
  - policy: legacy-block-governance
    models: [gpt-5.4-mini-legacy-block]

Before (cecd481, merge base)

Chat stream, legacy rewriter (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-ELwUw2wky4o4TsgCxBiobQ6jW0WJG","object":"chat.completion.chunk","created":1788898462,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-ELwUw2wky4o4TsgCxBiobQ6jW0WJG","object":"chat.completion.chunk","created":1788898462,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":"pers"}}]}

data: {"id":"chatcmpl-ELwUw2wky4o4TsgCxBiobQ6jW0WJG","object":"chat.completion.chunk","created":1788898462,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":"im"}}]}

data: {"id":"chatcmpl-ELwUw2wky4o4TsgCxBiobQ6jW0WJG","object":"chat.completion.chunk","created":1788898462,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":"mon"}}]}

data: {"id":"chatcmpl-ELwUw2wky4o4TsgCxBiobQ6jW0WJG","object":"chat.completion.chunk","created":1788898462,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]


HTTP 200

Chat non-stream, legacy rewriter (/v1/chat/completions)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy","messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
{"id":"chatcmpl-ELwUxBQD2l71m4388sHuSX74LJxqd","created":1788898463,"model":"gpt-5.4-mini-legacy","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"[REWRITTEN BY LEGACY HOOK] persimmon","role":"assistant","provider_specific_fields":{"refusal":null},"annotations":[]},"provider_specific_fields":{}}],"usage":{"completion_tokens":6,"prompt_tokens":18,"total_tokens":24,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0},"prompt_tokens_details":{"audio_tokens":0,"cached_tokens":0}},"service_tier":"default"}
HTTP 200

Messages stream, legacy rewriter (/v1/messages)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:25238/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":32,"stream":true,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
event: message_start
data: {"type":"message_start","message":{"model":"claude-haiku-4-5-legacy","id":"msg_011CeratCzRMKcPd4JjVxaGG","type":"message","role":"assistant","content":[],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}      }

event: ping
data: {"type": "ping"}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"pers"}  }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"immon"} }

event: content_block_stop
data: {"type":"content_block_stop","index":0         }

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null},"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":6}           }

event: message_stop
data: {"type":"message_stop"           }


HTTP 200

Messages non-stream, legacy rewriter (/v1/messages)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:25238/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":32,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
{"model":"claude-haiku-4-5-legacy","id":"msg_011CeratGLat8tXdw32ybJHC","type":"message","role":"assistant","content":[{"type":"text","text":"[REWRITTEN BY LEGACY HOOK] persimmon"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"service_tier":"standard","inference_geo":"not_available"}}
HTTP 200

Responses stream, legacy rewriter (/v1/responses), text and completed events only

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/responses -d '{"model":"gpt-5.4-mini-legacy","stream":true,"input":"Reply with exactly the word persimmon and nothing else."}' | grep -E 'output_text\.(delta|done)|response\.completed|^HTTP' | sed -E 's/("type":"response.completed".*"text":"[^"]*").*/\1 ...}/'
  2. Observed:
data: {"type":"response.output_text.delta","item_id":"msg_015b39758e381c0d006aa06ca26c4487d0bd319e97e5d6a6b6","output_index":0,"content_index":0,"delta":"pers","logprobs":[],"obfuscation":"eB6jYSmOJ8v0","sequence_number":4,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.delta","item_id":"msg_015b39758e381c0d006aa06ca26c4487d0bd319e97e5d6a6b6","output_index":0,"content_index":0,"delta":"im","logprobs":[],"obfuscation":"F5knBmLTixL2z4","sequence_number":5,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.delta","item_id":"msg_015b39758e381c0d006aa06ca26c4487d0bd319e97e5d6a6b6","output_index":0,"content_index":0,"delta":"mon","logprobs":[],"obfuscation":"GpBTz8SumANDX","sequence_number":6,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.done","item_id":"msg_015b39758e381c0d006aa06ca26c4487d0bd319e97e5d6a6b6","output_index":0,"content_index":0,"text":"persimmon","logprobs":[],"sequence_number":7,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.completed","response":{"id":"resp_CUK-9cbEvMz-SgQSns_9uKXVffUAgMxERLXFkascCUJ5THrAyaE-6096AVIl6b1fD4sCMLfN2S4RNxa7SViSsvHsro_uTCOlyn7EE9Nnnug_TgdM8r-KBNbRbJnWiee7pWKB4YovClee26WKDJoCYj3zLjcRNZN6IvHOVAnmnl-HTzpXCRe4eyWvEvrBrP7Bv1qjYcuyFs4Vvw8g9VFhmJaHC3mFfbKszBLcayuq1JJy2Yl_rJVdkzmghw_b4jqz0aVu9n692x55BaRRjwi5X9SHOMnNdSm6LSBGRIwV-iexNcQ62xCDPSvmIdDXdr424UQlEONLuowshmQ3xaQi24hVVsvB43WqMLhSW80b6jjdaJOjuSlnBlThrtHS20CPTnv1X8tB9lC-sVxVLQPYt4uMGuWavjZVOLdCEOvSrTTvvyJoUNiBeQGxZWIETczw_3Q6iTUymURJLkKusIkf27cR","created_at":1788898466,"metadata":{},"model":"gpt-5.4-mini-2026-03-17","object":"response","output":[{"id":"msg_015b39758e381c0d006aa06ca26c4487d0bd319e97e5d6a6b6","content":[{"annotations":[],"text":"persimmon" ...}
HTTP 200

Responses non-stream, legacy rewriter (/v1/responses)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/responses -d '{"model":"gpt-5.4-mini-legacy","input":"Reply with exactly the word persimmon and nothing else."}' | { read -r body; jq -c '{status, output: [.output[] | {type, content}]}' <<< "$body"; cat; }
  2. Observed:
{"status":"completed","output":[{"type":"message","content":[{"annotations":[],"text":"[REWRITTEN BY LEGACY HOOK] persimmon","type":"output_text","logprobs":[]}]}]}
HTTP 200

Chat stream, legacy blocker (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy-block","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-ELwV1XLvK5xsprxXVUz03lXUUfGuJ","object":"chat.completion.chunk","created":1788898468,"model":"gpt-5.4-mini-legacy-block","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-ELwV1XLvK5xsprxXVUz03lXUUfGuJ","object":"chat.completion.chunk","created":1788898468,"model":"gpt-5.4-mini-legacy-block","choices":[{"index":0,"delta":{"content":"kum"}}]}

data: {"id":"chatcmpl-ELwV1XLvK5xsprxXVUz03lXUUfGuJ","object":"chat.completion.chunk","created":1788898468,"model":"gpt-5.4-mini-legacy-block","choices":[{"index":0,"delta":{"content":"quat"}}]}

data: {"id":"chatcmpl-ELwV1XLvK5xsprxXVUz03lXUUfGuJ","object":"chat.completion.chunk","created":1788898468,"model":"gpt-5.4-mini-legacy-block","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]


HTTP 200

Chat non-stream, legacy blocker (/v1/chat/completions)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy-block","messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
{"error":{"message":"Violated legacy blocker policy: kumquat","type":"invalid_request_error","param":null,"code":"400","provider_specific_fields":{"error":"Violated legacy blocker policy: kumquat","guardrail_name":"legacy-blocker","guardrail_mode":"post_call"}}}
HTTP 400

After (fe836e8, branch tip)

Chat stream, legacy rewriter (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
data: {"id":"chatcmpl-ELwW20vxGh1nTKIrmgoqljwEv7Bxo","object":"chat.completion.chunk","created":1788898530,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"role":"assistant","content":"[REWRITTEN BY LEGACY HOOK] persimmon"}}]}

data: {"id":"chatcmpl-ELwW20vxGh1nTKIrmgoqljwEv7Bxo","object":"chat.completion.chunk","created":1788898530,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-ELwW20vxGh1nTKIrmgoqljwEv7Bxo","object":"chat.completion.chunk","created":1788898530,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-ELwW20vxGh1nTKIrmgoqljwEv7Bxo","object":"chat.completion.chunk","created":1788898530,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{"content":""}}]}

data: {"id":"chatcmpl-ELwW20vxGh1nTKIrmgoqljwEv7Bxo","object":"chat.completion.chunk","created":1788898530,"model":"gpt-5.4-mini-legacy","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]


HTTP 200

Chat non-stream, legacy rewriter (/v1/chat/completions)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy","messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
{"id":"chatcmpl-ELwW3RgdMaDrhgkiOksASdYCxs7kg","created":1788898531,"model":"gpt-5.4-mini-legacy","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"[REWRITTEN BY LEGACY HOOK] persimmon","role":"assistant","provider_specific_fields":{"refusal":null},"annotations":[]},"provider_specific_fields":{}}],"usage":{"completion_tokens":6,"prompt_tokens":18,"total_tokens":24,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0},"prompt_tokens_details":{"audio_tokens":0,"cached_tokens":0}},"service_tier":"default"}
HTTP 200

Messages stream, legacy rewriter (/v1/messages)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:25238/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":32,"stream":true,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
event: message_start
data: {"type":"message_start","message":{"model":"claude-haiku-4-5-legacy","id":"msg_011CerayFjmCN4Swc6Foc7TU","type":"message","role":"assistant","content":[],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}             }

event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "[REWRITTEN BY LEGACY HOOK] persimmon"}}

event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": ""}}

event: content_block_stop
data: {"type":"content_block_stop","index":0             }

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"container":null},"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":6}  }

event: message_stop
data: {"type":"message_stop"     }


HTTP 200

Messages non-stream, legacy rewriter (/v1/messages)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -H 'anthropic-version: 2023-06-01' http://localhost:25238/v1/messages -d '{"model":"claude-haiku-4-5-legacy","max_tokens":32,"messages":[{"role":"user","content":"Reply with exactly the word persimmon and nothing else."}]}'
  2. Observed:
{"model":"claude-haiku-4-5-legacy","id":"msg_011CerayKR1v8m28r1RVFS3N","type":"message","role":"assistant","content":[{"type":"text","text":"[REWRITTEN BY LEGACY HOOK] persimmon"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":19,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":6,"service_tier":"standard","inference_geo":"not_available"}}
HTTP 200

Responses stream, legacy rewriter (/v1/responses), text and completed events only

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/responses -d '{"model":"gpt-5.4-mini-legacy","stream":true,"input":"Reply with exactly the word persimmon and nothing else."}' | grep -E 'output_text\.(delta|done)|response\.completed|^HTTP' | sed -E 's/("type":"response.completed".*"text":"[^"]*").*/\1 ...}/'
  2. Observed:
data: {"type":"response.output_text.delta","item_id":"msg_000c78b4293a8ce6006aa06ce7455887d0927706e33f7eb1c8","output_index":0,"content_index":0,"delta":"[REWRITTEN BY LEGACY HOOK] persimmon","logprobs":[],"obfuscation":"N8vboxS7hMbc","sequence_number":4,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.delta","item_id":"msg_000c78b4293a8ce6006aa06ce7455887d0927706e33f7eb1c8","output_index":0,"content_index":0,"delta":"","logprobs":[],"obfuscation":"4HGmpaml7xL2Md","sequence_number":5,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.delta","item_id":"msg_000c78b4293a8ce6006aa06ce7455887d0927706e33f7eb1c8","output_index":0,"content_index":0,"delta":"","logprobs":[],"obfuscation":"GoBNHeneMnM0J","sequence_number":6,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.output_text.done","item_id":"msg_000c78b4293a8ce6006aa06ce7455887d0927706e33f7eb1c8","output_index":0,"content_index":0,"text":"[REWRITTEN BY LEGACY HOOK] persimmon","logprobs":[],"sequence_number":7,"model":"gpt-5.4-mini-legacy"}
data: {"type":"response.completed","response":{"id":"resp_aAqeRhCT--dDOtWRueD15X6GhTuyJYrUMl_fUaeP9QvUu70mplC8I0f_t7GHFceXDZ-e_mql76fZJL6Qubl4rc37L13FP7I9o1w2dtRT3OztczYxQjEkTiNJP66Jiy-hVrOEjNIkn3q0HwiRUxgBQaKuRMUO3_yg0hTO0pbsfOYzqM3_YokzrZgJUq4M3nQqmON4pHlS-G8nDP3z4J8cZDUYDO-kcOYsg22S9ijmBms3jabKc6ZJO6JUto1ccd8D0HC3az6jD0WFsPXbusy7-KYCVjDMtDOyf7jJSMgFw7Uhg3SX25eoQRCe7HgkO_No7pB-Xy5nAOsu3UrjRLOvWYsTekf0tw1TtMjnHEXLlFsUUqFHR84udYVFr21Y9hwykEf7l3rmyf0qVLvGSrOuR4TRQMEo6bPDwPMKbPwmwX8wWgrpjEn8w60aGEH3ijUROE0_inhVBh5Zd4eISwzvzJl-","created_at":1788898534,"metadata":{},"model":"gpt-5.4-mini-2026-03-17","object":"response","output":[{"id":"msg_000c78b4293a8ce6006aa06ce7455887d0927706e33f7eb1c8","content":[{"annotations":[],"text":"[REWRITTEN BY LEGACY HOOK] persimmon" ...}
HTTP 200

Responses non-stream, legacy rewriter (/v1/responses)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/responses -d '{"model":"gpt-5.4-mini-legacy","input":"Reply with exactly the word persimmon and nothing else."}' | { read -r body; jq -c '{status, output: [.output[] | {type, content}]}' <<< "$body"; cat; }
  2. Observed:
{"status":"completed","output":[{"type":"message","content":[{"annotations":[],"text":"[REWRITTEN BY LEGACY HOOK] persimmon","type":"output_text","logprobs":[]}]}]}
HTTP 200

Chat stream, legacy blocker (/v1/chat/completions)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy-block","stream":true,"messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
data: {"error": {"message": "Violated legacy blocker policy: kumquat", "type": "invalid_request_error", "param": null, "code": "400", "provider_specific_fields": {"error": "Violated legacy blocker policy: kumquat", "guardrail_name": "legacy-blocker", "guardrail_mode": "post_call"}}}

data: [DONE]


HTTP 400

Chat non-stream, legacy blocker (/v1/chat/completions)

  1. curl -sS -w '\nHTTP %{http_code}\n' -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" http://localhost:25238/v1/chat/completions -d '{"model":"gpt-5.4-mini-legacy-block","messages":[{"role":"user","content":"Reply with exactly the word kumquat and nothing else."}]}'
  2. Observed:
{"error":{"message":"Violated legacy blocker policy: kumquat","type":"invalid_request_error","param":null,"code":"400","provider_specific_fields":{"error":"Violated legacy blocker policy: kumquat","guardrail_name":"legacy-blocker","guardrail_mode":"post_call"}}}
HTTP 400

Verdict: every stream on the tip carries the legacy hook's rewrite (chat, Messages, Responses, including response.output_text.done and response.completed), the raising hook ends the chat stream with HTTP 400 and a single JSON error frame before [DONE], and all four non-streamed replies are byte-for-byte the same shape on both legs

@codecov

codecov Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
litellm/proxy/policy_engine/pipeline_executor.py 96.22% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

…eline' into litellm_legacy_hook_streaming_pipeline_step

# Conflicts:
#	litellm/proxy/utils.py
…call rewrites

Each streaming step drops the response an earlier step's translation stored under
request_data["response"], so a later legacy hook sees the stream as the steps before it
left it instead of the first step's snapshot. A legacy replacement whose tool calls differ
from the scanned chunks is now undeliverable like a text mismatch, so the original stream is
released with a warning instead of delivering the text while dropping the tool-call change
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

Base automatically changed from litellm_fix_post_call_policy_pipeline to litellm_internal_staging September 8, 2026 22:19
@mateo-berri
mateo-berri requested a review from a team September 8, 2026 22:19

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

Stale Bugbot comment from a previous run.

A legacy post-call hook that changes the response it was handed and returns None (the
model armor guardrail masks choice content that way) used to have that rewrite dropped on
the streaming pipeline path, since the adapter only re-scanned a returned replacement. The
adapter now re-scans the response it handed the hook when the hook returns None, so an
in-place rewrite reaches the client through the same ended-stream write-back
…-guardrails header

A streaming step whose rewrite the executor threw away (a tool-call rewrite, a text rewrite
the translation cannot write back, or one the adapter refused) still marked its guardrail as
applied, so the header claimed an output the client never received. The step now returns
right after releasing the original chunks, which leaves the header as the merge base sent it
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@codspeed

codspeed Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_legacy_hook_streaming_pipeline_step (5fdbb2a) with litellm_internal_staging (6e96885)

Open in CodSpeed

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

Stale Bugbot comment from a previous run.

A Messages stream that ends with only tool_use blocks reaches the legacy
step without a texts key, while the non-streaming rescan of the same
response sends an empty list. Compare both as empty and keep the stream
when the hook left the tool calls alone.
@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

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

Stale Bugbot comment from a previous run.

…nd no rescan

A translation that hands the hook no assembled response leaves the stream
as it is, and a rewrite the translation cannot rescan is released as the
original stream with a warning.
@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

Comment on lines +196 to +201
raise UndeliverableStreamRewrite(self.guardrail_name or "unknown")
rewritten: Final = rescanned.get("texts")
if len(_scanned_texts(rewritten)) != len(_scanned_texts(inputs.get("texts"))):
raise UndeliverableStreamRewrite(self.guardrail_name or "unknown")
if _tool_call_shapes(rescanned.get("tool_calls")) != _tool_call_shapes(inputs.get("tool_calls")):
raise UndeliverableStreamRewrite(self.guardrail_name or "unknown")

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.

P2 Expected Failures Are Thrown

Failed rescans and shape mismatches raise exceptions instead of modeling failures as values. This repository requirement must be satisfied before merging

Context Used: CLAUDE.md (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!

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.

This exception predates the PR: the chat, Responses, and Messages translations already raise it to abort a scan mid-translation; the adapter joins that contract

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.

You're right. UndeliverableStreamRewrite is an existing control-flow exception used by the endpoint translations to abort an undeliverable scan, and this adapter follows that same contract. _run_streaming_step catches it immediately, restores the original chunks, and releases the stream, so it is not an uncaught expected failure or a new value-vs-exception modeling issue. With that context, I’m withdrawing this finding.

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

Stale Bugbot comment from a previous run.

…assemble and off guardrails with their own iterator hook

The streaming pipeline step only takes a post-call hook on routes whose
translation assembles the streamed response (chat completions, Responses,
Messages). On /v1/completions, the Gemini streamGenerateContent route, and
A2A streams the pipeline is skipped with the merge-base warning and the hook
runs on its own afterwards, instead of getting a None response while the
header says the guardrail ran. A guardrail that overrides
async_post_call_streaming_iterator_hook next to its post-call hook keeps its
native per-chunk path rather than running buffered through the adapter
@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 5fdbb2a. 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 21ae29b into litellm_internal_staging Sep 10, 2026
87 of 88 checks passed
@mateo-berri
mateo-berri deleted the litellm_legacy_hook_streaming_pipeline_step branch September 10, 2026 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant