litellm/tests/unit/proxy/guardrails
Mateo Wang 41210f8f7b
feat(guardrails): opt-in Bedrock scan of tool-call arguments and tool descriptions as text (#52999)
* feat(guardrails): opt-in Bedrock ApplyGuardrail scan of tool-call arguments and tool descriptions as text

Tool calls in the request history are scanned as INPUT and model-generated tool calls as OUTPUT on chat completions, messages and responses. scan_tool_descriptions_as_text now accepts bedrock

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(guardrails): scan decoded tool-call arguments and reject the tool text scans in during_call mode

Tool-call arguments are JSON-decoded before the Bedrock scan so escapes cannot hide text, arguments nested too deep to scan are blocked, and both flags are rejected for a Bedrock guardrail running during_call, whose native hook never reaches the scan

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(guardrails): dedupe tool-call keys before the escape check and assert scanned text in the default-off test

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(guardrails): scan streamed chat completions tool calls on the Bedrock post-call stream hook

A tool-call-only /v1/chat/completions stream was assembled and scanned as text only, so scan_tool_calls_as_text never saw the streamed arguments

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(guardrails): type the Bedrock tool-call scan inputs so the typecheck ceilings hold

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(guardrails): scan custom tool calls in the Bedrock tool-call text scan

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(guardrails): scan legacy function_call in the Bedrock tool-call text scan; inject the http handler in tests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(guardrails): answer the masked tool-call scan test with a masked Bedrock reply

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(guardrails): type the legacy function_call lookup

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(guardrails): block a tool call that the Bedrock tool-call text scan masks

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(guardrails): scan tool-call argument values that a repeated JSON key shadows

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(guardrails): type the tool text scan test parameters and split a two-loop comprehension

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(guardrails): type the stream helpers in the tool text scan tests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(guardrails): read scan_tool_calls_as_text through a helper and type the bedrock post-call hook

Reads the new flag through effective_scan_tool_calls_as_text_for_guardrail like the sibling
guardrail flags, so guardrail objects without the attribute keep working, types the legacy
bedrock post-call hook's request body to clear a new basedpyright error, and regenerates the
API schema files for the new field

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-20 08:08:19 +00:00
..
guardrail_hooks feat(guardrails): opt-in Bedrock scan of tool-call arguments and tool descriptions as text (#52999) 2026-11-20 08:08:19 +00: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
test_guardrail_load_balancing.py
test_guardrail_registry.py feat(guardrails): opt-in Bedrock scan of tool-call arguments and tool descriptions as text (#52999) 2026-11-20 08:08:19 +00: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