mastra-ai/mastra · error
Questions must be greater than 0
Error message
Questions must be greater than 0
What it means
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.
Source
Thrown at packages/rag/src/document/extractors/questions.ts:35
/**
* Extract questions from a list of nodes.
*/
export class QuestionsAnsweredExtractor extends BaseExtractor {
llm: MastraLanguageModel | MastraLegacyLanguageModel;
questions: number = 5;
promptTemplate: QuestionExtractPrompt;
embeddingOnly: boolean = false;
/**
* Constructor for the QuestionsAnsweredExtractor class.
* @param {MastraLanguageModel} llm MastraLanguageModel instance.
* @param {number} questions Number of questions to generate.
* @param {QuestionExtractPrompt['template']} promptTemplate Optional custom prompt template (should include {context}).
* @param {boolean} embeddingOnly Whether to use metadata for embeddings only.
*/
constructor(options?: QuestionAnswerExtractArgs) {
if (options?.questions && options.questions < 1) throw new Error('Questions must be greater than 0');
super();
this.llm = options?.llm ?? baseLLM;
this.questions = options?.questions ?? 5;
this.promptTemplate = options?.promptTemplate
? new PromptTemplate({
templateVars: ['numQuestions', 'context'],
template: options.promptTemplate,
}).partialFormat({
numQuestions: '5',
})
: defaultQuestionExtractPrompt;
this.embeddingOnly = options?.embeddingOnly ?? false;
}
/**
* Extract answered questions from a node.View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
new QuestionAnswerExtractor({ questions: config.questionCount }); // questionCount = 0
// after
new QuestionAnswerExtractor({ questions: Math.max(1, config.questionCount) }); Defensive patterns
Strategy: validation
Validate before calling
const questions = config.questionCount ?? 5;
if (!Number.isInteger(questions) || questions < 1) throw new RangeError(`questions must be >= 1, got ${questions}`);
const extractor = new QuestionAnswerExtractor({ questions }); Try / catch
try {
new QuestionAnswerExtractor({ questions });
} catch (e) {
if (e instanceof Error && e.message === 'Questions must be greater than 0') {
extractor = new QuestionAnswerExtractor({ questions: 5 });
} else throw e;
} Prevention
- 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.
When it happens
Trigger: new QuestionAnswerExtractor({ questions: 0 }) or any negative number, e.g. { questions: -3 }.
Common situations: 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.
Understand the failure class
Background: "Invalid configuration value" and "Unsupported/Unknown setting value" errors: why libraries reject your config strings, numbers, and types — this error's family across 30 libraries.
Related errors
- HTML chunking requires either headers or sections to be spec
- JSON chunking requires maxSize to be specified
- Sentence chunking requires maxSize to be specified
- Keywords must be greater than 0
- Summaries must be one of 'self', 'prev', 'next'
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/d18576785f944f39.
Report an issue: GitHub.