{"record":{"id":"a8d0051f489234b9","repo":"mastra-ai/mastra","slug":"summaries-must-be-one-of-self-prev-next","errorCode":null,"errorMessage":"Summaries must be one of 'self', 'prev', 'next'","messagePattern":"Summaries must be one of 'self', 'prev', 'next'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/rag/src/document/extractors/summary.ts","lineNumber":35,"sourceCode":"/**\n * Summarize an array of nodes using a custom LLM.\n *\n * @param nodes Array of node-like objects\n * @param options Summary extraction options\n * @returns Array of summary results\n */\nexport class SummaryExtractor extends BaseExtractor {\n  private llm: MastraLanguageModel | MastraLegacyLanguageModel;\n  summaries: string[];\n  promptTemplate: SummaryPrompt;\n  private selfSummary: boolean;\n  private prevSummary: boolean;\n  private nextSummary: boolean;\n  constructor(options?: SummaryExtractArgs) {\n    const summaries = options?.summaries ?? ['self'];\n\n    if (summaries && !summaries.some(s => ['self', 'prev', 'next'].includes(s)))\n      throw new Error(\"Summaries must be one of 'self', 'prev', 'next'\");\n\n    super();\n\n    this.llm = options?.llm ?? baseLLM;\n    this.summaries = summaries;\n    this.promptTemplate = options?.promptTemplate\n      ? new PromptTemplate({\n          templateVars: ['context'],\n          template: options.promptTemplate,\n        })\n      : defaultSummaryPrompt;\n\n    this.selfSummary = summaries?.includes('self') ?? false;\n    this.prevSummary = summaries?.includes('prev') ?? false;\n    this.nextSummary = summaries?.includes('next') ?? false;\n  }\n\n  /**","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/rag/src/document/extractors/summary.ts#L17-L53","documentation":"The SummaryExtractor constructor validates the `summaries` option array: at least one entry must be one of 'self', 'prev', or 'next'. An empty array or an array containing only unknown values is rejected because the extractor would have nothing to summarize.","triggerScenarios":"new SummaryExtractor({ summaries: [] }) or new SummaryExtractor({ summaries: ['sibling'] }) — empty array or entries outside the allowed set.","commonSituations":"Typos in mode names ('Self', 'previous', 'curr'), empty config arrays read from JSON/YAML, or passing values copied from another library's summary extractor.","solutions":["Use only 'self', 'prev', and/or 'next' in the summaries array, e.g. { summaries: ['self', 'prev'] }.","Fix casing/typos — the values are case-sensitive lowercase strings.","Omit the option entirely to default to ['self']."],"exampleFix":"// before\nnew SummaryExtractor({ summaries: ['previous'] });\n// after\nnew SummaryExtractor({ summaries: ['prev', 'next'] });","handlingStrategy":"validation","validationCode":"const VALID = ['self', 'prev', 'next'] as const;\ntype SummaryMode = typeof VALID[number];\nconst summaries: SummaryMode[] = (config.summaries ?? ['self']).filter((s): s is SummaryMode => (VALID as readonly string[]).includes(s));\nif (summaries.length === 0) throw new Error('summaries must contain at least one of self|prev|next');","typeGuard":"const isSummaryMode = (s: unknown): s is 'self' | 'prev' | 'next' =>\n  s === 'self' || s === 'prev' || s === 'next';","tryCatchPattern":"try {\n  return new SummaryExtractor({ summaries });\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"Summaries must be one of\")) {\n    return new SummaryExtractor(); // defaults to ['self']\n  }\n  throw e;\n}","preventionTips":["Type the option as a union literal type so typos fail at compile time.","Never accept free strings from config without whitelist filtering.","Rely on the default ['self'] when unsure."],"tags":["configuration","validation","rag"],"backgroundTag":"invalid-configuration-value","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}