litellm/tests/unit/proxy/guardrails
mrinal-berri 3b05f390f2
feat(guardrails): opt-in pre_call scan of tool descriptions as text for PANW and Presidio (#50301)
* feat(guardrails): opt-in pre_call scan of tool descriptions as text for PANW and Presidio

PANW Prisma AIRS and Presidio only scan text, so the tools[] sent to the model
reached it unscanned. The new per-guardrail scan_tool_descriptions_as_text flag
scans every description string in tools[] on pre_call, one guardrail call per
tool, so a block returns 400 and a mask rewrites the description in place.
Other guardrails are unchanged and reject the flag at startup.

Resolves LIT-8384

* fix(guardrails): also scan legacy functions[] descriptions as text

With scan_tool_descriptions_as_text on, a Chat Completions client could move a
tool definition into the legacy functions[] list and skip the scan. The scan now
covers both tools[] and functions[], writing masks back to whichever field held
the definition. Test helpers are now fully typed.

* test(guardrails): cover untouched tools through PANW instead of patching Presidio

The Presidio case replaced a private session method. Its one unique check, that a
tool without a flagged description is sent unchanged, now runs through PANW's
injected HTTP client. Real Presidio is covered by the live proof in the PR.

* chore(ui): regenerate OpenAPI snapshot and UI types for scan_tool_descriptions_as_text

* refactor(guardrails): return tool-scan failures as values and raise them in one place

An over-deep tool definition and a guardrail that returns the wrong number of
descriptions now come back as _ToolNotScanned values, and _raise_public maps them
to the existing 400 body, as endpoint_image_scan does. Adds tests for both paths.

* fix(guardrails): scan tool descriptions carried in Responses additional_tools and tool_search_output input items

Tool definitions sent inside /v1/responses input items reach the model the same way
top-level tools do, through the chat bridge hoist or native forwarding, but the
opt-in pre_call scan only read the top-level tools and functions lists. Each tool is
now located by its path in the request and masked text is written back at that path.

* chore(guardrails): drop docstrings that restate the tool-description scan code
2026-11-19 14:04:10 -08:00
..
guardrail_hooks feat(guardrails): opt-in pre_call scan of tool descriptions as text for PANW and Presidio (#50301) 2026-11-19 14:04:10 -08:00
__init__.py
test_anthropic_sse.py fix(guardrails)!: keep the upstream error when a /v1/messages stream ends in one (#49088) 2026-10-31 02:56:20 -07:00
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 fix(guardrails): mask reasoning text on /v1/responses output (#52504) 2026-11-19 01:25:06 -08:00
test_deferred_guardrail_logging.py fix(logging): retain streaming success logging tasks until they finish (#52067) 2026-11-16 11:21:05 -08:00
test_endpoint_image_scan.py feat(guardrails): scan an image on /apply_guardrail with a Bedrock guardrail (#51016) 2026-11-17 18:13:28 +00:00
test_guardrail_coverage.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
test_guardrail_endpoints.py feat(guardrails): scan an image on /apply_guardrail with a Bedrock guardrail (#51016) 2026-11-17 18:13:28 +00:00
test_guardrail_helpers.py fix(proxy): reject unknown guardrail names on key, user, team and project writes (#51080) 2026-11-11 19:28:45 -08:00
test_guardrail_initializers.py refactor(types): replace Any with proven types in 157 files (#44798) 2026-10-06 15:31:54 +00:00
test_guardrail_load_balancing.py test: migrate SDK and proxy-booting legacy CircleCI tests to their tiers (#45758) 2026-10-11 00:17:21 -07:00
test_guardrail_registry.py feat(guardrails): opt-in pre_call scan of tool descriptions as text for PANW and Presidio (#50301) 2026-11-19 14:04:10 -08:00
test_init_guardrails.py fix(config): treat blank env values as unset so the proxy neither crash-loops nor silently drops a guardrail (#46341) 2026-10-14 12:49:31 -07:00
test_llm_as_a_judge.py fix(guardrails): mask reasoning text on /v1/responses output (#52504) 2026-11-19 01:25:06 -08:00
test_mcp_jwt_signer.py fix(mcp)!: forward the LiteLLM key when the admin configures it (#50604) 2026-11-10 20:51:34 -08:00
test_pillar_guardrails.py refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
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 feat(accounting): add opt-in SpendLogs ledger (#49856) 2026-11-04 17:49:15 -08:00