litellm/tests/unit/proxy/guardrails/guardrail_hooks
izzybn 2c4d234466
fix(guardrails): classify only the frames each read completes in Presidio's first-frame wait (#54379)
* fix(guardrails): classify only the frames each read completes in Presidio's first-frame wait

Presidio's wait for the first frame with a JSON object re-split and re-classified its whole buffer on every read, so a long run of leading non-object frames cost CPU quadratic in the number of reads. It now buffers in a bytearray, finds frame ends only in the newly read bytes, and classifies only the frames that read completed

* test(guardrails): check Presidio's first-frame wait classifies each byte once instead of timing it

The test guide bans checks that depend on execution speed, so the CPU-time limit on the many-leading-reads test is replaced by a test that each read is handed only the frames it completed, including frame ends split across reads

* test(guardrails): drive Presidio's real first-frame wait in its per-read classification test

The test copied the wait's loop, so it still passed if the wait itself dropped the offset the classifier returns. The wait now takes the classifier as a parameter, defaulting to the one it called before, and the test runs the real wait with a recording classifier. The classifier docstring now says the caller relays the preface

* test(benchmarks): benchmark Presidio's first-frame wait over many leading reads and a frame split into many reads

Unit tests can't check the wait's cost without timing it, so CodSpeed now times the real wait over 6000 leading non-object reads and over one 48 KB frame in 16-byte reads. Rescanning every classified frame for a JSON object, or searching the whole unclassified tail for a frame end, makes these runs many times slower

