{"record":{"id":"8415b193e4fafca4","repo":"BerriAI/litellm","slug":"invalid-regex-for-tool-type-in-rule-rule-id","errorCode":null,"errorMessage":"Invalid regex for tool_type in rule '{rule.id}': {exc}","messagePattern":"Invalid regex for tool_type in rule '(.+?)': (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_hooks/tool_permission.py","lineNumber":109,"sourceCode":"        compiled_patterns: Final[dict[str, dict[str, re.Pattern]]] = {}\n\n        for rule_item in rules or []:\n            rule = rule_item if isinstance(rule_item, ToolPermissionRule) else ToolPermissionRule(**rule_item)\n\n            target_patterns: dict[str, re.Pattern | None] = {\n                \"tool_name\": None,\n                \"tool_type\": None,\n            }\n            if rule.tool_name is not None:\n                try:\n                    target_patterns[\"tool_name\"] = re.compile(rule.tool_name)\n                except re.error as exc:\n                    raise ValueError(f\"Invalid regex for tool_name in rule '{rule.id}': {exc}\") from exc\n            if rule.tool_type is not None:\n                try:\n                    target_patterns[\"tool_type\"] = re.compile(rule.tool_type)\n                except re.error as exc:\n                    raise ValueError(f\"Invalid regex for tool_type in rule '{rule.id}': {exc}\") from exc\n\n            rule_patterns: dict[str, re.Pattern] = {}\n            for path, pattern in (rule.allowed_param_patterns or {}).items():\n                try:\n                    rule_patterns[path] = re.compile(pattern)\n                except re.error as exc:\n                    raise ValueError(f\"Invalid regex in allowed_param_patterns for rule '{rule.id}': {exc}\") from exc\n\n            parsed_rules.append(rule)\n            compiled_targets[rule.id] = target_patterns\n            if rule_patterns:\n                compiled_patterns[rule.id] = rule_patterns\n\n        # Swap in the fully-built maps only after every rule compiles, so an\n        # invalid regex raises without leaving a partially-built ruleset (a\n        # missing compiled target is read as a match-all wildcard).\n        self.rules = parsed_rules\n        self._compiled_rule_targets = compiled_targets","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/tool_permission.py#L91-L127","documentation":"Error \"Invalid regex for tool_type in rule '{rule.id}': {exc}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/proxy/guardrails/guardrail_hooks/tool_permission.py:109 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the tool_type regular expression in the referenced rule.","Test the regex offline (e.g. with Python re) before adding it to the config."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}