litellm/tests/unit/proxy/utils
Mateo Wang 00bedbd20e
fix(guardrails): keep streamed chat chunks as JSON when Azure text moderation or LLM Guard passes them (#55695)
* fix(guardrails): keep streamed chat chunks as JSON when Azure text moderation passes

* fix(guardrails): skip whitespace-only text in the Azure text moderation streaming hook

Azure Content Safety answers whitespace-only text with a 400, which ended the stream with an error event

* fix(guardrails): keep streamed chat chunks as JSON when LLM Guard passes

The LLM Guard streaming hook returned the text it checked, and the proxy replaces a chunk with any value a streaming hook returns, so every chunk went out as bare text

* fix(guardrails): give Azure text moderation's streamed block event a readable message

The block event now uses the same error shape as other proxy errors, so the
OpenAI SDK shows the Azure reason instead of a generic streaming error. Tests
stream a banned word split across two chunks through both the Azure and LLM
Guard hooks

* fix(proxy): skip streaming hooks for chunks that add no text

Tool-call, role-only and finish chunks add no text, so asking a streaming
hook about them sent guardrails like Azure text moderation the same text
again on every tool-call chunk. The token-id drop still runs on them

* fix(guardrails): raise Azure text moderation streaming blocks so the proxy's failure path handles them
2026-12-02 15:10:49 -08:00
..
helpers feat(proxy)!: make Scalar the default API reference and remove ReDoc (#53063) 2026-11-23 10:49:54 -08:00
prisma_and_spend fix(proxy): honor disable_spend_logs from db config and on redis replay (#54526) 2026-11-28 11:25:38 -08:00
proxy_logging fix(guardrails): keep streamed chat chunks as JSON when Azure text moderation or LLM Guard passes them (#55695) 2026-12-02 15:10:49 -08:00
__init__.py test(proxy): move utils, agent_endpoints and endpoint tests into tests/unit/proxy (#44006) 2026-10-01 11:06:42 -07:00