BerriAI/litellm · error · ValueError

Invalid regex for tool_type in rule '{rule.id}': {exc}

Error message

Invalid regex for tool_type in rule '{rule.id}': {exc}

What it means

Error "Invalid regex for tool_type in rule '{rule.id}': {exc}" thrown in BerriAI/litellm.

Source

Thrown at litellm/proxy/guardrails/guardrail_hooks/tool_permission.py:109

        compiled_patterns: Final[dict[str, dict[str, re.Pattern]]] = {}

        for rule_item in rules or []:
            rule = rule_item if isinstance(rule_item, ToolPermissionRule) else ToolPermissionRule(**rule_item)

            target_patterns: dict[str, re.Pattern | None] = {
                "tool_name": None,
                "tool_type": None,
            }
            if rule.tool_name is not None:
                try:
                    target_patterns["tool_name"] = re.compile(rule.tool_name)
                except re.error as exc:
                    raise ValueError(f"Invalid regex for tool_name in rule '{rule.id}': {exc}") from exc
            if rule.tool_type is not None:
                try:
                    target_patterns["tool_type"] = re.compile(rule.tool_type)
                except re.error as exc:
                    raise ValueError(f"Invalid regex for tool_type in rule '{rule.id}': {exc}") from exc

            rule_patterns: dict[str, re.Pattern] = {}
            for path, pattern in (rule.allowed_param_patterns or {}).items():
                try:
                    rule_patterns[path] = re.compile(pattern)
                except re.error as exc:
                    raise ValueError(f"Invalid regex in allowed_param_patterns for rule '{rule.id}': {exc}") from exc

            parsed_rules.append(rule)
            compiled_targets[rule.id] = target_patterns
            if rule_patterns:
                compiled_patterns[rule.id] = rule_patterns

        # Swap in the fully-built maps only after every rule compiles, so an
        # invalid regex raises without leaving a partially-built ruleset (a
        # missing compiled target is read as a match-all wildcard).
        self.rules = parsed_rules
        self._compiled_rule_targets = compiled_targets

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Fix the tool_type regular expression in the referenced rule.
  2. Test the regex offline (e.g. with Python re) before adding it to the config.

When it happens

Trigger: Thrown at litellm/proxy/guardrails/guardrail_hooks/tool_permission.py:109 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/8415b193e4fafca4. Report an issue: GitHub.