ComposioHQ/composio · error · Error
Invalid ${keyword} regular expression ${JSON.stringify(patte
Error message
Invalid ${keyword} regular expression ${JSON.stringify(pattern)}. What it means
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.
Source
Thrown at ts/packages/json-schema-to-effect-schema/src/index.ts:227
} else if (schemaArrayKeywords.has(key) && Array.isArray(child)) {
for (const nested of child) {
forEachSchemaNode(nested, seen, visit);
}
} else if (schemaValueKeywords.has(key)) {
for (const nested of Array.isArray(child) ? child : [child]) {
forEachSchemaNode(nested, seen, visit);
}
}
}
};
const assertRegexCompiles = (pattern: string, keyword: string): void => {
try {
// The same flag `@cfworker/json-schema` compiles with, so this accepts
// exactly the patterns the interpreter would.
new RegExp(pattern, 'u');
} catch (cause) {
throw new Error(`Invalid ${keyword} regular expression ${JSON.stringify(pattern)}.`, { cause });
}
};
// Follows every reference reachable from one dynamic-key subschema, including
// through the schemas those references resolve to, so a local pointer whose
// target carries a dangling reference is caught as well.
const assertDynamicReferencesResolve = (
subSchema: unknown,
lookup: Record<string, unknown>,
seen: WeakSet<object>
): void => {
forEachSchemaNode(subSchema, seen, node => {
const ref = node.$ref;
if (typeof ref !== 'string') {
return;
}
const absolute = (node as { readonly __absolute_ref__?: string }).__absolute_ref__ ?? ref;View on GitHub (pinned to 64b1b85502)
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
Example fix
// before
{ "pattern": "^[a-z\-]+$" } // invalid escape under 'u'
// after
{ "pattern": "^[a-z-]+$" } Defensive patterns
Strategy: validation
Validate before calling
const regexOk = (p: string): boolean => { try { new RegExp(p, 'u'); return true; } catch { return false; } };
if (!regexOk(schema.pattern ?? '')) throw new Error(`Invalid pattern: ${schema.pattern}`); Type guard
function isValidUnicodeRegex(pattern: string): boolean { try { new RegExp(pattern, 'u'); return true; } catch { return false; } } Try / catch
try { convert(schema); } catch (e) { if (/regular expression/.test((e as Error).message)) { /* fix or drop the pattern, reconvert */ } throw e; } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- schema is unsatisfiable (JSON Schema `false`)
- {error.message}
- Invalid patternProperties regular expression: {pattern!r}
- Unrecognized key(s) in object: {', '.join(repr(key) for key
- Tool schema nesting exceeded the maximum supported depth (${
AI-assisted analysis of ComposioHQ/composio@64b1b85502 (2026-08-28).
Data as JSON: /api/errors/4d418e7a04a602af.
Report an issue: GitHub.