mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-30 01:08:33 +00:00
* fix(guardrails): scan refusal text on chat and Responses output Output guardrails only read message content and output_text parts, so a model refusal reached the client unmasked and a blocking guardrail let it through. Presidio, Bedrock Guardrails, Model Armor and the unified handlers now read and rewrite chat message.refusal, streamed delta.refusal, Responses refusal parts and refusal stream events, on HTTP and on WebSocket Responses. * fix(guardrails): write Model Armor redactions into a single-part Responses body Model Armor returns one sanitized string for everything it scanned, so a Responses body answered 400 and a stream was blocked whenever masking had to rewrite it. When the scan came from one content part, write the string into that part and sync the buffered stream events. A body that joined several parts or tool-call arguments has no single place for the string and stays blocked. * fix(guardrails): keep Model Armor's non-streamed Responses scan on message text A masking Model Armor answered 400 on a Responses body with an email in forced tool call arguments, where main answers 200. Scan only message text on that path, since one sanitized string cannot be written back into tool call arguments, and spread that string over every part so a body with several parts is masked instead of blocked * fix(logging): redact chat refusal text when message logging is off * fix(guardrails): keep Model Armor masks on answer parts and write back emptied refusals A refusal a guardrail empties on an ended chat stream is now written back as an empty string instead of escaping raw Model Armor on non-streamed Responses scans tool call arguments when it blocks, masks only answer message parts so a bridged reasoning item keeps its own text, and blocks a stream whose text events fall outside message parts. A chat choice with both content and a refusal gets the masked text once, in content * fix(guardrails): check Armor tool args in mask mode and content filter streamed refusals Model Armor masking on non-streamed Responses now scans tool call arguments and reasoning too, so its URI, jailbreak and RAI filters block a flagged argument. It scans the message text again alone when the two differ, so the mask lands only on the answer The content filter's chat stream hook keeps one holdback per choice and field, so a streamed refusal is masked or blocked like content The shared chat stream scan skips relayed error strings instead of crashing on them, and the Rust spend log redaction covers the refusal field like the Python one * fix(guardrails): block a Responses answer that Armor's message-only rescan flags When Model Armor masks a non-streamed Responses body that also carries tool calls or reasoning, it scans the message text again alone to place its mask. That second scan now blocks the response when it flags the text, instead of only reading its masked copy Adds a regression test that a Presidio Responses stream cut short in the middle of a tool call ends with an error before any event goes out, so its raw arguments never reach the client * fix(guardrails): block Model Armor's message-only rescan when it matches without a rewrite Model Armor's second scan of non-streamed Responses message text now answers 400 when it reports a de-identify match but returns no rewrite, as the shared guardrail path already does, instead of sending the matched text out unchanged. The rescan also writes its own guardrail log entry, so a block from it no longer reads as success Presidio already ends a Responses stream when the analyzer cannot be reached, and a regression test now pins that. A streamed chunk builder test that passed at the merge base is removed, since it caught nothing * fix(guardrails): keep response text out of the shared Responses output debug log The shared Responses output extractor logged each whole output item at debug level, so with debug logging on, the answer text that Model Armor now scans on non-streamed Responses reached the logs even with sanitize_error_detail on. The line now logs only the item index and its part count * fix(guardrails): block a non-streamed Responses Armor match that comes back without a rewrite Under a masking Model Armor guardrail, a non-streamed Responses scan that reports a de-identify match but returns no rewrite now answers 400, as the message-only rescan and the stream path already do, instead of sending the matched text out unchanged. Chat keeps main's behavior there, since failing it would turn requests main answers with 200 into errors --------- Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| count_tokens | ||
| __init__.py | ||
| test_openai_count_tokens_transformation.py | ||
| test_openai_responses_data_residency.py | ||
| test_openai_responses_guardrail_handler.py | ||
| test_openai_responses_guardrail_tool_merge.py | ||
| test_openai_responses_http.py | ||
| test_openai_responses_transformation.py | ||