{"record":{"id":"6fccf9d36600ad2c","repo":"vercel/ai","slug":"chunking-must-be-word-line-a-regexp-an-intl","errorCode":null,"errorMessage":"Chunking must be \"word\", \"line\", a RegExp, an Intl.Segmenter, or a ChunkDetector function. Received: ${chunking}","messagePattern":"Chunking must be \"word\", \"line\", a RegExp, an Intl\\.Segmenter, or a ChunkDetector function\\. Received: (.+?)","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-text/smooth-stream.ts","lineNumber":91,"sourceCode":"\n      if (!buffer.startsWith(match)) {\n        throw new Error(\n          `Chunking function must return a match that is a prefix of the buffer. Received: \"${match}\" expected to start with \"${buffer}\"`,\n        );\n      }\n\n      return match;\n    };\n  } else {\n    const chunkingRegex =\n      typeof chunking === 'string'\n        ? CHUNKING_REGEXPS[chunking]\n        : chunking instanceof RegExp\n          ? chunking\n          : undefined;\n\n    if (chunkingRegex == null) {\n      throw new InvalidArgumentError({\n        argument: 'chunking',\n        message: `Chunking must be \"word\", \"line\", a RegExp, an Intl.Segmenter, or a ChunkDetector function. Received: ${chunking}`,\n      });\n    }\n\n    detectChunk = buffer => {\n      const lastIndex = chunkingRegex.lastIndex;\n      chunkingRegex.lastIndex = 0;\n\n      let match: RegExpExecArray | null;\n      try {\n        match = chunkingRegex.exec(buffer);\n      } finally {\n        chunkingRegex.lastIndex = lastIndex;\n      }\n\n      if (!match) {\n        return null;","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-text/smooth-stream.ts#L73-L109","documentation":"InvalidArgumentError thrown by smoothStream when the `chunking` option is none of the supported types: 'word', 'line', a RegExp, an Intl.Segmenter, or a ChunkDetector function. The value is validated up front so bad configuration fails fast instead of mid-stream.","triggerScenarios":"Passing chunking: 'words' (plural typo), 'sentence', a string like 'word ' with whitespace, a number, an object, or null/undefined where a detector was intended.","commonSituations":"Typos in the preset name; copying code from an older AI SDK version where different presets existed; passing a regex-like string instead of a RegExp literal; forgetting the option is typed but validated at runtime.","solutions":["Use exactly 'word' or 'line', or pass a RegExp like /(?<=\\s)/, an Intl.Segmenter, or a function.","Fix typos such as 'words' -> 'word' and 'lines' -> 'line'.","Convert regex strings to real RegExp objects before passing them."],"exampleFix":"// before\nsmoothStream({ chunking: 'words' });\n// after\nsmoothStream({ chunking: 'word' });","handlingStrategy":"validation","validationCode":"const ALLOWED = ['word', 'line'];\nconst ok =\n  (typeof chunking === 'string' && ALLOWED.includes(chunking)) ||\n  chunking instanceof RegExp ||\n  chunking instanceof Intl.Segmenter ||\n  typeof chunking === 'function';\nif (!ok) throw new Error(`unsupported chunking: ${String(chunking)}`);","typeGuard":"function isChunking(v: unknown): v is 'word' | 'line' | RegExp | Intl.Segmenter | ChunkDetector {\n  return v === 'word' || v === 'line' || v instanceof RegExp ||\n    v instanceof Intl.Segmenter || typeof v === 'function';\n}","tryCatchPattern":null,"preventionTips":["Use the exported smoothStream with literal presets 'word'/'line' only.","Convert regex strings with new RegExp(str) before passing.","Type the option as Chunking to get compile-time errors on typos."],"tags":["streaming","smooth-stream","invalid-argument","configuration"],"backgroundTag":"invalid-argument-value","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}