ComposioHQ/composio · error · ValueError
Invalid patternProperties regular expression: {pattern!r}
Error message
Invalid patternProperties regular expression: {pattern!r} What it means
A patternProperties key in an object schema failed to compile as a Python regular expression (re.error), re-raised as ValueError by _compile_pattern_property. The regex is compiled eagerly while building the object policy, so the failure happens at model construction, not first use.
Source
Thrown at python/composio/utils/schema_converter.py:680
_validate_dynamic_key_schema(schema, root_schema, root_validator)
materializer = None
if _contains_default(schema):
annotation = json_schema_to_pydantic_type(schema, root_schema=root_schema)
_mark_explicit_default_fields(annotation, schema, root_schema)
materializer = TypeAdapter(annotation)
return _DynamicKeyValidator(
validator=root_validator.evolve(schema=schema),
materializer=materializer,
)
def _compile_pattern_property(pattern: str) -> t.Pattern[str]:
try:
return re.compile(pattern)
except re.error as exc:
raise ValueError(
f"Invalid patternProperties regular expression: {pattern!r}"
) from exc
def _validate_object_policy_schema(
schema: t.Dict[str, t.Any],
root_schema: t.Dict[str, t.Any],
) -> None:
"""Validate a dynamic object policy without materializing defaults."""
validator_type = jsonschema_validators.validator_for(
root_schema,
default=jsonschema_validators.Draft7Validator,
)
root_validator = validator_type(root_schema)
for pattern, pattern_schema in (schema.get("patternProperties") or {}).items():
_compile_pattern_property(pattern)
_validate_dynamic_key_schema(View on GitHub (pinned to 64b1b85502)
Solutions
- Test the pattern with `re.compile(pattern)` locally to reproduce, then fix the regex
- Remove JS-style delimiters/flags (no leading/trailing /, no trailing i or g)
- Fix escaping: in JSON the pattern should be "^\\d+$" to mean ^\d+$ in regex
- Simplify the pattern to constructs supported by Python's re module
Example fix
# before
"patternProperties": {"/^\w+$/": {"type": "string"}}
# after
"patternProperties": {"^\w+$": {"type": "string"}} Defensive patterns
Strategy: validation
Validate before calling
import re
def patterns_compile(schema):
if isinstance(schema, dict):
for pat in (schema.get("patternProperties") or {}):
try: re.compile(pat)
except re.error: return False
return all(patterns_compile(v) for v in schema.values())
if isinstance(schema, list):
return all(patterns_compile(i) for i in schema)
return True
assert patterns_compile(schema) Try / catch
try:
build_model(schema)
except ValueError as e:
if "patternProperties" in str(e):
schema["patternProperties"] = fix_regex_dialect(schema["patternProperties"]) Prevention
- Test every pattern with re.compile before shipping the schema
- Avoid JS-only regex constructs and delimiters when authoring patterns
- Double-check escaping levels when patterns pass through JSON/YAML
When it happens
Trigger: A schema contains "patternProperties": {"^([a-z+": invalid regex — unbalanced parens/brackets, stray backslash, or constructs valid in ECMA/PCRE but invalid in Python's re. Also raw regexes not escaped when embedded in YAML/JSON strings.
Common situations: Porting schemas written for JavaScript validators (different regex dialect); double-escaping bugs where a pattern arrives as `\\d` instead of `\d` (or vice versa); truncation during templating; copy-paste from regex testers that include delimiters like /.../ flags.
Related errors
- Invalid ${keyword} regular expression ${JSON.stringify(patte
- Cannot resolve $ref {pointer}
- JSON Schema node depth exceeded cap ({MAX_NODE_DEPTH})
- JSON Schema $ref chain exceeded depth cap ({MAX_REF_CHAIN_DE
- JSON Schema nesting too deep to dereference
AI-assisted analysis of ComposioHQ/composio@64b1b85502 (2026-08-28).
Data as JSON: /api/errors/762e79cd1adf8552.
Report an issue: GitHub.