{"record":{"id":"d18576785f944f39","repo":"mastra-ai/mastra","slug":"questions-must-be-greater-than-0","errorCode":null,"errorMessage":"Questions must be greater than 0","messagePattern":"Questions must be greater than 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/rag/src/document/extractors/questions.ts","lineNumber":35,"sourceCode":"\n/**\n * Extract questions from a list of nodes.\n */\nexport class QuestionsAnsweredExtractor extends BaseExtractor {\n  llm: MastraLanguageModel | MastraLegacyLanguageModel;\n  questions: number = 5;\n  promptTemplate: QuestionExtractPrompt;\n  embeddingOnly: boolean = false;\n\n  /**\n   * Constructor for the QuestionsAnsweredExtractor class.\n   * @param {MastraLanguageModel} llm MastraLanguageModel instance.\n   * @param {number} questions Number of questions to generate.\n   * @param {QuestionExtractPrompt['template']} promptTemplate Optional custom prompt template (should include {context}).\n   * @param {boolean} embeddingOnly Whether to use metadata for embeddings only.\n   */\n  constructor(options?: QuestionAnswerExtractArgs) {\n    if (options?.questions && options.questions < 1) throw new Error('Questions must be greater than 0');\n\n    super();\n\n    this.llm = options?.llm ?? baseLLM;\n    this.questions = options?.questions ?? 5;\n    this.promptTemplate = options?.promptTemplate\n      ? new PromptTemplate({\n          templateVars: ['numQuestions', 'context'],\n          template: options.promptTemplate,\n        }).partialFormat({\n          numQuestions: '5',\n        })\n      : defaultQuestionExtractPrompt;\n    this.embeddingOnly = options?.embeddingOnly ?? false;\n  }\n\n  /**\n   * Extract answered questions from a node.","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/rag/src/document/extractors/questions.ts#L17-L53","documentation":"The QuestionAnswerExtractor constructor validates the `questions` option: if provided and less than 1, it throws immediately instead of proceeding with an invalid count of questions to generate per chunk. The default is 5 when omitted.","triggerScenarios":"new QuestionAnswerExtractor({ questions: 0 }) or any negative number, e.g. { questions: -3 }.","commonSituations":"Computing the question count from config (e.g. Math.floor of a ratio that rounds to 0), parsing user input from CLI/env, or off-by-one loops that end at 0.","solutions":["Pass a positive integer for `questions`, e.g. new QuestionAnswerExtractor({ questions: 5 }).","If the value is computed, clamp it: Math.max(1, computedCount).","If you don't need a specific count, omit `questions` to use the default of 5."],"exampleFix":"// before\nnew QuestionAnswerExtractor({ questions: config.questionCount }); // questionCount = 0\n// after\nnew QuestionAnswerExtractor({ questions: Math.max(1, config.questionCount) });","handlingStrategy":"validation","validationCode":"const questions = config.questionCount ?? 5;\nif (!Number.isInteger(questions) || questions < 1) throw new RangeError(`questions must be >= 1, got ${questions}`);\nconst extractor = new QuestionAnswerExtractor({ questions });","typeGuard":null,"tryCatchPattern":"try {\n  new QuestionAnswerExtractor({ questions });\n} catch (e) {\n  if (e instanceof Error && e.message === 'Questions must be greater than 0') {\n    extractor = new QuestionAnswerExtractor({ questions: 5 });\n  } else throw e;\n}","preventionTips":["Clamp computed counts with Math.max(1, n).","Centralize extractor option parsing and validate before construction.","Add a unit test for zero/negative question counts."],"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"}