litellm/tests/test_litellm/proxy/policy_engine
ryan-crabbe-berri 23873f8447
fix(policies): reject non-existent team/key/model scope entries on attachment create (#32131)
* fix(policies): reject non-existent team/key/model scope entries on attachment create

Creating a policy attachment accepted arbitrary team, key, and model values with
no validation, so a typo'd or non-existent team was silently persisted (LIT-4199).
The create endpoint now rejects a concrete (non-wildcard) team, key, or model that
does not resolve to a real entity, wiring the previously-dead PolicyValidator
existence checks and reusing RouteChecks._is_wildcard_pattern so validation agrees
with request-time matching, where only a trailing "*" is a wildcard. Wildcard
patterns are still allowed through since they may match zero entities today and
more later, and tags stay free-form. The Admin UI's Teams field validates the same
rule for immediate feedback when its team list has loaded, deferring to the backend
otherwise.

* style(policies): use builtin list generics and | None in scope validator

Keeps the new find_invalid_scope_entries signature off the UP006/UP045 strict
ruff budgets instead of copying the surrounding legacy typing.List/Optional idiom.

* fix(policies): separate multiple attachment scope errors with ' | '

Addresses Greptile review: joining per-entry validation messages with a bare
space read as one run-on sentence; ' | ' makes the multi-error 400 detail easier
to parse for users and programmatically.
2026-07-04 11:58:29 -07:00
..
__init__.py [Feat] New LiteLLM Policy engine - create policies to manage guardrails, conditions - permissions per Key, Team (#19612) 2026-01-22 19:49:53 -08:00
test_attachment_registry.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_condition_evaluator.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_pipeline_executor.py fix(guardrails): match policy-pipeline block response to direct guardrail attachment (#31421) 2026-06-26 14:25:10 -07:00
test_policy_matcher.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_policy_resolver.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_policy_validator.py fix(policies): reject non-existent team/key/model scope entries on attachment create (#32131) 2026-07-04 11:58:29 -07:00
test_policy_versioning.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_policy_versioning_e2e.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00