{"record":{"id":"342dc663e0143dad","repo":"mastra-ai/mastra","slug":"run-experiment-target-failed-to-generate-result","errorCode":"RUN_EXPERIMENT_TARGET_FAILED_TO_GENERATE_RESULT","errorMessage":"Failed to run experiment: Error generating result from target","messagePattern":"Failed to run experiment: Error generating result from target","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/evals/run/index.ts","lineNumber":832,"sourceCode":"}\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);\n    } else if (item.inputs && Array.isArray(item.inputs) && item.inputs.length > 0) {\n      return await executeAgentMultiTurn(target, item, targetOptions as RunEvalsAgentOptions);\n    } else {\n      return await executeAgent(target, item, targetOptions as RunEvalsAgentOptions);\n    }\n  } catch (error) {\n    throw new MastraError(\n      {\n        domain: 'SCORER',\n        id: 'RUN_EXPERIMENT_TARGET_FAILED_TO_GENERATE_RESULT',\n        category: 'USER',\n        text: 'Failed to run experiment: Error generating result from target',\n        details: {\n          item: JSON.stringify(item),\n        },\n      },\n      error,\n    );\n  }\n}\n\nasync function executeWorkflow(target: Workflow, item: RunEvalsDataItem<any>, targetOptions?: WorkflowRunOptions) {\n  const observabilityContext = resolveObservabilityContext(item);\n  const run = await target.createRun({ disableScorers: true });\n  const workflowResult = await run.start({","sourceCodeStart":814,"sourceCodeEnd":850,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/evals/run/index.ts#L814-L850","documentation":"Wraps any failure that occurs while executing the experiment target (an Agent or Workflow) during an evals/experiment run in packages/core/src/evals/run/index.ts. executeTarget dispatches to executeWorkflow, executeAgentTurns, executeAgentMultiTurn, or executeAgent; if any of those throw, the original error is wrapped in a MastraError (SCORER domain, USER category) with the serialized data item in details. The cause chain retains the underlying error.","triggerScenarios":"Calling mastra.getExperiment()/runEvals where the target agent or workflow throws during generation: LLM API auth/network failure, invalid input schema for a workflow's inputData, agent generation error (invalid model, tool crash), or an exception inside executeAgentTurns/executeAgentMultiTurn/executeAgent for the given item.","commonSituations":"Expired or missing model provider API key; workflow input failing its Zod schema at runtime; item.inputs/turns misconfigured so the agent receives malformed prompts; model name typo causing provider 404; tool the agent calls throws.","solutions":["Inspect error.cause / details.item to find the underlying target failure (it is preserved in the MastraError cause chain).","Verify model provider credentials and model ID configured on the agent.","Validate that item.input / item.inputs / item.turns match what the agent or workflow expects (workflow inputData must satisfy the start schema).","Run the target (agent.generate or workflow.start) directly with the same item to reproduce the root error outside the experiment runner.","If a tool is the culprit, test the tool in isolation with the same request context."],"exampleFix":"// before: experiment fails with opaque target error\nconst item = { input: { topic: 123 } }; // workflow expects { topic: string }\n// after: validate input before running the experiment\nconst parsed = workflow.inputSchema.parse({ topic: 123 }); // throws a clear Zod error first\nconst item = { input: parsed };","handlingStrategy":"try-catch","validationCode":"// before running the experiment, validate the target and inputs\nif (isWorkflow(target)) target.inputSchema.parse(item.input);\nif (!isWorkflow(target) && !item.input && !item.inputs?.length && !item.turns?.length) {\n  throw new Error('Dataset item has no input for agent target');\n}","typeGuard":"function hasValidAgentInput(item) {\n  return Boolean(item.input || (Array.isArray(item.inputs) && item.inputs.length > 0) || (Array.isArray(item.turns) && item.turns.length > 0));\n}","tryCatchPattern":"try {\n  await mastra.getExperiment({ target, scorers, data }).run();\n} catch (e) {\n  if (e?.id === 'RUN_EXPERIMENT_TARGET_FAILED_TO_GENERATE_RESULT') {\n    console.error('Target failed:', e.cause, 'item:', e.details?.item);\n  }\n  throw e;\n}","preventionTips":["Validate workflow inputData against the workflow's input schema before the run","Test model credentials with a trivial agent.generate call before batch experiments","Reproduce target failures by running the agent/workflow directly on the failing item","Log details.item from the MastraError to identify the failing dataset row"],"tags":["evals","agent","workflow","error-wrapping"],"backgroundTag":"llm-generation-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}