{"record":{"id":"5b3600569f270ecb","repo":"mastra-ai/mastra","slug":"either-context-or-contextextractor-is-required-for","errorCode":null,"errorMessage":"Either context or contextExtractor is required for Context Precision scoring","messagePattern":"Either context or contextExtractor is required for Context Precision scoring","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/evals/src/scorers/llm/context-precision/index.ts","lineNumber":62,"sourceCode":"  output: ScorerRunOutputForLLMJudge;\n  options: ContextPrecisionMetricOptions;\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 createContextPrecisionScorer({\n  model,\n  options,\n}: {\n  model: MastraModelConfig;\n  options: ContextPrecisionMetricOptions;\n}) {\n  if (!options.context && !options.contextExtractor) {\n    throw new Error('Either context or contextExtractor is required for Context Precision 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-precision-scorer',\n    name: 'Context Precision Scorer',\n    description:\n      'A scorer that evaluates the relevance and precision of retrieved context nodes for generating expected outputs',\n    judge: {\n      model,\n      instructions: CONTEXT_PRECISION_AGENT_INSTRUCTIONS,\n    },\n    type: 'agent',\n  })\n    .analyze({\n      description: 'Evaluate the relevance of each context piece for generating the expected output',","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/evals/src/scorers/llm/context-precision/index.ts#L44-L80","documentation":"createContextPrecisionScorer needs retrieved context to judge: it must come either from a static options.context array or be computed per-run via options.contextExtractor. If neither is supplied the scorer cannot obtain context at scoring time, so the factory throws immediately. This is construction-time configuration validation in packages/evals/src/scorers/llm/context-precision/index.ts:62.","triggerScenarios":"Calling createContextPrecisionScorer({ model, options: {} }); passing options without context and without contextExtractor (e.g. only scale or other metric options); building options from config where both keys were dropped.","commonSituations":"Copying a context-precision example and deleting the context option; expecting the scorer to auto-derive context from the run's retrievedDocuments (it does not unless contextExtractor reads them); switching scorers and not updating the options object.","solutions":["Pass context: ['retrieved chunk 1', ...] for a fixed context set","Pass contextExtractor: ({ run }) => string[] to pull context from each run (e.g. from retrievedDocuments)","Verify both keys are spelled exactly context and contextExtractor on the options object","If you actually need recall-style checking, confirm you are using the right metric, but note it has the same requirement"],"exampleFix":"// before\nconst scorer = createContextPrecisionScorer({ model: 'openai/gpt-4o', options: {} });\n\n// after\nconst scorer = createContextPrecisionScorer({\n  model: 'openai/gpt-4o',\n  options: { contextExtractor: ({ run }) => run.input?.retrievedDocuments?.map(d => d.content) ?? [] },\n});","handlingStrategy":"validation","validationCode":"function validateContextOptions(o: ContextPrecisionMetricOptions): void {\n  if (!o.context && !o.contextExtractor) {\n    throw new Error('Context Precision needs options.context or options.contextExtractor');\n  }\n}\nvalidateContextOptions(options);","typeGuard":"function hasContextSource(o: ContextPrecisionMetricOptions): o is ContextPrecisionMetricOptions & ({ context: string[] } | { contextExtractor: (...a: unknown[]) => string[] }) {\n  return Boolean(o.context) || Boolean(o.contextExtractor);\n}","tryCatchPattern":"try {\n  const scorer = createContextPrecisionScorer({ 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 Precision options');\n  }\n  throw err;\n}","preventionTips":["Always wire either context or contextExtractor when creating context-based scorers","Use contextExtractor to pull from run.input.retrievedDocuments for RAG evals","Validate options with a schema at config load time","Spell keys exactly: context, contextExtractor"],"tags":["evals","scorer","context-precision","config"],"backgroundTag":"missing-context-option","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}