vercel/ai · warning
Could not convert regex pattern at ${refs.currentPath.join('
Error message
Could not convert regex pattern at ${refs.currentPath.join('/')} to a flag-independent form! Falling back to the flag-ignorant source What it means
When converting a zod string regex check into a JSON Schema pattern, the converter tries to strip flags (like 'i' or 'm') into an inline flag-independent form. If the rewritten regex is not valid, it warns and falls back to the raw source, meaning flags are silently dropped in the JSON Schema pattern.
Source
Thrown at packages/provider-utils/src/to-json-schema/zod3-to-json-schema/parsers/string.ts:417
if (flags.s && source[i] === '.') {
pattern += inCharGroup ? `${source[i]}\r\n` : `[${source[i]}\r\n]`;
continue;
}
pattern += source[i];
if (source[i] === '\\') {
isEscaped = true;
} else if (inCharGroup && source[i] === ']') {
inCharGroup = false;
} else if (!inCharGroup && source[i] === '[') {
inCharGroup = true;
}
}
try {
new RegExp(pattern);
} catch {
console.warn(
`Could not convert regex pattern at ${refs.currentPath.join(
'/',
)} to a flag-independent form! Falling back to the flag-ignorant source`,
);
return regex.source;
}
return pattern;
}
View on GitHub (pinned to 69428b1f8b)
Solutions
- Rewrite the regex to be flag-independent (e.g. embed (?i) semantics manually, or use (?s)/(?m) style constructs supported by the target).
- Handle case-insensitivity outside the schema (e.g. normalize input with toLowerCase before validation) and use a flagless regex.
- Accept the fallback and apply the flag semantics at the application level after schema validation.
- Check the produced JSON Schema and manually patch the 'pattern' property with the correct flag-aware form.
Example fix
// before z.string().regex(/^[a-z]+$/i) // after z.string().regex(/^[a-zA-Z]+$/) // flag-independent, converts cleanly
Defensive patterns
Strategy: validation
Validate before calling
// ensure regexes convert flag-independently before use
schema._def.checks?.forEach(c => {
if (c.kind === 'regex' && (c.regex.flags)) console.warn('flagged regex in schema', c.regex);
}); Prevention
- Use flagless regexes in zod string checks when the schema will be converted
- Unit-test converted JSON Schema patterns against expected inputs
- Bake case-insensitivity into character classes instead of the 'i' flag
When it happens
Trigger: zodToJsonSchema conversion of a schema containing z.string().regex(...) where the regex uses flags that cannot be represented flag-independently, and the synthesized pattern fails `new RegExp(pattern)` validation.
Common situations: Case-insensitive or multiline regex checks in zod schemas being converted for generateObject/tool schemas; complex regexes with character classes or quantifiers that break the flag-inlining rewrite.
Related errors
- Recursive reference detected at ${refs.currentPath.join('/')
- Google schema conversion does not support recursive JSON Sch
- Google schema conversion only supports references to direct
- Google does not support this JSON Schema enum. Enum values m
- No object generated: response did not match schema.
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/1cee2e0884dbd85f.
Report an issue: GitHub.