litellm/tests/unit/proxy/guardrails
izzybn c1eb4031d8
fix(responses): keep every input item in the logged input (#54253)
* fix(responses): keep every input item in the logged input

The cache control and prompt management hooks ran on the role-bearing input items only and left that filtered list as the logged messages, so function_call and function_call_output items never reached logging callbacks. A stray messages field on a /responses body also replaced the logged input

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

* fix(responses): keep the lint gate level and cover the stored prompt path

The pre-call logging check read the request body through untyped attribute accesses, which pushed the type gate past its ceiling. It now goes through one typed helper. Adds a regression test for a stored prompt on /responses

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

* fix(responses): log the copy a guardrail masked, test injection on native routing

A pre-call guardrail that rewrites only messages on a Responses call keeps its masked copy in the logged input, and one that replaces input is logged too. The cache-control logging tests now run on native Responses routing and assert the merged input with the injected marker

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

* fix(responses): log a string input as a user message and keep every item in WebSocket turn logs

Logging.update_messages wraps a str input the way Logging.__init__ does, so a /v1/responses call with input="..." still logs a user message after the logged input is reset from the hooked body. Each Responses WebSocket turn now logs every item of its response.create frame, so function_call and function_call_output items reach callbacks there too. The new tests are fully typed and their guardrail stubs return new dicts

* fix(responses): log nested response.create frames and record WebSocket turns without patching Logging

* fix(responses): set a WebSocket turn's logged messages through update_messages

log_pre_api_call's messages argument and the failed-turn token estimate read Logging.messages, which still held the connection's value. Also drop the WebSocket route from the responses input check, since its pre-call body never carries input

* test(responses): prove vector store context keeps tool items in the logged input

* fix(xecguard): read input_text and output_text parts when flattening messages

* test(responses): fake OpenAI over HTTP in the logged input tests and type the XecGuard test

---------

Co-authored-by: mateo <277851410+mateo-berri@users.noreply.github.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-12-01 00:40:08 +00:00
..
guardrail_hooks fix(responses): keep every input item in the logged input (#54253) 2026-12-01 00:40:08 +00:00
__init__.py feat(guardrails): send a configured gateway_name from noma_v2 to Noma (#43678) 2026-09-29 10:20:40 -07:00
test_anthropic_sse.py fix(guardrails)!: mask PII in Presidio tool calls and refuse streams it cannot read (#53396) 2026-11-23 03:09:43 -08: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(proxy): move management_endpoints, management_helpers and guardrails tests into tests/unit/proxy (#44003) 2026-10-01 10:52:03 -07:00
test_content_utils.py fix(decisions): accept OpenAI input_json content parts on /v1/decisions (#52805) 2026-11-20 13:33:36 -08:00
test_custom_code_security.py test(unit): make 21 flaky unit tests deterministic (#54785) 2026-11-26 20:48:13 -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 fix(guardrails)!: close gaps in bedrock tool call and tool description scans (#54169) 2026-11-25 06:56:15 +00:00
test_guardrail_helpers.py feat(guardrails): reject requests that name an unregistered guardrail when reject_unregistered_guardrails is on (#53214) 2026-11-20 18:39:29 -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 fix(guardrails)!: close gaps in bedrock tool call and tool description scans (#54169) 2026-11-25 06:56:15 +00:00
test_init_guardrails.py fix(guardrails): stop Presidio logging_only from masking the client response (#54502) 2026-11-25 21:42:48 +00: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(proxy): move management_endpoints, management_helpers and guardrails tests into tests/unit/proxy (#44003) 2026-10-01 10:52:03 -07:00
test_usage_endpoints.py fix(guardrails): serve usage detail for a guardrail removed from config (#53315) 2026-11-23 11:54:37 -08:00
test_usage_tracking.py feat(spend-logs): rust spend log ledger writer (#52163) 2026-11-20 16:31:04 -08:00