BerriAI/litellm · error · ValueError
Unknown pattern name: '{pattern_name}'. Available patterns:
Error message
Unknown pattern name: '{pattern_name}'. Available patterns: {available_patterns} What it means
get_compiled_pattern() resolves a masking rule's pattern by name against PREBUILT_PATTERNS, which is loaded from the patterns.json shipped with the guardrail (us_ssn, email, credit_card, github_token, generic_api_key, iban, sg_nric, ...). A name that is not a key in that file raises ValueError listing every valid name, so the fix is always visible in the message itself.
Source
Thrown at litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/patterns.py:73
PATTERN_EXTRA_CONFIG[pattern_data["name"]] = extra_config
def get_compiled_pattern(pattern_name: str) -> Pattern[str]:
"""
Get a compiled regex pattern by name.
Args:
pattern_name: Name of the prebuilt pattern
Returns:
Compiled regex pattern
Raises:
ValueError: If pattern_name is not found in PREBUILT_PATTERNS
"""
if pattern_name not in PREBUILT_PATTERNS:
available_patterns: Final = ", ".join(PREBUILT_PATTERNS.keys())
raise ValueError(f"Unknown pattern name: '{pattern_name}'. Available patterns: {available_patterns}")
return re.compile(PREBUILT_PATTERNS[pattern_name], re.IGNORECASE)
def get_all_pattern_names() -> list[str]:
"""
Get a list of all available prebuilt pattern names.
Returns:
List of pattern names
"""
return list(PREBUILT_PATTERNS.keys())
# Build category mapping from JSON
PATTERN_CATEGORIES: Final[dict[str, list[str]]] = {}
for pattern_data in _PATTERNS_DATA["patterns"]:
category = pattern_data["category"]View on GitHub (pinned to 77b7c6c40c)
Solutions
- Call get_all_pattern_names() (or read the error message) and use one of the listed names exactly
- Fix the typo in the rule, e.g. 'creditcard' to 'credit_card'
- If no prebuilt pattern fits, supply a custom regex in the masking rule instead of a name
- Verify the patterns.json of your installed LiteLLM version after upgrades and pin the version in deployments
Example fix
# before - unknown name, raises ValueError
rule = {"pattern": "creditcard", "action": "mask"}
# after - exact name from PREBUILT_PATTERNS
from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.patterns import get_all_pattern_names
assert "creditcard" in get_all_pattern_names() or True
rule = {"pattern": "credit_card", "action": "mask"} Defensive patterns
Strategy: validation
Validate before calling
from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.patterns import (
get_all_pattern_names,
get_compiled_pattern,
)
valid = set(get_all_pattern_names())
for rule in masking_rules:
if rule.get("prebuilt"):
assert rule["pattern"] in valid, f"unknown pattern {rule['pattern']!r}; valid: {sorted(valid)}"
get_compiled_pattern # only called after the assertion above Type guard
def is_valid_pattern_name(name: object) -> bool:
from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.patterns import get_all_pattern_names
return isinstance(name, str) and name in set(get_all_pattern_names()) Prevention
- Validate every pattern name against get_all_pattern_names() in a config lint step before deploying
- Pin the LiteLLM version so patterns.json cannot change under you between releases
- Prefer exact names copied from the error message or get_all_pattern_names() output over names from memory
When it happens
Trigger: Configuring the content filter guardrail with a pattern name that does not exist in the installed patterns.json: typos ('creditcard' vs 'credit_card'), names from other tools (Presidio detectors), or patterns renamed/removed after a LiteLLM upgrade.
Common situations: Hand-written guardrail YAML referencing pattern names from memory; upgrading LiteLLM where patterns.json changed between versions; configs copied from docs or other repos that drift from the installed version; region-specific names assumed to exist (e.g. 'uk_nino') that were never shipped.
Related errors
- bucket_name must be provided for GCS destination
- MAVVRIK_API_ENDPOINT must be an HTTPS URL
- MAVVRIK_API_ENDPOINT host must be a Mavvrik domain (e.g. htt
- MAVVRIK_API_KEY must be provided for Mavvrik FOCUS destinati
- MAVVRIK_API_ENDPOINT must be provided for Mavvrik FOCUS dest
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/adf8a3e919856265.
Report an issue: GitHub.