{"record":{"id":"4d418e7a04a602af","repo":"ComposioHQ/composio","slug":"invalid-keyword-regular-expression-json-strin","errorCode":null,"errorMessage":"Invalid ${keyword} regular expression ${JSON.stringify(pattern)}.","messagePattern":"Invalid (.+?) regular expression (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ts/packages/json-schema-to-effect-schema/src/index.ts","lineNumber":227,"sourceCode":"    } else if (schemaArrayKeywords.has(key) && Array.isArray(child)) {\n      for (const nested of child) {\n        forEachSchemaNode(nested, seen, visit);\n      }\n    } else if (schemaValueKeywords.has(key)) {\n      for (const nested of Array.isArray(child) ? child : [child]) {\n        forEachSchemaNode(nested, seen, visit);\n      }\n    }\n  }\n};\n\nconst assertRegexCompiles = (pattern: string, keyword: string): void => {\n  try {\n    // The same flag `@cfworker/json-schema` compiles with, so this accepts\n    // exactly the patterns the interpreter would.\n    new RegExp(pattern, 'u');\n  } catch (cause) {\n    throw new Error(`Invalid ${keyword} regular expression ${JSON.stringify(pattern)}.`, { cause });\n  }\n};\n\n// Follows every reference reachable from one dynamic-key subschema, including\n// through the schemas those references resolve to, so a local pointer whose\n// target carries a dangling reference is caught as well.\nconst assertDynamicReferencesResolve = (\n  subSchema: unknown,\n  lookup: Record<string, unknown>,\n  seen: WeakSet<object>\n): void => {\n  forEachSchemaNode(subSchema, seen, node => {\n    const ref = node.$ref;\n    if (typeof ref !== 'string') {\n      return;\n    }\n\n    const absolute = (node as { readonly __absolute_ref__?: string }).__absolute_ref__ ?? ref;","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/ts/packages/json-schema-to-effect-schema/src/index.ts#L209-L245","documentation":"In json-schema-to-effect-schema, assertRegexCompiles pre-checks every 'pattern'/'patternProperties' regex with new RegExp(pattern, 'u') using the same flags the runtime interpreter uses. If the regex does not compile (commonly invalid under the 'u' flag), it throws before conversion, so failures surface at build/convert time, not mid-execution.","triggerScenarios":"A JSON Schema passed to the converter containing a pattern or patternProperties regex that is invalid, or valid in non-unicode mode but invalid under the 'u' flag (e.g. unescaped '-', lone surrogates, invalid escapes like \\d inside character classes in old syntax, escaped \\- constructs).","commonSituations":"Regexes authored for Python/PCRE (e.g. '\\p{L}' without 'u' semantics handled, '\\-' escapes) pasted into tool schemas; OpenAPI-derived schemas with sloppy patterns; hand-written JSON Schema for tool parameters.","solutions":["Fix the regex to be valid ECMAScript unicode-mode (drop invalid escapes like '\\-', escape '-' in classes or place at edges)","Test with new RegExp(pattern, 'u') locally to validate before feeding the converter","Simplify overly clever regexes in tool schemas to portable subsets","If the pattern is informational, replace with a simpler equivalent or move validation into tool runtime code"],"exampleFix":"// before\n{ \"pattern\": \"^[a-z\\-]+$\" } // invalid escape under 'u'\n// after\n{ \"pattern\": \"^[a-z-]+$\" }","handlingStrategy":"validation","validationCode":"const regexOk = (p: string): boolean => { try { new RegExp(p, 'u'); return true; } catch { return false; } };\nif (!regexOk(schema.pattern ?? '')) throw new Error(`Invalid pattern: ${schema.pattern}`);","typeGuard":"function isValidUnicodeRegex(pattern: string): boolean { try { new RegExp(pattern, 'u'); return true; } catch { return false; } }","tryCatchPattern":"try { convert(schema); } catch (e) { if (/regular expression/.test((e as Error).message)) { /* fix or drop the pattern, reconvert */ } throw e; }","preventionTips":["Test every JSON Schema pattern with new RegExp(p, 'u') before conversion","Avoid PCRE-specific escapes (\\-, \\d inside odd contexts)","Keep tool-schema regexes in the portable ECMAScript subset"],"tags":["regex","json-schema","validation","unicode"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}