{"record":{"id":"b380095be9fb3dae","repo":"mastra-ai/mastra","slug":"run-experiment-scorer-failed-to-score-trajectory","errorCode":"RUN_EXPERIMENT_SCORER_FAILED_TO_SCORE_TRAJECTORY","errorMessage":"Failed to run experiment: Error running trajectory scorer ${scorer.id}","messagePattern":"Failed to run experiment: Error running trajectory scorer (.+?)","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/evals/run/index.ts","lineNumber":1181,"sourceCode":"      const trajectory = traceTrajectory ?? (rawOutput ? extractTrajectory(rawOutput) : { steps: [] });\n\n      for (const scorer of scorers.trajectory) {\n        try {\n          const score = await scorer.run({\n            input: targetResult.scoringData?.input,\n            output: trajectory,\n            groundTruth: item.groundTruth,\n            expectedTrajectory: item.expectedTrajectory,\n            requestContext: item.requestContext,\n            scoreSource: 'experiment',\n            targetScope: 'trajectory',\n            targetEntityType,\n            targetTraceId,\n            targetSpanId: targetResult.spanId,\n          });\n          trajectoryScorerResults[scorer.id] = score;\n        } catch (error) {\n          throw new MastraError(\n            {\n              domain: 'SCORER',\n              id: 'RUN_EXPERIMENT_SCORER_FAILED_TO_SCORE_TRAJECTORY',\n              category: 'USER',\n              text: `Failed to run experiment: Error running trajectory scorer ${scorer.id}`,\n              details: {\n                scorerId: scorer.id,\n                item: JSON.stringify(item),\n              },\n            },\n            error,\n          );\n        }\n      }\n      if (Object.keys(trajectoryScorerResults).length > 0) {\n        scorerResults.trajectory = trajectoryScorerResults;\n      }\n    }","sourceCodeStart":1163,"sourceCodeEnd":1199,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/evals/run/index.ts#L1163-L1199","documentation":"Thrown when a trajectory scorer (scoring the conversation/workflow trajectory as a whole) fails during an agent experiment run. The runner wraps the underlying scorer.run error in a MastraError with id RUN_EXPERIMENT_SCORER_FAILED_TO_SCORE_TRAJECTORY, naming the scorer id.","triggerScenarios":"Experiment on an Agent with scorers.trajectory configured; scorer.run is invoked with EntityType.TRAJECTORY targeting the run's trace/span and throws — e.g. the trajectory scorer cannot parse the turns/messages or its judge LLM fails.","commonSituations":"Multi-turn dataset items (item.turns/item.inputs) producing trajectories the scorer didn't expect (empty messages); trajectory scorer requiring tool-call data absent from the run; LLM judge misconfiguration.","solutions":["Check the wrapped cause for the scorer-internal error.","Confirm the dataset items produce non-empty, well-formed trajectories (turns/inputs arrays).","Validate the trajectory scorer's expected input shape (messages, tool calls) against what the agent produced.","Test the trajectory scorer standalone on a recorded trace.","Fix judge model credentials/rate limits if LLM-based."],"exampleFix":"// before: trajectory scorer assumes toolCalls exist\nconst score = trajectory.filter(t => t.toolCalls.length > 0)...\n// after: guard for missing data\nconst score = trajectory.filter(t => (t.toolCalls ?? []).length > 0)...","handlingStrategy":"validation","validationCode":"// ensure dataset items yield non-empty trajectories before scoring\nfor (const item of data) {\n  const hasTurns = Array.isArray(item.turns) && item.turns.length > 0;\n  const hasInputs = Array.isArray(item.inputs) && item.inputs.length > 0;\n  if (!hasTurns && !hasInputs) throw new Error('Item produces an empty trajectory');\n}","typeGuard":"function producesTrajectory(item) {\n  return (Array.isArray(item.turns) && item.turns.length > 0) || (Array.isArray(item.inputs) && item.inputs.length > 0);\n}","tryCatchPattern":null,"preventionTips":["Verify trajectory scorers expect message-shaped trajectory data, not StepResults","Test trajectory scorers on one recorded multi-turn run first","Guard trajectory processing for missing toolCalls/messages fields","Check judge model availability before long trajectory-heavy runs"],"tags":["evals","scorer","trajectory","error-wrapping"],"backgroundTag":"scorer-run-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}