fix(test): update realtime guardrail test assertions for voice violation behavior#22332
fix(test): update realtime guardrail test assertions for voice violation behavior#22332
Conversation
…ion behavior Tests were asserting no response.create/conversation.item.create sent to backend when guardrail blocks, but the implementation intentionally sends these to have the LLM voice the guardrail violation message to the user. Updated assertions to verify the correct guardrail flow: - response.cancel is sent to stop any in-progress response - conversation.item.create with violation message is injected - response.create is sent to voice the violation - original blocked content is NOT forwarded Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes two previously failing realtime streaming guardrail tests by aligning their assertions with the actual implementation in
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| tests/test_litellm/litellm_core_utils/test_realtime_streaming.py | Updated two guardrail test assertions to align with the actual implementation behavior: guardrail blocks now voice the violation message via conversation.item.create + response.create. Minor issues: stale docstring and fragile string-based filtering. |
Sequence Diagram
sequenceDiagram
participant Backend as Backend WS (LLM)
participant Proxy as RealTimeStreaming
participant Client as Client WS
Note over Backend,Client: Audio transcription guardrail flow
Backend->>Proxy: conversation.item.input_audio_transcription.completed
Proxy->>Proxy: run_realtime_guardrails(transcript)
Proxy-->>Proxy: Guardrail raises exception (blocked)
Proxy->>Backend: response.cancel
Proxy->>Client: error (guardrail_violation)
Proxy->>Backend: conversation.item.create (violation prompt)
Proxy->>Backend: response.create
Note over Backend,Client: Text input guardrail flow
Client->>Proxy: conversation.item.create (user text)
Proxy->>Proxy: run_realtime_guardrails(text)
Proxy-->>Proxy: Guardrail raises exception (blocked)
Proxy->>Backend: response.cancel
Proxy->>Client: error (guardrail_violation)
Proxy->>Backend: conversation.item.create (violation prompt)
Proxy->>Backend: response.create
Note over Proxy: Original message NOT forwarded
Last reviewed commit: 9a48c8e
| # Filter out guardrail-injected items (contain "Say exactly the following message") | ||
| original_items = [ | ||
| item for item in forwarded_items | ||
| if not any( | ||
| "Say exactly the following message" in c.get("text", "") | ||
| for c in item.get("item", {}).get("content", []) | ||
| if isinstance(c, dict) | ||
| ) |
There was a problem hiding this comment.
Fragile coupling to implementation string literal
Filtering guardrail-injected items by checking for the hardcoded substring "Say exactly the following message" is brittle — if the prompt wording in realtime_streaming.py:351 changes, this test will silently pass incorrectly (it would stop filtering guardrail items and could mask a real forwarding bug). Consider asserting on a more stable property, such as checking that no item contains the original user text ("My email is test@example.com").
Additional Comments (1)
The docstring still says "NOT sending response.create to the backend", but the updated assertions now correctly expect exactly one |
Addresses Greptile review feedback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
response.create/conversation.item.createmessages are sent to the backend when a guardrail blocksrealtime_streaming.py:348-363intentionally sends these to have the LLM voice the guardrail violation message to the user in audio sessionstest_realtime_guardrail_blocks_prompt_injection: Now verifies the full guardrail flow —response.cancel+ guardrailconversation.item.create+response.createtest_realtime_text_input_guardrail_blocks_and_returns_error: Now filters out guardrail-injected items and only asserts the original blocked message wasn't forwardedTest plan
🤖 Generated with Claude Code