mastra-ai/mastra · error · MastraError

MASTR_SCORER_FAILED_TO_CREATE_MISSING_ID

MASTR_SCORER_FAILED_TO_CREATE_MISSING_ID

Error message

Scorers must have an ID field. Please provide an ID in the scorer config.

What it means

Every MastraScorer requires a unique `id` in its config, which the framework uses to register, reference, and persist the scorer. The constructor throws MASTR_SCORER_FAILED_TO_CREATE_MISSING_ID (SCORER domain, USER category) when config.id is undefined, so an anonymous scorer can never be instantiated.

Source

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

   * Tracks whether this scorer was defined in code or loaded from storage.
   * Set by `Mastra.addScorer()` when the `source` option is provided.
   */
  public source?: DefinitionSource;

  constructor(
    public config: ScorerConfig<TID, TInput, TRunOutput>,
    private steps: Array<ScorerStepDefinition> = [],
    private originalPromptObjects: Map<
      string,
      | PromptObject<any, any, any, TInput, TRunOutput>
      | GenerateReasonPromptObject<any, TInput, TRunOutput>
      | GenerateScorePromptObject<any, TInput, TRunOutput>
    > = new Map(),
    mastra?: Mastra,
  ) {
    this.#mastra = mastra;
    if (!this.config.id) {
      throw new MastraError({
        id: 'MASTR_SCORER_FAILED_TO_CREATE_MISSING_ID',
        domain: ErrorDomain.SCORER,
        category: ErrorCategory.USER,
        text: `Scorers must have an ID field. Please provide an ID in the scorer config.`,
      });
    }
  }

  /**
   * Registers the Mastra instance with the scorer.
   * This enables access to custom gateways for model resolution.
   * @internal
   */
  __registerMastra(mastra: Mastra): void {
    this.#mastra = mastra;
  }

  /**

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Add a stable, unique `id` string to the scorer config object.
  2. If the config is built dynamically, ensure the id key is present and not undefined at construction time.
  3. Update old scorer definitions that predate the required-id requirement by assigning them explicit ids.

Example fix

// before
const scorer = new AnswerScorer({ name: 'answer-check' });
// after
const scorer = new AnswerScorer({ id: 'answer-check', name: 'answer-check' });
Defensive patterns

Strategy: validation

Validate before calling

if (!config || typeof config.id !== 'string' || config.id.length === 0) {
  throw new TypeError('Scorer config must include a non-empty string id');
}
const scorer = new MyScorer(config);

Type guard

function hasScorerId(config: { id?: string } | undefined): config is { id: string } & Record<string, unknown> {
  return typeof config?.id === 'string' && config.id.length > 0;
}

Try / catch

let scorer: MyScorer;
try {
  scorer = new MyScorer(config);
} catch (e) {
  if (e instanceof MastraError && e.id === 'MASTR_SCORER_FAILED_TO_CREATE_MISSING_ID') {
    throw new Error(`Scorer '${config?.name ?? 'unknown'}' is missing required config.id`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Creating `new MyScorer({ name: 'x' })` or extending Scorer/MastraScorer and passing a config object that omits the `id` field entirely, or passing `id: undefined` programmatically.

Common situations: Copy-pasting a scorer config that only sets name/description; building configs dynamically where the id property name was misspelled; older code or examples written before `id` became required in the scorer config API.

Related errors


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