litellm/tests/unit/proxy/guardrails
simonp9 594f862bf3
fix(streaming): rebuild each choice of an n>1 chat stream on its own (#49002)
* fix(streaming): rebuild each choice of an n>1 chat stream on its own

stream_chunk_builder folded every choice of an n>1 chat stream into choice 0, so post-call guardrails such as tool_permission re-emitted one choice holding every choice's tool calls, and spend logs and logging callbacks kept only the first choice's text. Each choice is now assembled from its own chunks, while usage, cost, and hidden params still read the whole stream. Cisco AI Defense compares each choice's streamed text on its own so safe n>1 streams still pass through unchanged.

* fix(streaming): keep bridged reasoning summaries on choice 0 and infer an unreported choice finish reason

* fix(streaming): match MCP follow-ups and bridged summary text to the rebuilt choices

MCP auto-execute now answers only the first choice's tool calls, since its
follow-up turn continues that choice alone. The Responses bridge streams a
space before each reasoning summary part after the first, matching the
non-streamed reply. build_base_response now takes the per-choice streams
instead of having its choices replaced afterwards

* fix(streaming): space every later reasoning summary part, deny per judged call, and rebuild in one text pass

* fix(guardrails): key tool_permission denials for custom tool calls too, and type the stream rebuild's messages

* fix(mcp): continue the first choice that called a tool when an n>1 reply auto-executes MCP tools

* fix(noma): scan each choice of a multi-choice reply on its own

* fix(noma): keep masked choices when a later choice's scan fails open on a stream

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-10-29 18:29:14 -07:00
..
guardrail_hooks fix(streaming): rebuild each choice of an n>1 chat stream on its own (#49002) 2026-10-29 18:29:14 -07:00
__init__.py
test_anthropic_sse.py
test_auto_router_compression.py refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
test_content_filter_path_traversal.py
test_content_utils.py fix(guardrails): skip embeddings input in google_text_moderation (#48934) 2026-10-28 20:05:03 -07:00
test_custom_code_security.py
test_deferred_guardrail_logging.py fix(cost): finalize synchronous response cost once for header, spend log and rollups (#48993) 2026-10-29 11:46:49 -07:00
test_guardrail_coverage.py fix(guardrails)!: make lakera_v2 on_flagged block reject PII-only detections, add mask (#48944) 2026-10-29 11:48:37 -07:00
test_guardrail_endpoints.py
test_guardrail_initializers.py
test_guardrail_load_balancing.py
test_guardrail_registry.py
test_init_guardrails.py
test_llm_as_a_judge.py
test_mcp_jwt_signer.py
test_pillar_guardrails.py
test_prompt_security_guardrails.py fix(anthropic)!: send /v1/messages PDF documents to OpenAI-shaped providers as file parts (#47166) 2026-10-29 08:06:12 -07:00
test_qostodian_nexus_guardrail.py
test_usage_endpoints.py
test_usage_tracking.py