* test(proxy): check the SSE frame-end search directly

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 11:15:49 +00:00
..
akto refactor(mcp): drop the experimental label from the MCP server and client paths (#48513) 2026-10-27 17:47:50 +00:00
aporia_ai
azure
content_filter fix(guardrails): scan refusal text in output guardrails on chat and responses (#54039) 2026-11-24 05:27:45 -08:00
dynamoai chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
guardrails_ai refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
ibm_guardrails chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
javelin
litellm_content_filter fix(guardrails): record every content filter match in logging_only and offer the mode in the UI (#46673) 2026-10-16 00:37:03 -07:00
noma fix(guardrails): honor streaming settings on the Noma v2 guardrail (#46606) 2026-10-15 18:29:05 -07:00
openai feat(openai)!: honor per-deployment workload identity on non-chat routes (#39966) 2026-10-16 22:25:15 +00:00
semantic_guard refactor(typing): clear 1181 basedpyright Any errors across 431 files (#47789) 2026-10-24 11:31:09 -07:00
unified_guardrails fix(anthropic): skip a stream data line that is not a JSON object (#53393) 2026-11-22 22:54:02 +00:00
zscaler_ai_guard fix(zscaler_ai_guard)!: scan only the last user turn on requests (#50139) 2026-11-05 13:00:21 -08:00
__init__.py
_cisco_ai_defense_test_utils.py
code_execution_compliance_dataset.json
conftest.py fix(grayswan): honor failure policy for invalid monitor decisions (#52191) 2026-11-17 14:59:20 -08:00
test_agent_365.py
test_aim.py
test_airia.py feat(guardrails): add Airia guardrail integration (#40784) 2026-10-14 15:45:47 -07:00
test_alice.py fix(guardrails): stop the alice guardrail sending each prompt four times (#51392) 2026-11-17 18:13:42 -08:00
test_bedrock_guardrail_tool_text_scans.py fix(guardrails)!: close gaps in bedrock tool call and tool description scans (#54169) 2026-11-25 06:56:15 +00:00
test_bedrock_guardrails.py fix(guardrails): scan the system prompt and tool results in Bedrock during_call on /v1/messages (#53507) 2026-11-24 17:13:50 -08:00
test_bedrock_invoke_guardrail_checks.py
test_block_code_execution.py
test_block_code_execution_compliance.py
test_cato_networks.py fix(anthropic)!: do not surface server_tool_use as client tool_calls (#48385) 2026-11-06 03:54:34 -08:00
test_cisco_ai_defense_chat.py fix(decisions): accept OpenAI input_json content parts on /v1/decisions (#52805) 2026-11-20 13:33:36 -08:00
test_cisco_ai_defense_mcp.py
test_collieai.py feat(guardrails): add the CollieAi guardrail integration (#49224) 2026-11-12 01:05:12 +00:00
test_compresr.py fix(websearch)!: keep the provider prefix on the agentic follow-up model (#38885) 2026-10-29 04:47:18 -07:00
test_conduct.py
test_crowdstrike_aidr.py
test_custom_code_bounded_execution.py
test_decision_model.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_deepkeep.py
test_dynamoai.py
test_enkryptai.py
test_generic_guardrail_api.py fix(guardrails): read per-request extra_body from the proxy request in the generic guardrail api (#52438) 2026-11-19 21:00:27 +00:00
test_grayswan.py fix(guardrails): mask reasoning text on /v1/responses output (#52504) 2026-11-19 01:25:06 -08:00
test_headroom.py fix(guardrails): keep cache_control in /v1/messages guardrail translation for Claude and Gemini aliases (#53742) 2026-11-23 09:35:07 -08:00
test_hiddenlayer.py fix(guardrails): mask reasoning text on /v1/responses output (#52504) 2026-11-19 01:25:06 -08:00
test_javelin.py
test_lakera_ai.py fix(anthropic)!: do not surface server_tool_use as client tool_calls (#48385) 2026-11-06 03:54:34 -08:00
test_lakera_ai_v2.py refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
test_lasso.py fix(anthropic)!: do not surface server_tool_use as client tool_calls (#48385) 2026-11-06 03:54:34 -08:00
test_llm_shield_proxy.py fix(anthropic): skip a stream data line that is not a JSON object (#53393) 2026-11-22 22:54:02 +00:00
test_mcp_end_user_permission.py
test_mcp_security.py fix(mcp): drop hosted MCP tool_choice under drop_params and honor drop_params in Bedrock batch rows (#53697) 2026-11-23 08:51:59 -08:00
test_microsoft_purview.py fix(responses): answer Codex compaction_trigger on the chat-completions bridge (#53266) 2026-11-21 14:53:31 -08:00
test_model_armor.py fix(guardrails): scan refusal text in output guardrails on chat and responses (#54039) 2026-11-24 05:27:45 -08:00
test_noma.py fix(streaming): rebuild each choice of an n>1 chat stream on its own (#49002) 2026-10-29 18:29:14 -07:00
test_noma_v2.py fix(bedrock)!: stream Converse passthrough frames through post_call guardrails instead of buffering (#46307) 2026-10-17 00:53:53 -07:00
test_onyx.py
test_ovalix.py fix(guardrails): mask reasoning text on /v1/responses output (#52504) 2026-11-19 01:25:06 -08:00
test_ovalix_extraction.py feat(ovalix)!: scan files, tool calls and tool results (#49309) 2026-10-31 17:01:12 -07:00
test_pangea.py fix(anthropic)!: do not surface server_tool_use as client tool_calls (#48385) 2026-11-06 03:54:34 -08:00
test_panw_prisma_airs.py fix(anthropic): skip a stream data line that is not a JSON object (#53393) 2026-11-22 22:54:02 +00:00
test_presidio.py fix(guardrails): classify only the frames each read completes in Presidio's first-frame wait (#54379) 2026-11-25 11:15:49 +00:00
test_presidio_union_fix.py
test_promptguard.py
test_qualifire.py fix(guardrails): mask reasoning text on /v1/responses output (#52504) 2026-11-19 01:25:06 -08:00
test_reco.py feat(guardrails): add native Reco guardrail provider (pre_call), fail closed by default (#48243) 2026-10-24 15:33:17 -07:00
test_repelloai.py fix(anthropic)!: do not surface server_tool_use as client tool_calls (#48385) 2026-11-06 03:54:34 -08:00
test_response_rejection_guardrail_code.py
test_singulr.py
test_straiker.py feat(guardrails): hold streamed tool calls for the verdict and log prompts blocked with a reply (#51872) 2026-11-20 16:58:15 -08:00
test_structured_messages_writeback.py fix(anthropic): send an https PDF image_url to Claude as a document (#49708) 2026-11-03 07:05:15 +00:00
test_tool_permission.py fix(responses): one answer for which tool a bridged call is, read by the reply, tool permission and spend logs (#53269) 2026-11-24 22:26:42 +00:00
test_tool_policy_guardrail.py feat(vertex_ai): add Meta Muse models on Vertex AI (#50768) 2026-11-21 13:00:24 -08:00
test_typesafe.py
test_vigil_guard.py
test_wingback.py
test_xecguard.py