{"record":{"id":"762e79cd1adf8552","repo":"ComposioHQ/composio","slug":"invalid-patternproperties-regular-expression-pat","errorCode":null,"errorMessage":"Invalid patternProperties regular expression: {pattern!r}","messagePattern":"Invalid patternProperties regular expression: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/composio/utils/schema_converter.py","lineNumber":680,"sourceCode":"    _validate_dynamic_key_schema(schema, root_schema, root_validator)\n\n    materializer = None\n    if _contains_default(schema):\n        annotation = json_schema_to_pydantic_type(schema, root_schema=root_schema)\n        _mark_explicit_default_fields(annotation, schema, root_schema)\n        materializer = TypeAdapter(annotation)\n\n    return _DynamicKeyValidator(\n        validator=root_validator.evolve(schema=schema),\n        materializer=materializer,\n    )\n\n\ndef _compile_pattern_property(pattern: str) -> t.Pattern[str]:\n    try:\n        return re.compile(pattern)\n    except re.error as exc:\n        raise ValueError(\n            f\"Invalid patternProperties regular expression: {pattern!r}\"\n        ) from exc\n\n\ndef _validate_object_policy_schema(\n    schema: t.Dict[str, t.Any],\n    root_schema: t.Dict[str, t.Any],\n) -> None:\n    \"\"\"Validate a dynamic object policy without materializing defaults.\"\"\"\n    validator_type = jsonschema_validators.validator_for(\n        root_schema,\n        default=jsonschema_validators.Draft7Validator,\n    )\n    root_validator = validator_type(root_schema)\n\n    for pattern, pattern_schema in (schema.get(\"patternProperties\") or {}).items():\n        _compile_pattern_property(pattern)\n        _validate_dynamic_key_schema(","sourceCodeStart":662,"sourceCodeEnd":698,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/python/composio/utils/schema_converter.py#L662-L698","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\n\"patternProperties\": {\"/^\\w+$/\": {\"type\": \"string\"}}\n# after\n\"patternProperties\": {\"^\\w+$\": {\"type\": \"string\"}}","handlingStrategy":"validation","validationCode":"import re\ndef patterns_compile(schema):\n    if isinstance(schema, dict):\n        for pat in (schema.get(\"patternProperties\") or {}):\n            try: re.compile(pat)\n            except re.error: return False\n        return all(patterns_compile(v) for v in schema.values())\n    if isinstance(schema, list):\n        return all(patterns_compile(i) for i in schema)\n    return True\nassert patterns_compile(schema)","typeGuard":null,"tryCatchPattern":"try:\n    build_model(schema)\nexcept ValueError as e:\n    if \"patternProperties\" in str(e):\n        schema[\"patternProperties\"] = fix_regex_dialect(schema[\"patternProperties\"])","preventionTips":["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"],"tags":["json-schema","regex","pattern-properties","python-re"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}