test(guardrails): e2e validation of streaming_transform_mode: incremental_diff (PR #32084) - #32703
Closed
mateo-berri wants to merge 10 commits into
Closed
test(guardrails): e2e validation of streaming_transform_mode: incremental_diff (PR #32084)#32703mateo-berri wants to merge 10 commits into
mateo-berri wants to merge 10 commits into
Conversation
… streaming transform
…call passthrough, n>1 finish_reason)
…_transform' into litellm_e2e_guardrail_streaming_test-2497 Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
Validates PR #32084 (
generic_guardrail_apistreaming text transform +ComplianceCheckermode-match fix)Linear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
Live e2e validation of PR #32084 against a real LiteLLM proxy (gpt-4o-mini, real OpenAI API, real $$$). All 6 cases below.
Setup: mock guardrail server on port 8888, proxy on port 4000 with
generic_guardrail_apiconfigured,streaming_transform_mode: incremental_diff,streaming_sampling_rate: 1.pr32084_streaming_guardrail_e2e_validation.mp4
Test 1: Basic streaming rewrite
Guardrail mode:
incremental_diff. Server: replaceSENSITIVEVALUE_123->[REDACTED_123](withstream_holdback_charsto prevent partial prefix exposure).Command:
Raw chunks received by client:
Assembled client text:
The secret code is [REDACTED_123] and nothing else.Raw
SENSITIVEVALUE_123in any chunk? NoTest 1 - basic streaming rewrite showing [REDACTED_123]
Test 2: Holdback behavior
Server holds back partial prefix of "Thomas Weber" across chunk boundaries, replaces once full name arrives.
Command:
Raw chunks:
The/patient//[NAME_REDACTED]/had/condition/XYZ/.Assembled:
The patient [NAME_REDACTED] had condition XYZ.Raw
Thomas Weberin any chunk? No. PartialThomas Win any chunk? NoTest 2 - holdback preventing Thomas Weber from reaching client
Test 3: Prefix-rewrite / underflow failure
Server returns NONE for partial "John" (no holdback - this is the misconfiguration). When "John Smith" arrives at end of stream, tries to return "The patient is [NAME]." - but "John" was already emitted. Underflow detected.
Command:
Client received:
The/patient/is/Johnthen:No
data: [DONE]. Stream terminated abruptly (fail-closed). For non-A2A endpoints, the underflow raises HTTPException(400, stream_transform_underflow) which closes the HTTP connection. For A2A (JSON-RPC), it emits an in-stream JSON-RPC error instead.Test 3 - underflow causes abrupt stream termination
Test 4: Tool-call stream behavior
Tool call chunks pass through raw (before inspection). End-of-stream block-only check inspects tool calls and blocks.
Tool call chunks delivered raw to client first:
Then after all chunks accumulated, guardrail ran block-only check over assembled tool calls and fired:
Tool call chunks: delivered before inspection (end-of-stream inspection only, not block-before-delivery).
Test 5: Mixed text + tool-call
Text portion rewritten via incremental_diff. Tool call chunks passed through raw (identifiable by
system_fingerprint/obfuscationfields from raw OpenAI response; synthetic text chunks lack those).Assembled text:
The code is [REDACTED_123]. Now, I will call the get_info function...Raw
SENSITIVEVALUE_123? No. Tool call chunks present? Yes (get_info). Synthetic text chunks mixed with raw tool call chunks in same stream.Test 6: Baseline compatibility (block_only)
Same guardrail server (
rewrite_sensitive) but usingblock-only-guardrail(streaming_transform_mode: block_only). Rewrites dropped; raw value reaches client.Raw chunks:
S/ENSITIVE/VALUE/_/123all visible to client.Assembled:
The secret code is SENSITIVEVALUE_123 and nothing else.incremental_diffbehavior: not activated (backward compatible; opt-in only)Test 6 - block_only mode drops rewrites, raw value visible
Potential regressions / backward incompatible changes
No change for existing users:
streaming_transform_modedefaults toblock_only(exact pre-PR behavior).Tool calls in
incremental_diffmode: tool call argument chunks are delivered to the client before the end-of-stream block check fires. This was always true forblock_onlywithstreaming_end_of_stream_only: falsetoo (sampled block can fire mid-stream but tool call chunks always pass raw). No regression.Underflow for OpenAI chat completions: HTTP connection close rather than explicit in-stream SSE error event. For A2A the PR correctly emits a JSON-RPC error. Non-A2A clients need to handle connection close as an error indicator (no
data: [DONE]).ComplianceCheckermode-match fix: guardrails configured withguardrail_mode: [list]were never matching before this PR. This is a bug fix but changes behavior for list-mode guardrails. Previously-skipped compliance checks will now run.Type
✅ Test
Changes
No code changes; this branch merges PR #32084 from the contributor fork onto
litellm_internal_stagingto provide live proxy validation.To show artifacts inline, enable in settings.