{"record":{"id":"9db933b91e75f927","repo":"mastra-ai/mastra","slug":"invalid-agent-scorers","errorCode":"INVALID_AGENT_SCORERS","errorMessage":"Agent scorers must be an array of scorers or an AgentScorerConfig","messagePattern":"Agent scorers must be an array of scorers or an AgentScorerConfig","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/evals/run/index.ts","lineNumber":807,"sourceCode":"        id: 'NO_SCORERS_PROVIDED',\n        category: 'USER',\n        text: 'At least one workflow, step, or trajectory scorer must be provided',\n      });\n    }\n  } else if (!isWorkflow(target) && isAgentScorerConfig(scorers)) {\n    const hasScorers =\n      (scorers.agent && scorers.agent.length > 0) || (scorers.trajectory && scorers.trajectory.length > 0);\n\n    if (!hasScorers) {\n      throw new MastraError({\n        domain: 'SCORER',\n        id: 'NO_SCORERS_PROVIDED',\n        category: 'USER',\n        text: 'At least one agent or trajectory scorer must be provided',\n      });\n    }\n  } else if (!isWorkflow(target) && !Array.isArray(scorers) && !isAgentScorerConfig(scorers)) {\n    throw new MastraError({\n      domain: 'SCORER',\n      id: 'INVALID_AGENT_SCORERS',\n      category: 'USER',\n      text: 'Agent scorers must be an array of scorers or an AgentScorerConfig',\n    });\n  }\n}\n\nasync function executeTarget(\n  target: Agent | Workflow,\n  item: RunEvalsDataItem<any>,\n  targetOptions?: RunEvalsAgentOptions | WorkflowRunOptions,\n) {\n  try {\n    if (isWorkflow(target)) {\n      return await executeWorkflow(target, item, targetOptions as WorkflowRunOptions);\n    } else if (item.turns && Array.isArray(item.turns) && item.turns.length > 0) {\n      return await executeAgentTurns(target, item, targetOptions as RunEvalsAgentOptions);","sourceCodeStart":789,"sourceCodeEnd":825,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/evals/run/index.ts#L789-L825","documentation":"For agent targets, `scorers` must be either a plain array of scorers or an AgentScorerConfig object (with `agent`/`trajectory` keys). Any other value — a string, a single scorer object not in an array, a malformed config, or a workflow-shaped config on a non-workflow target — is rejected as a type/shape error before the run starts.","triggerScenarios":"Passing a single scorer object directly instead of wrapping it in an array (`scorers: myScorer`); passing a string scorer ID; passing `{ steps: ... }` or `{ workflow: ... }` config while the target is an agent; scorers loaded from JSON losing their expected shape.","commonSituations":"Migrating from older APIs that accepted a bare scorer; copy-pasting workflow scorer configs into agent runs; YAML/JSON config parsing producing strings or unexpected structures.","solutions":["Wrap a single scorer in an array: `scorers: [myScorer]`","For keyed configs on agent targets, use the AgentScorerConfig shape: `{ agent: [...], trajectory: [...] }`","If you intended workflow/step scorers, set `target` to the Workflow — the object shape must match the target kind"],"exampleFix":"// before\nrunEvals({ target: agent, scorers: myScorer, data });\n// after\nrunEvals({ target: agent, scorers: [myScorer], data });","handlingStrategy":"type-guard","validationCode":"function assertScorersShape(scorers, isWf) {\n  const ok = Array.isArray(scorers) || (typeof scorers === 'object' && scorers !== null && (isWf ? true : ('agent' in scorers || 'trajectory' in scorers)));\n  if (!ok) throw new Error('scorers must be an array of scorers or a valid config object');\n}","typeGuard":"function isScorerArray(s: unknown): s is unknown[] {\n  return Array.isArray(s);\n}\nfunction isAgentScorerConfigLike(s: unknown): s is { agent?: unknown[]; trajectory?: unknown[] } {\n  return typeof s === 'object' && s !== null && ('agent' in s || 'trajectory' in s);\n}","tryCatchPattern":"try {\n  await runEvals({ target, scorers, data });\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'INVALID_AGENT_SCORERS') {\n    throw new TypeError(`Bad scorers argument: ${e.message}. Wrap single scorers in an array.`);\n  }\n  throw e;\n}","preventionTips":["Always pass scorers as an array or the documented config object — never a bare scorer","Type the scorers parameter with the library's union type so TypeScript catches bare-scorer mistakes","Validate scorers loaded from JSON/YAML against the expected shape before runEvals"],"tags":["evals","typescript","configuration"],"backgroundTag":"invalid-argument-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}