litellm/tests/test_litellm/proxy/guardrails/guardrail_hooks
ryan-crabbe-berri 680bcfd8aa
test(lint): ban blind pytest.raises(Exception) with ruff B017 (#37731)
* test(lint): ban blind pytest.raises(Exception) with ruff B017

A bare pytest.raises(Exception) accepts whatever the body throws. The TypeError
a refactor introduces satisfies it exactly as well as the rejection the test was
written for, so the crash reads as a pass and the test never goes red.

All 111 existing sites are narrowed here. A runtime probe recorded the concrete
exception each one actually catches, and each site now names that type. Where
the code under test genuinely raises a bare Exception, the site pins a stable
slice of the message with match= instead.

Two sites tell on themselves. The shared responses-API cancel test raises
"custom_llm_provider is required but passed as None" rather than talking to a
provider at all, because cancel_responses takes a provider, not a model. And
test_bedrock_guardrails_with_streaming was the only test in its file still
passing without AWS credentials, because the NoCredentialsError boto3 raised
long before the guardrail ran satisfied the blind raises.

* fix(test): widen the openai batch-dispatch assertion to OpenAIError

The narrowed NotFoundError only holds where OPENAI_API_KEY is set. Without one
the SDK raises OpenAIError while building the client, long before any 404, so CI
went red. OpenAIError covers both and still rejects a TypeError from a refactor.
2026-08-20 18:09:42 -07:00
..
azure fix(guardrails): scan text on /guardrails/apply_guardrail for Azure Content Safety (#36894) 2026-08-17 11:18:40 -07:00
content_filter fix(guardrails): scan /v1/messages tool traffic 2026-08-05 14:11:27 -07:00
guardrails_ai style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
openai fix(guardrails): keep guardrail information in spend logs when the caller sends its own metadata 2026-07-24 16:20:44 -07:00
unified_guardrails fix(a2a): return SSE (text/event-stream) for message/stream instead of NDJSON (#35037) 2026-08-20 16:19:58 -07:00
_cisco_ai_defense_test_utils.py feat(guardrails): add Cisco AI Defense integration (#28249) (#30338) 2026-06-12 23:21:23 -07:00
code_execution_compliance_dataset.json feat(add-new-block_code_execution-guardrail): prevent agent from executing code (#22154) 2026-02-25 22:02:14 -08:00
test_aim.py fix(guardrails): walk Responses-API text taxonomy in shared content helpers (#32542) 2026-07-08 23:24:11 -07:00
test_bedrock_guardrails.py test(lint): ban blind pytest.raises(Exception) with ruff B017 (#37731) 2026-08-20 18:09:42 -07:00
test_bedrock_invoke_guardrail_checks.py feat(bedrock guardrails): add resource-less InvokeGuardrailChecks (detect-only) mode (#33299) 2026-07-14 19:31:17 -07:00
test_block_code_execution.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_block_code_execution_compliance.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_cato_networks.py Litellm OSS Staging (#29161) 2026-06-01 21:22:35 -07:00
test_cisco_ai_defense_chat.py feat(guardrails): add Cisco AI Defense integration (#28249) (#30338) 2026-06-12 23:21:23 -07:00
test_cisco_ai_defense_mcp.py feat(guardrails): add Cisco AI Defense integration (#28249) (#30338) 2026-06-12 23:21:23 -07:00
test_compresr.py fix(guardrails): preserve cache_control breakpoints in compresr write-back 2026-07-25 14:47:25 -07:00
test_crowdstrike_aidr.py fix(guardrails): send only new messages since last assistant turn to CrowdStrike AIDR (#31974) 2026-07-06 09:47:00 -07:00
test_deepkeep.py feat: add deepkeep as custom guardrail (#33844) 2026-07-20 19:27:40 -07:00
test_dynamoai.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_enkryptai.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_generic_guardrail_api.py feat(guardrails): streaming text transformation in generic_guardrail_api (#33110) 2026-07-14 17:38:11 -07:00
test_grayswan.py fix(guardrails): forward grayswan scan id header (#32544) 2026-07-08 15:05:27 -07:00
test_headroom.py fix(proxy): improve Headroom 404 compression error diagnostics (#35952) 2026-08-07 08:16:41 -07:00
test_hiddenlayer.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_lakera_ai_v2.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_lasso.py feat(lasso): send source.type=litellm for Used By attribution (#33090) 2026-07-13 10:39:41 -07:00
test_mcp_end_user_permission.py test: remove tests that never execute 2026-08-12 10:45:38 -07:00
test_mcp_security.py Add MCP Security guardrail to block unregistered MCP servers (#21429) 2026-02-17 21:19:13 -08:00
test_microsoft_purview.py feat(guardrails): add Microsoft Purview DLP guardrail (#24966) 2026-05-22 15:59:04 -07:00
test_model_armor.py fix(guardrails): keep guardrail information in spend logs when the caller sends its own metadata 2026-07-24 16:20:44 -07:00
test_noma.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_noma_v2.py perf(guardrails): stop sending the conversation twice in the noma v2 payload (#36764) 2026-08-17 15:37:17 -07:00
test_onyx.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_ovalix.py feat: litellm oss 110626 (#30202) 2026-06-11 22:30:26 -07:00
test_pangea.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_panw_prisma_airs.py fix(panw_prisma_airs): scan tool call args as plain text, not a tool_event (#37038) 2026-08-15 23:14:43 +00:00
test_presidio.py test(lint): ban blind pytest.raises(Exception) with ruff B017 (#37731) 2026-08-20 18:09:42 -07:00
test_presidio_union_fix.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_promptguard.py Add PromptGuard guardrail integration (#24268) 2026-04-09 08:12:24 -07:00
test_qualifire.py Hotfix - docs qualifire (#18724) 2026-01-07 17:23:12 +05:30
test_repelloai.py chore: litellm oss staging (#30745) 2026-06-18 13:55:35 -07:00
test_response_rejection_guardrail_code.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_singulr.py chore(ci): merge oss branch (#33784) 2026-07-17 23:22:13 +00:00
test_straiker.py feat(proxy): redact or drop individual batch records instead of rejecting the file (#37561) 2026-08-20 13:12:55 -07:00
test_structured_messages_writeback.py fix(guardrails/headroom): stop compressing the turn the model must act on (#35294) 2026-07-30 18:53:31 -07:00
test_tool_permission.py fix(guardrails): scan and re-emit raw Anthropic SSE streams in the bedrock post-call hook (#36598) 2026-08-13 07:23:49 +00:00
test_tool_policy_guardrail.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_vigil_guard.py Litellm OSS Staging 010626 (#29422) 2026-06-01 21:42:51 -07:00
test_xecguard.py fix(xecguard): sanitize scan result before recording it for logging (#32935) 2026-07-12 02:46:02 +00:00