{"record":{"id":"1cee2e0884dbd85f","repo":"vercel/ai","slug":"could-not-convert-regex-pattern-at-refs-currentp","errorCode":null,"errorMessage":"Could not convert regex pattern at ${refs.currentPath.join('/')} to a flag-independent form! Falling back to the flag-ignorant source","messagePattern":"Could not convert regex pattern at (.+?) to a flag-independent form! Falling back to the flag-ignorant source","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/provider-utils/src/to-json-schema/zod3-to-json-schema/parsers/string.ts","lineNumber":417,"sourceCode":"    if (flags.s && source[i] === '.') {\n      pattern += inCharGroup ? `${source[i]}\\r\\n` : `[${source[i]}\\r\\n]`;\n      continue;\n    }\n\n    pattern += source[i];\n    if (source[i] === '\\\\') {\n      isEscaped = true;\n    } else if (inCharGroup && source[i] === ']') {\n      inCharGroup = false;\n    } else if (!inCharGroup && source[i] === '[') {\n      inCharGroup = true;\n    }\n  }\n\n  try {\n    new RegExp(pattern);\n  } catch {\n    console.warn(\n      `Could not convert regex pattern at ${refs.currentPath.join(\n        '/',\n      )} to a flag-independent form! Falling back to the flag-ignorant source`,\n    );\n    return regex.source;\n  }\n\n  return pattern;\n}\n","sourceCodeStart":399,"sourceCodeEnd":427,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/provider-utils/src/to-json-schema/zod3-to-json-schema/parsers/string.ts#L399-L427","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nz.string().regex(/^[a-z]+$/i)\n// after\nz.string().regex(/^[a-zA-Z]+$/) // flag-independent, converts cleanly","handlingStrategy":"validation","validationCode":"// ensure regexes convert flag-independently before use\nschema._def.checks?.forEach(c => {\n  if (c.kind === 'regex' && (c.regex.flags)) console.warn('flagged regex in schema', c.regex);\n});","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["regex","json-schema","zod","schema-conversion"],"backgroundTag":"regex-flag-conversion-failed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}