Repository navigation
feat(guardrails): run legacy post-call hooks as streaming pipeline steps - #40284
mateo-berri merged 15 commits into
Conversation
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.
…ferred post-call pass
…eline' into litellm_legacy_hook_streaming_pipeline_step
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Greptile SummaryThis 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.
Confidence Score: 5/5The 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
|
| 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 e2e QATested at: fe836e8 Both legs booted from a git worktree of the named commit with Boot:
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)
Chat non-stream, legacy rewriter (/v1/chat/completions)
Messages stream, legacy rewriter (/v1/messages)
Messages non-stream, legacy rewriter (/v1/messages)
Responses stream, legacy rewriter (/v1/responses), text and completed events only
Responses non-stream, legacy rewriter (/v1/responses)
Chat stream, legacy blocker (/v1/chat/completions)
Chat non-stream, legacy blocker (/v1/chat/completions)
After (fe836e8, branch tip)Chat stream, legacy rewriter (/v1/chat/completions)
Chat non-stream, legacy rewriter (/v1/chat/completions)
Messages stream, legacy rewriter (/v1/messages)
Messages non-stream, legacy rewriter (/v1/messages)
Responses stream, legacy rewriter (/v1/responses), text and completed events only
Responses non-stream, legacy rewriter (/v1/responses)
Chat stream, legacy blocker (/v1/chat/completions)
Chat non-stream, legacy blocker (/v1/chat/completions)
Verdict: every stream on the tip carries the legacy hook's rewrite (chat, Messages, Responses, including |
Codecov Report❌ Patch coverage is
📢 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
|
bugbot run |
…itellm_legacy_hook_streaming_pipeline_step
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
|
bugbot 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.
|
bugbot 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.
|
bugbot run |
| 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") |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
…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
…itellm_legacy_hook_streaming_pipeline_step
…t completions route
…itellm_legacy_hook_streaming_pipeline_step
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 5fdbb2a. Configure here.
TLDR
Problem this solves:
How it solves it:
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
post_callpipeline policy whose step names a guardrail written against the older post-call hook (it prefixes every reply with[REWRITTEN BY LEGACY HOOK]) togpt-5.4-mini-legacyandclaude-haiku-4-5-legacy, attaches a second such policy whose hook rejects the word kumquat togpt-5.4-mini-legacy-block, and restarts the proxy"model": "gpt-5.4-mini-legacy"asking for the word persimmon and gets HTTP 200 with"content": "[REWRITTEN BY LEGACY HOOK] persimmon""stream": trueand the SSE chunks spellpers,im,mon, with no rewrite anywhere in the stream"model": "claude-haiku-4-5-legacy"and"stream": true, and thecontent_block_deltaevents spellpers,immon, untouched"model": "gpt-5.4-mini-legacy"and"stream": true, and theresponse.output_text.deltaevents spellpers,im,mon, withresponse.output_text.donereadingpersimmon"model": "gpt-5.4-mini-legacy-block"asking for the word kumquat and get HTTP 400Violated legacy blocker policy: kumquat"stream": trueand get HTTP 200 with chunks spellingkum,quat, so the block holds for non-streamed calls onlyAfter: the same streams carry the hook's rewrite, and the hook's rejection ends the stream with its error
post_callpipeline policy whose step names a guardrail written against the older post-call hook (it prefixes every reply with[REWRITTEN BY LEGACY HOOK]) togpt-5.4-mini-legacyandclaude-haiku-4-5-legacy, attaches a second such policy whose hook rejects the word kumquat togpt-5.4-mini-legacy-block, and restarts the proxy"model": "gpt-5.4-mini-legacy"asking for the word persimmon and gets HTTP 200 with"content": "[REWRITTEN BY LEGACY HOOK] persimmon""stream": trueand the first content chunk reads[REWRITTEN BY LEGACY HOOK] persimmon, followed by empty deltas and"finish_reason": "stop""model": "claude-haiku-4-5-legacy"and"stream": true, and the firstcontent_block_deltareads[REWRITTEN BY LEGACY HOOK] persimmon, followed by an empty delta and the usualcontent_block_stop,message_delta,message_stop"model": "gpt-5.4-mini-legacy"and"stream": true, and the firstresponse.output_text.deltareads[REWRITTEN BY LEGACY HOOK] persimmon, withresponse.output_text.doneandresponse.completedcarrying the same text"model": "gpt-5.4-mini-legacy-block"asking for the word kumquat and get HTTP 400Violated legacy blocker policy: kumquat"stream": trueand get HTTP 400 whose only SSE frame isdata: {"error": {"message": "Violated legacy blocker policy: kumquat", ...}}followed bydata: [DONE], with no content chunkRelevant 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
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Both legs: the proxy booted from the worktree with
--num_workers 2on port 37779, no database, real OpenAI (gpt-5.4-mini) and Anthropic (claude-haiku-4-5) spend.legacy_hook.pysits onPYTHONPATH. 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 withlitellm_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 themBoot:
python litellm/proxy/proxy_cli.py --config config.yaml --port 37779 --num_workers 2 --detailed_debugconfig.yaml(themodel_listmapsgpt-5.4-mini,gpt-5.4-mini-legacy, andgpt-5.4-mini-legacy-blocktoopenai/gpt-5.4-mini, andclaude-haiku-4-5andclaude-haiku-4-5-legacytoanthropic/claude-haiku-4-5):legacy_hook.py, two guardrails that only implement the older post-call hook (noapply_guardrail); the rewriter handles the chat, Messages, and Responses shapes, the blocker handles chat:The 16
Risk probecases on each side are the /live-pr-risk run.risk_hooks.pysits onPYTHONPATHand adds 5 guardrails that exist only to observe the paths this diff changes:legacyUnguardedis an older hook that readsresponse.choices[0].message.contentwithout checking the shape and raisesValueErroron the word coffee,legacyRecorderis an older hook that appends what it was handed to$LIT7176_RECORD_FILE,neitherHookonly has a pre-call hook so a stream has nothing to run, andunifiedRaiseris the control, anapply_guardrailthat raisesValueErroron coffee, andlegacyToolMaskeris an older hook that masks the arguments of every tool call in place and returnsNone. The tool-only Messages probe reusesclaude-haiku-4-5-legacyand thelegacyRewriterhook from the requests above, since that hook prefixes text blocks and leavestool_useblocks 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/completionsand the Gemini stream route throughlegacy-governance, and the built-intool_permissionguardrail, 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 shapeThe config for the probes is the one above plus these entries, so the probes only attach to their own models
Before (2b2e6cf)
Chat stream, legacy rewriter (/v1/chat/completions)
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."}]}'Chat non-stream, legacy rewriter (/v1/chat/completions)
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."}]}'{"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)
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."}]}'{"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)
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}]}'{"status":"completed","output":[{"type":"message","content":[{"annotations":[],"text":"[REWRITTEN BY LEGACY HOOK] persimmon","type":"output_text","logprobs":[]}]}]}Chat stream, legacy blocker (/v1/chat/completions)
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."}]}'Chat non-stream, legacy blocker (/v1/chat/completions)
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."}]}'Control: chat stream, unified content filter with MASK (/v1/chat/completions)
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."}]}'Risk probe: chat stream, older hook raising
ValueError(/v1/chat/completions)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."}]}'Risk probe: chat non-stream, same raising hook (/v1/chat/completions)
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."}]}'Risk probe: Responses stream, older hook that only knows the chat shape (/v1/responses), text events only
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."}'Risk probe: Responses non-stream, same hook (/v1/responses)
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."}'Risk probe: Messages stream, older hook that only knows the chat shape (/v1/messages)
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."}]}'Risk probe: chat stream, same raising hook under
on_error: allow(/v1/chat/completions)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."}]}'Risk probe: chat stream and non-stream on a pipeline the stream cannot gate (/v1/chat/completions), recorder file
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."}]}'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."}]}'cat "$LIT7176_RECORD_FILE"Risk probe: Messages stream and non-stream on a tool-only reply, older hook that leaves tool calls alone (/v1/messages), proxy log
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?"}]}'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?"}]}'Risk probe: chat stream through 2 rewriting hooks in one pipeline (/v1/chat/completions)
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."}]}'Risk probe: chat stream and non-stream on a tool call, older hook that masks the arguments in place (/v1/chat/completions), proxy log
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?"}]}'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?"}]}'grep discarded litellm.logRisk probe control: chat stream, unified guardrail raising
ValueError(/v1/chat/completions)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."}]}'Risk probe: text completion stream through the rewriting hook's pipeline (/v1/completions), headers included
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."}'Risk probe: chat stream and non-stream on a tool call through the built-in
tool_permissionguardrail, which has its own streaming hook (/v1/chat/completions)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?"}]}'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?"}]}'Risk probe: chat stream through the rewriting hook's pipeline with the response headers (/v1/chat/completions)
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."}]}'Risk probe: Messages stream and non-stream through the blocking hook, which only reads the chat shape (/v1/messages)
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."}]}'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."}]}'Risk probe: Gemini stream through the rewriting hook's pipeline (/v1beta/models/{model}:streamGenerateContent), headers included
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."}]}]}'After (5fdbb2a)
Chat stream, legacy rewriter (/v1/chat/completions)
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."}]}'Chat non-stream, legacy rewriter (/v1/chat/completions)
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."}]}'{"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)
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."}]}'{"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)
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}]}'{"status":"completed","output":[{"type":"message","content":[{"annotations":[],"text":"[REWRITTEN BY LEGACY HOOK] persimmon","type":"output_text","logprobs":[]}]}]}Chat stream, legacy blocker (/v1/chat/completions)
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."}]}'Chat non-stream, legacy blocker (/v1/chat/completions)
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."}]}'Control: chat stream, unified content filter with MASK (/v1/chat/completions)
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."}]}'Risk probe: chat stream, older hook raising
ValueError(/v1/chat/completions)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."}]}'Risk probe: chat non-stream, same raising hook (/v1/chat/completions)
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."}]}'Risk probe: Responses stream, older hook that only knows the chat shape (/v1/responses), text events only
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."}'Risk probe: Responses non-stream, same hook (/v1/responses)
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."}'Risk probe: Messages stream, older hook that only knows the chat shape (/v1/messages)
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."}]}'Risk probe: chat stream, same raising hook under
on_error: allow(/v1/chat/completions)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."}]}'Risk probe: chat stream and non-stream on a pipeline the stream cannot gate (/v1/chat/completions), recorder file
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."}]}'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."}]}'cat "$LIT7176_RECORD_FILE"Risk probe: Messages stream and non-stream on a tool-only reply, older hook that leaves tool calls alone (/v1/messages), proxy log
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?"}]}'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?"}]}'Risk probe: chat stream through 2 rewriting hooks in one pipeline (/v1/chat/completions)
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."}]}'Risk probe: chat stream and non-stream on a tool call, older hook that masks the arguments in place (/v1/chat/completions), proxy log
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?"}]}'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?"}]}'grep discarded litellm.logRisk probe control: chat stream, unified guardrail raising
ValueError(/v1/chat/completions)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."}]}'Risk probe: text completion stream through the rewriting hook's pipeline (/v1/completions), headers included
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."}'Risk probe: chat stream and non-stream on a tool call through the built-in
tool_permissionguardrail, which has its own streaming hook (/v1/chat/completions)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?"}]}'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?"}]}'Risk probe: chat stream through the rewriting hook's pipeline with the response headers (/v1/chat/completions)
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."}]}'Risk probe: Messages stream and non-stream through the blocking hook, which only reads the chat shape (/v1/messages)
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."}]}'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."}]}'Risk probe: Gemini stream through the rewriting hook's pipeline (/v1beta/models/{model}:streamGenerateContent), headers included
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."}]}]}'Observations from the run:
response.completedandoutput_item.donealso carry the rewriteNonewithout changing the response leaves the stream untouchedon_error: allowkeeps the stream on a hook error/v1/completionsand Gemini streams stay unrewritten on both legstool_permissiondenies the streamed tool call the same on both legsType
🆕 New Feature
Caveats (if any)
Medium
response.choiceswithout checking the shape now ends/v1/responsesand/v1/messagesstreams with HTTP 500 on a pipeline whoseon_erroris left at its default ofblock. 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: allowkeeps the stream, and every in-repo hook with a post-call hook guards the shape, so this reaches only custom hooks without a guardapply_guardrailnow 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 themLow
/v1/chat/completions,/v1/responses,/v1/messages). On/v1/completions, the GeministreamGenerateContentroute, and A2A streams the pipeline is skipped with the merge-base warning and the hook runs on its own afterwards, as before this PRasync_post_call_streaming_iterator_hooknext to its post-call hook (the built-intool_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"type":"None","code":"500") while the non-streamed call returnsinternal_server_error, since the stream path reusesemit_streaming_http_erroras it standsrequest_routeunset, 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 unsetNoneon a Messages or Responses stream counts as a pass, so the step lists it inx-litellm-applied-guardrailsalthough 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_metadataalready listing requested guardrails before any of them runsresponse.choicesto 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 separatelyModelResponse, soid,model, and cache usage come from that rebuild rather than the upstreammessage_start; type, content, stop reason, and token usage match the non-streamed callFinal Attestation
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