{"record":{"id":"411d28cc23ffc073","repo":"mastra-ai/mastra","slug":"maxquestions-must-be-at-least-1-for-summarization","errorCode":null,"errorMessage":"maxQuestions must be at least 1 for Summarization scoring","messagePattern":"maxQuestions must be at least 1 for Summarization scoring","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/evals/src/scorers/llm/summarization/index.ts","lineNumber":194,"sourceCode":" * @example\n * ```ts\n * const scorer = createSummarizationScorer({\n *   model: 'openai/gpt-5.5',\n *   options: { maxQuestions: 10 },\n * });\n *\n * const result = await scorer.run(run);\n * ```\n */\nexport function createSummarizationScorer({\n  model,\n  options = {},\n}: {\n  model: MastraModelConfig;\n  options?: SummarizationMetricOptions;\n}) {\n  if (options.maxQuestions !== undefined && options.maxQuestions < 1) {\n    throw new Error('maxQuestions must be at least 1 for Summarization scoring');\n  }\n\n  const maxQuestions = options.maxQuestions ?? DEFAULT_MAX_QUESTIONS;\n\n  return createScorer<ScorerRunInputForLLMJudge, ScorerRunOutputForLLMJudge>({\n    id: 'summarization-scorer',\n    name: 'Summarization Scorer',\n    description:\n      'A scorer that evaluates whether a summary stays faithful to its source text and preserves the information the source states',\n    judge: {\n      model,\n      instructions: SUMMARIZATION_AGENT_INSTRUCTIONS,\n    },\n    type: 'agent',\n  })\n    .preprocess({\n      description: 'Judge each summary claim against the source and draw coverage questions from it',\n      outputSchema: sourceJudgementOutputSchema,","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/evals/src/scorers/llm/summarization/index.ts#L176-L212","documentation":"The summarization scorer generates questions from a summary to verify it is faithful; maxQuestions controls how many are generated. A value below 1 (0 or negative) makes question generation impossible, so createSummarizationScorer throws at construction time. Only an explicitly provided options.maxQuestions is validated; omitted values fall back to DEFAULT_MAX_QUESTIONS.","triggerScenarios":"Calling createSummarizationScorer({ model, options: { maxQuestions: 0 } }) or with any negative number, e.g. maxQuestions: -1, or a maxQuestions computed from an expression that evaluates to <= 0.","commonSituations":"Loading maxQuestions from config/env where the default is 0; computing maxQuestions from a ratio of summary length that floors to 0; a user entering 0 in a UI thinking it means 'unlimited'.","solutions":["Set options.maxQuestions to a positive integer, e.g. maxQuestions: 5.","Remove the maxQuestions option entirely to use the library default.","Clamp before passing: Math.max(1, configuredMaxQuestions || DEFAULT)."],"exampleFix":"// before\nconst scorer = createSummarizationScorer({ model, options: { maxQuestions: 0 } });\n// after\nconst scorer = createSummarizationScorer({ model, options: { maxQuestions: 5 } });","handlingStrategy":"validation","validationCode":"const DEFAULT_MAX_QUESTIONS = 5;\nconst maxQuestions = options.maxQuestions ?? DEFAULT_MAX_QUESTIONS;\nif (!Number.isInteger(maxQuestions) || maxQuestions < 1) {\n  throw new RangeError(`maxQuestions must be a positive integer, got ${maxQuestions}`);\n}","typeGuard":"const isValidMaxQuestions = (n: unknown): n is number => typeof n === 'number' && Number.isInteger(n) && n >= 1;","tryCatchPattern":"try {\n  const scorer = createSummarizationScorer({ model, options });\n} catch (err) {\n  if (err instanceof Error && err.message.includes('maxQuestions must be at least 1')) {\n    options = { ...options, maxQuestions: 5 }; // retry with default\n  } else throw err;\n}","preventionTips":["Clamp user/config-provided values with Math.max(1, value) before constructing the scorer.","Never use 0 to mean 'default'; omit the option instead.","Validate env/config numbers at startup with a schema (e.g. zod .int().min(1))."],"tags":["validation","range-check","scorer","configuration"],"backgroundTag":"invalid-parameter-value","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}