{"record":{"id":"adf8a3e919856265","repo":"BerriAI/litellm","slug":"unknown-pattern-name-pattern-name-available","errorCode":null,"errorMessage":"Unknown pattern name: '{pattern_name}'. Available patterns: {available_patterns}","messagePattern":"Unknown pattern name: '(.+?)'\\. Available patterns: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/patterns.py","lineNumber":73,"sourceCode":"    PATTERN_EXTRA_CONFIG[pattern_data[\"name\"]] = extra_config\n\n\ndef get_compiled_pattern(pattern_name: str) -> Pattern[str]:\n    \"\"\"\n    Get a compiled regex pattern by name.\n\n    Args:\n        pattern_name: Name of the prebuilt pattern\n\n    Returns:\n        Compiled regex pattern\n\n    Raises:\n        ValueError: If pattern_name is not found in PREBUILT_PATTERNS\n    \"\"\"\n    if pattern_name not in PREBUILT_PATTERNS:\n        available_patterns: Final = \", \".join(PREBUILT_PATTERNS.keys())\n        raise ValueError(f\"Unknown pattern name: '{pattern_name}'. Available patterns: {available_patterns}\")\n\n    return re.compile(PREBUILT_PATTERNS[pattern_name], re.IGNORECASE)\n\n\ndef get_all_pattern_names() -> list[str]:\n    \"\"\"\n    Get a list of all available prebuilt pattern names.\n\n    Returns:\n        List of pattern names\n    \"\"\"\n    return list(PREBUILT_PATTERNS.keys())\n\n\n# Build category mapping from JSON\nPATTERN_CATEGORIES: Final[dict[str, list[str]]] = {}\nfor pattern_data in _PATTERNS_DATA[\"patterns\"]:\n    category = pattern_data[\"category\"]","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/patterns.py#L55-L91","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before - unknown name, raises ValueError\nrule = {\"pattern\": \"creditcard\", \"action\": \"mask\"}\n\n# after - exact name from PREBUILT_PATTERNS\nfrom litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.patterns import get_all_pattern_names\nassert \"creditcard\" in get_all_pattern_names() or True\nrule = {\"pattern\": \"credit_card\", \"action\": \"mask\"}","handlingStrategy":"validation","validationCode":"from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.patterns import (  \n    get_all_pattern_names,  \n    get_compiled_pattern,  \n)  \n  \nvalid = set(get_all_pattern_names())  \nfor rule in masking_rules:  \n    if rule.get(\"prebuilt\"):  \n        assert rule[\"pattern\"] in valid, f\"unknown pattern {rule['pattern']!r}; valid: {sorted(valid)}\"  \nget_compiled_pattern  # only called after the assertion above","typeGuard":"def is_valid_pattern_name(name: object) -> bool:  \n    from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.patterns import get_all_pattern_names  \n    return isinstance(name, str) and name in set(get_all_pattern_names())","tryCatchPattern":null,"preventionTips":["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"],"tags":["content-filter","regex-pattern","config","validation"],"backgroundTag":"invalid-pattern-name","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}