Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

refactor(policy_engine): accept any sequence of policy names in condition matching

yucheng99e14efb62d9
diff --git a/litellm/proxy/policy_engine/policy_matcher.py b/litellm/proxy/policy_engine/policy_matcher.py
index 2f7fcd23b75..2b54b5dbe41 100644
--- a/litellm/proxy/policy_engine/policy_matcher.py
+++ b/litellm/proxy/policy_engine/policy_matcher.py
@@ -7,7 +7,7 @@ apply to a given request based on team alias, key alias, and model.
Policies are matched via policy_attachments which define WHERE each policy applies.
"""
-from collections.abc import Callable
+from collections.abc import Callable, Sequence
from typing import Final
from litellm._logging import verbose_proxy_logger
@@ -139,7 +139,7 @@ class PolicyMatcher:
"""Predicate telling whether a policy exists and its condition matches the context."""
return lambda policy_name: bool(
PolicyMatcher.get_policies_with_matching_conditions(
- policy_names=[policy_name], # mutable-ok: the matcher takes a list
+ policy_names=(policy_name,),
context=context,
policies=policies,
)
@@ -147,7 +147,7 @@ class PolicyMatcher:
@staticmethod
def get_policies_with_matching_conditions(
- policy_names: list[str],
+ policy_names: Sequence[str],
context: PolicyMatchContext,
policies: dict[str, Policy] | None = None,
) -> list[str]: