{"record":{"id":"732f8d5ce5da8c1f","repo":"mastra-ai/mastra","slug":"no-context-available-for-evaluation","errorCode":null,"errorMessage":"No context available for evaluation","messagePattern":"No context available for evaluation","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/evals/src/scorers/llm/context-precision/index.ts","lineNumber":90,"sourceCode":"      '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',\n      outputSchema: contextRelevanceOutputSchema,\n      createPrompt: ({ run }) => {\n        const input = getUserMessageFromRunInput(run.input) ?? '';\n        const output = getAssistantMessageFromRunOutput(run.output) ?? '';\n\n        // Get context either from options or extractor\n        const context = getContext({ input: run.input, output: run.output, options });\n\n        if (context.length === 0) {\n          throw new Error('No context available for evaluation');\n        }\n\n        return createContextRelevancePrompt({\n          input,\n          output,\n          context,\n        });\n      },\n    })\n    .generateScore(({ results }) => {\n      if (!results.analyzeStepResult || results.analyzeStepResult.verdicts.length === 0) {\n        return 0;\n      }\n\n      const verdicts = results.analyzeStepResult.verdicts;\n\n      // Sort verdicts by context_index to ensure proper order\n      const sortedVerdicts = verdicts.sort((a, b) => a.context_index - b.context_index);","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/evals/src/scorers/llm/context-precision/index.ts#L72-L108","documentation":"This error fires at scoring time inside the context-precision scorer's pipeline. After resolving context — either from options.context or by invoking contextExtractor — if the resulting array is empty there is nothing for the LLM judge to rank, so the step throws. Unlike 2115/2116 (factory-time), this one occurs during run() when a per-run contextExtractor returns an empty array for that specific run.","triggerScenarios":"Calling score()/run() where options.contextExtractor({ run }) returns [] for that run (e.g. run.input has no retrievedDocuments); passing dynamic context that resolves to an empty array for a particular sample.","commonSituations":"RAG evaluation where some runs had no retrieval hits; contextExtractor reading a field with the wrong name/shape so it always maps to []; batch scoring with mixed datasets where some rows lack context.","solutions":["Fix or harden the contextExtractor so it falls back to a valid context source when the primary field is absent","Pre-filter runs: skip scoring (or mark as errored) for runs whose extractor yields no context","Inspect the failing run's input to confirm where retrieved context should live and correct the extractor's field access","If the static context option is what you intended, ensure contextExtractor is not overriding it with an empty result"],"exampleFix":"// before\noptions: { contextExtractor: ({ run }) => run.input.retrievedDocuments.map(d => d.text) }\n\n// after\noptions: {\n  contextExtractor: ({ run }) => {\n    const docs = run.input.retrievedDocuments ?? [];\n    if (!docs.length) throw new Error('Run has no retrieved documents; skipping');\n    return docs.map(d => d.text);\n  },\n}","handlingStrategy":"try-catch","validationCode":"const ctx = options.contextExtractor?.({ run }) ?? options.context ?? [];\nif (!ctx.length) {\n  console.warn('Skipping run: no context resolved for evaluation');\n  return null;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await scorer.run(payload);\n  return result;\n} catch (err) {\n  if ((err as Error).message === 'No context available for evaluation') {\n    markRunErrored(payload, 'no context resolved');\n    return null;\n  }\n  throw err;\n}","preventionTips":["Make contextExtractor defensive: fall back or throw a descriptive error when fields are missing","Log the run input shape when the extractor returns nothing","Pre-filter dataset rows lacking retrieved documents","Test contextExtractor against real run fixtures, not just happy-path samples"],"tags":["evals","scorer","context-precision","runtime"],"backgroundTag":"empty-context-array","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}