mastra-ai/mastra · error · MastraError

RUN_EXPERIMENT_SCORER_FAILED_TO_SCORE_WORKFLOW_TRAJECTORY

RUN_EXPERIMENT_SCORER_FAILED_TO_SCORE_WORKFLOW_TRAJECTORY

Error message

Failed to run experiment: Error running workflow trajectory scorer ${scorer.id}

What it means

Thrown when a trajectory scorer fails during a workflow experiment run (trajectory over the workflow's execution path). The runner wraps the underlying error with id RUN_EXPERIMENT_SCORER_FAILED_TO_SCORE_WORKFLOW_TRAJECTORY, naming the scorer id, targeting EntityType.TRAJECTORY with the workflow run's trace/span.

Source

Thrown at packages/core/src/evals/run/index.ts:1300

      }

      for (const scorer of scorers.trajectory) {
        try {
          const score = await scorer.run({
            input: targetResult.scoringData?.input,
            output: trajectory,
            groundTruth: item.groundTruth,
            expectedTrajectory: item.expectedTrajectory,
            requestContext: item.requestContext,
            scoreSource: 'experiment',
            targetScope: 'trajectory',
            targetEntityType: EntityType.TRAJECTORY,
            targetTraceId,
            targetSpanId: targetResult.spanId,
          });
          trajectoryScorerResults[scorer.id] = score;
        } catch (error) {
          throw new MastraError(
            {
              domain: 'SCORER',
              id: 'RUN_EXPERIMENT_SCORER_FAILED_TO_SCORE_WORKFLOW_TRAJECTORY',
              category: 'USER',
              text: `Failed to run experiment: Error running workflow trajectory scorer ${scorer.id}`,
              details: {
                scorerId: scorer.id,
                item: JSON.stringify(item),
              },
            },
            error,
          );
        }
      }
      if (Object.keys(trajectoryScorerResults).length > 0) {
        scorerResults.trajectory = trajectoryScorerResults;
      }
    }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Inspect the wrapped cause for the scorer's internal error.
  2. Verify the workflow run succeeded (status 'success') before trajectory scoring; fix failing steps.
  3. Use trajectory scorers designed for workflow trajectories (or adapt extract to StepResult shapes).
  4. Test the scorer on one recorded workflow trace via scorer.run.
  5. Check judge model credentials if the scorer is LLM-based.

Example fix

// before: agent-style trajectory scorer applied to workflow runs
scorers: { trajectory: [agentToolUsageScorer] }
// after: use a workflow-appropriate scorer or guard step shapes
extract: ({ run }) => ({ steps: run.stepResults ? Object.keys(run.stepResults) : [] })
Defensive patterns

Strategy: validation

Validate before calling

// only score trajectories of successful workflow runs
if (result.status !== 'success') throw new Error('Workflow run failed; trajectory incomplete for scoring');

Type guard

function hasWorkflowTrajectory(result) {
  return result.status === 'success' && Array.isArray(result.stepExecutionPath) && result.stepExecutionPath.length > 0;
}

Prevention

When it happens

Trigger: Experiment on a Workflow target with trajectory scorers; scorer.run against the workflow trajectory throws — e.g. the scorer cannot build a trajectory from workflow step results, or its judge/model call fails.

Common situations: Workflow run ended non-success so trajectory data is incomplete; trajectory scorer designed for agent messages fed workflow StepResults instead; LLM judge auth/rate-limit failure; step outputs lacking expected fields.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/13986ab5bc656169. Report an issue: GitHub.