{"record":{"id":"d19f156b710b817d","repo":"mastra-ai/mastra","slug":"either-context-or-contextextractor-is-required-for-d19f15","errorCode":null,"errorMessage":"Either context or contextExtractor is required for Context Recall scoring","messagePattern":"Either context or contextExtractor is required for Context Recall scoring","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/evals/src/scorers/llm/context-recall/index.ts","lineNumber":62,"sourceCode":"  output: ScorerRunOutputForLLMJudge;\n  options: ContextRecallMetricOptions;\n}) => {\n  if (options.contextExtractor && isScorerRunInputForAgent(input) && isScorerRunOutputForAgent(output)) {\n    return options.contextExtractor(input, output);\n  }\n\n  return options.context ?? [];\n};\n\nexport function createContextRecallScorer({\n  model,\n  options,\n}: {\n  model: MastraModelConfig;\n  options: ContextRecallMetricOptions;\n}) {\n  if (!options.context && !options.contextExtractor) {\n    throw new Error('Either context or contextExtractor is required for Context Recall scoring');\n  }\n  if (options.context && options.context.length === 0) {\n    throw new Error('Context array cannot be empty if provided');\n  }\n\n  return createScorer<ScorerRunInputForLLMJudge, ScorerRunOutputForLLMJudge>({\n    id: 'context-recall-scorer',\n    name: 'Context Recall Scorer',\n    description:\n      'A scorer that evaluates how well retrieved context covers the claims in a ground-truth reference answer',\n    judge: {\n      model,\n      instructions: CONTEXT_RECALL_AGENT_INSTRUCTIONS,\n    },\n    type: 'agent',\n  })\n    .preprocess({\n      description: 'Extract atomic claims from the ground-truth answer',","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/evals/src/scorers/llm/context-recall/index.ts#L44-L80","documentation":"createContextRecallScorer mirrors context precision: it requires context to judge how much of it the output covers, supplied via a static options.context array or a per-run options.contextExtractor. With neither, the scorer has no context to attribute statements against, so the factory throws at construction time (packages/evals/src/scorers/llm/context-recall/index.ts:62).","triggerScenarios":"Calling createContextRecallScorer({ model, options: {} }) or with options lacking both context and contextExtractor; options objects reused from metrics that do not require context (e.g. answer-relevance options).","commonSituations":"Swapping an answer-relevance scorer for context recall and reusing the old options; config-driven scorer setup where the context key was never wired; examples copied without the context field.","solutions":["Pass the retrieved documents: options.context: ['chunk 1', 'chunk 2', ...]","Or pass options.contextExtractor: ({ run }) => string[] to derive context per run","Double-check the options key spelling (context / contextExtractor) and that the object is passed under options","Confirm this is the metric you want; if scoring output quality without context, use a different scorer"],"exampleFix":"// before\nconst scorer = createContextRecallScorer({ model, options: { scale: 1 } });\n\n// after\nconst scorer = createContextRecallScorer({\n  model,\n  options: { scale: 1, context: groundTruthContext },\n});","handlingStrategy":"validation","validationCode":"function validateContextRecallOptions(o: ContextRecallMetricOptions): void {\n  if (!o.context && !o.contextExtractor) {\n    throw new Error('Context Recall needs options.context or options.contextExtractor');\n  }\n}\nvalidateContextRecallOptions(options);","typeGuard":"function hasRecallContextSource(o: ContextRecallMetricOptions): o is ContextRecallMetricOptions & ({ context: string[] } | { contextExtractor: (...a: unknown[]) => string[] }) {\n  return Boolean(o.context) || Boolean(o.contextExtractor);\n}","tryCatchPattern":"try {\n  const scorer = createContextRecallScorer({ model, options });\n} catch (err) {\n  if ((err as Error).message.includes('context or contextExtractor is required')) {\n    throw new ConfigError('Wire context or contextExtractor into Context Recall options');\n  }\n  throw err;\n}","preventionTips":["Supply the ground-truth/retrieved context when constructing the scorer","Do not reuse options objects from metrics that do not require context","Validate scorer options at config load time","Use contextExtractor for per-run context in RAG pipelines"],"tags":["evals","scorer","context-recall","config"],"backgroundTag":"missing-context-option","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}