litellm/tests/test_litellm/proxy/guardrails
Itay Ovadia 155e4080c4 fix(guardrails): align the max_messages window and stop identity being taken from the request body
Three findings from review of the previous commit.

max_messages applied the same number to two lists that count different things:
texts is fragment-based (a multimodal turn contributes several entries, a
tool-call-only turn contributes none) while structured_messages is message-based,
so the two views of the payload could cover different parts of the conversation,
sending text from an omitted turn or dropping text from a retained one. The
message window is now the source of truth and the text window is the number of
fragments those retained messages contain, counted with a role-agnostic helper so
an unenumerated role cannot silently shrink it.

/guardrails/apply_guardrail built request_data straight from the caller's
metadata, so a caller could claim a user_api_key_alias or user_api_key_team_id
that a guardrail exempts and get its text back unscanned. The authenticated
identity is now layered on top of the caller's metadata via the same sanitizer
the in-line path uses, so what authentication established wins. Caller metadata
that is not identity still passes through untouched, and every guardrail on that
route now sees the caller information it already sees in-line.

The per_session dedup cache was keyed only on the caller-supplied session id, so
whoever claimed an id first suppressed another tenant's entry for the same id.
The key is now namespaced by the authenticated key hash, falling back to the team
id.
2026-08-15 23:40:28 +03:00
..
guardrail_hooks fix(guardrails): align the max_messages window and stop identity being taken from the request body 2026-08-15 23:40:28 +03:00
test_content_filter_path_traversal.py Litellm OSS Staging 010626 (#29422) 2026-06-01 21:42:51 -07:00
test_content_utils.py feat(guardrails): add payload, applicability, dispatch and logging controls to generic_guardrail_api 2026-08-15 23:40:28 +03:00
test_custom_code_security.py fix(guardrails): return HTTP 400 for litellm content filter blocks (#28418) 2026-05-30 14:28:46 -07:00
test_deferred_guardrail_logging.py feat(proxy): enforce key/team guardrails on bedrock passthrough routes (#30194) 2026-06-12 07:23:29 -07:00
test_guardrail_coverage.py fix(tests): use canonical litellm_enterprise import path (#27699) 2026-05-12 12:32:57 -07:00
test_guardrail_endpoints.py fix(guardrails): align the max_messages window and stop identity being taken from the request body 2026-08-15 23:40:28 +03:00
test_guardrail_registry.py fix(guardrails): refuse scan_only_tool_results combos that scan nothing 2026-08-06 01:58:06 -07:00
test_init_guardrails.py fix(guardrails): chunk oversized Bedrock ApplyGuardrail requests instead of failing (#36119) 2026-08-07 19:44:24 -07:00
test_llm_as_a_judge.py fix(guardrails): resolve judge_model credentials via lazy Router lookup in llm_as_a_judge (#34509) 2026-07-25 20:16:43 -07:00
test_mcp_jwt_signer.py fix(mcp): JWT on tools/list and REST tools/call server resolution (#28227) 2026-05-20 13:31:44 -07:00
test_pillar_guardrails.py chore(proxy): harden request control fields 2026-04-29 22:35:17 -07:00
test_prompt_security_guardrails.py fixing prompt-security's guardrail implementation (#19374) 2026-01-21 20:09:40 -08:00
test_qostodian_nexus_guardrail.py feat: add Qohash Nexus guardrail hook (#24927) 2026-05-01 17:26:32 +05:30
test_usage_endpoints.py fix(guardrails): show YAML-defined guardrails in the Guardrail Monitor 2026-07-10 16:49:30 -07:00