mastra-ai/mastra · error · Error

Step "${scorerStep.name}" is not a prompt object

Error message

Step "${scorerStep.name}" is not a prompt object

What it means

MastraScorer keeps a registry (`originalPromptObjects`) of the prompt objects registered on the scorer. When a judge step runs, it looks the step up by name via `this.originalPromptObjects.get(scorerStep.name)`; if the name is absent, this plain Error is thrown. It means the step being executed was never registered as a prompt object on this scorer, so the library cannot produce the judge prompt.

Source

Thrown at packages/core/src/evals/base.ts:1367

      return { run, results: accumulatedResults, score };
    }

    return { run, results: accumulatedResults };
  }

  private async executeFunctionStep(scorerStep: ScorerStepDefinition, context: any) {
    return await scorerStep.definition(context);
  }

  private async executePromptStep(
    scorerStep: ScorerStepDefinition,
    observabilityContext: ObservabilityContext,
    context: any,
  ): Promise<{ result: unknown; prompt: string; judgeModel?: string; execution: ScorerJudgeExecution }> {
    const startedAt = performance.now();
    const originalStep = this.originalPromptObjects.get(scorerStep.name);
    if (!originalStep) {
      throw new Error(`Step "${scorerStep.name}" is not a prompt object`);
    }

    const prompt = await originalStep.createPrompt(context);
    const modelConfig = originalStep.judge?.model ?? this.config.judge?.model;
    const instructions = originalStep.judge?.instructions ?? this.config.judge?.instructions;
    const jsonPromptInjection =
      originalStep.judge?.jsonPromptInjection ?? this.config.judge?.jsonPromptInjection ?? 'auto';
    // Step-level tools override scorer-level tools. When present, the judge agent
    // can call them (in its own tool-call loop) before producing the step output.
    const tools = originalStep.judge?.tools ?? this.config.judge?.tools;
    const memory = this.config.judge?.memory;
    const defaultMemoryOptions = this.config.judge?.defaultMemoryOptions;
    const stepMemoryOptions = originalStep.judge?.memory;
    const onStream = originalStep.judge?.onStream ?? this.config.judge?.onStream;
    const onStepFinish = originalStep.judge?.onStepFinish ?? this.config.judge?.onStepFinish;
    const onFinish = originalStep.judge?.onFinish ?? this.config.judge?.onFinish;
    const maxSteps = originalStep.judge?.maxSteps ?? this.config.judge?.maxSteps;
    const inputProcessors = originalStep.judge?.inputProcessors ?? this.config.judge?.inputProcessors;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Ensure every scorer step is registered through the scorer constructor/config so it lands in `originalPromptObjects`
  2. Verify `scorerStep.name` matches the name of a registered prompt object exactly (case-sensitive)
  3. Re-create the scorer from current code/config if it was deserialized from an older schema
  4. If constructing steps dynamically, register each prompt object on the scorer before running it

Example fix

// before
scorer.addStep({ name: 'correctness-judge', ... }); // not registered -> throws at runtime
// after
const scorer = new MastraScorer({
  id: 'my-scorer',
  judge: { model: 'openai/gpt-4o', instructions: 'Grade the answer' },
});
// use the scorer's own judge step (auto-registered) instead of a hand-built step
Defensive patterns

Strategy: validation

Validate before calling

function isRegisteredPromptStep(scorer, stepName) {
  // access via the scorer's registered steps / originalPromptObjects surface
  return !!scorer.getStep?.(stepName) ?? false;
}
// assert before running:
if (!isRegisteredPromptStep(scorer, step.name)) throw new Error(`Step "${step.name}" not registered on scorer`);

Type guard

function hasRegisteredStep(scorer: MastraScorer, name: string): boolean {
  return typeof (scorer as any).originalPromptObjects?.get === 'function'
    && (scorer as any).originalPromptObjects.has(name);
}

Prevention

When it happens

Trigger: Calling `MastraScorer.runJudge`/internal step execution with a `scorerStep.name` that has no entry in `originalPromptObjects` — e.g. a scorer step was renamed, a custom step was injected that bypassed registration, or the scorer was constructed without registering its prompt objects.

Common situations: Renaming a scorer step but referencing the old name in config; building scorers programmatically and adding steps directly to internal state instead of via the constructor; version drift where serialized/stored scorer configs reference steps that no longer exist on the scorer class.

Related errors


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