{"record":{"id":"dadebc0a128a065b","repo":"mastra-ai/mastra","slug":"mastr-scorer-failed-to-create-missing-id","errorCode":"MASTR_SCORER_FAILED_TO_CREATE_MISSING_ID","errorMessage":"Scorers must have an ID field. Please provide an ID in the scorer config.","messagePattern":"Scorers must have an ID field\\. Please provide an ID in the scorer config\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/evals/base.ts","lineNumber":729,"sourceCode":"   * Tracks whether this scorer was defined in code or loaded from storage.\n   * Set by `Mastra.addScorer()` when the `source` option is provided.\n   */\n  public source?: DefinitionSource;\n\n  constructor(\n    public config: ScorerConfig<TID, TInput, TRunOutput>,\n    private steps: Array<ScorerStepDefinition> = [],\n    private originalPromptObjects: Map<\n      string,\n      | PromptObject<any, any, any, TInput, TRunOutput>\n      | GenerateReasonPromptObject<any, TInput, TRunOutput>\n      | GenerateScorePromptObject<any, TInput, TRunOutput>\n    > = new Map(),\n    mastra?: Mastra,\n  ) {\n    this.#mastra = mastra;\n    if (!this.config.id) {\n      throw new MastraError({\n        id: 'MASTR_SCORER_FAILED_TO_CREATE_MISSING_ID',\n        domain: ErrorDomain.SCORER,\n        category: ErrorCategory.USER,\n        text: `Scorers must have an ID field. Please provide an ID in the scorer config.`,\n      });\n    }\n  }\n\n  /**\n   * Registers the Mastra instance with the scorer.\n   * This enables access to custom gateways for model resolution.\n   * @internal\n   */\n  __registerMastra(mastra: Mastra): void {\n    this.#mastra = mastra;\n  }\n\n  /**","sourceCodeStart":711,"sourceCodeEnd":747,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/evals/base.ts#L711-L747","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add a stable, unique `id` string to the scorer config object.","If the config is built dynamically, ensure the id key is present and not undefined at construction time.","Update old scorer definitions that predate the required-id requirement by assigning them explicit ids."],"exampleFix":"// before\nconst scorer = new AnswerScorer({ name: 'answer-check' });\n// after\nconst scorer = new AnswerScorer({ id: 'answer-check', name: 'answer-check' });","handlingStrategy":"validation","validationCode":"if (!config || typeof config.id !== 'string' || config.id.length === 0) {\n  throw new TypeError('Scorer config must include a non-empty string id');\n}\nconst scorer = new MyScorer(config);","typeGuard":"function hasScorerId(config: { id?: string } | undefined): config is { id: string } & Record<string, unknown> {\n  return typeof config?.id === 'string' && config.id.length > 0;\n}","tryCatchPattern":"let scorer: MyScorer;\ntry {\n  scorer = new MyScorer(config);\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'MASTR_SCORER_FAILED_TO_CREATE_MISSING_ID') {\n    throw new Error(`Scorer '${config?.name ?? 'unknown'}' is missing required config.id`);\n  }\n  throw e;\n}","preventionTips":["Always set a stable, unique `id` in every scorer config.","Type the config with a required `id: string` field so TypeScript flags omissions.","Avoid dynamically building config objects with optional id keys."],"tags":["scorer","config","evals","missing-field"],"backgroundTag":"missing-required-id","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}