mastra-ai/mastra · error · MastraError

RUN_EXPERIMENT_TARGET_FAILED_TO_GENERATE_RESULT

RUN_EXPERIMENT_TARGET_FAILED_TO_GENERATE_RESULT

Error message

Failed to run experiment: Error generating result from target

What it means

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.

Source

Thrown at packages/core/src/evals/run/index.ts:832

}

async function executeTarget(
  target: Agent | Workflow,
  item: RunEvalsDataItem<any>,
  targetOptions?: RunEvalsAgentOptions | WorkflowRunOptions,
) {
  try {
    if (isWorkflow(target)) {
      return await executeWorkflow(target, item, targetOptions as WorkflowRunOptions);
    } else if (item.turns && Array.isArray(item.turns) && item.turns.length > 0) {
      return await executeAgentTurns(target, item, targetOptions as RunEvalsAgentOptions);
    } else if (item.inputs && Array.isArray(item.inputs) && item.inputs.length > 0) {
      return await executeAgentMultiTurn(target, item, targetOptions as RunEvalsAgentOptions);
    } else {
      return await executeAgent(target, item, targetOptions as RunEvalsAgentOptions);
    }
  } catch (error) {
    throw new MastraError(
      {
        domain: 'SCORER',
        id: 'RUN_EXPERIMENT_TARGET_FAILED_TO_GENERATE_RESULT',
        category: 'USER',
        text: 'Failed to run experiment: Error generating result from target',
        details: {
          item: JSON.stringify(item),
        },
      },
      error,
    );
  }
}

async function executeWorkflow(target: Workflow, item: RunEvalsDataItem<any>, targetOptions?: WorkflowRunOptions) {
  const observabilityContext = resolveObservabilityContext(item);
  const run = await target.createRun({ disableScorers: true });
  const workflowResult = await run.start({

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Inspect error.cause / details.item to find the underlying target failure (it is preserved in the MastraError cause chain).
  2. Verify model provider credentials and model ID configured on the agent.
  3. Validate that item.input / item.inputs / item.turns match what the agent or workflow expects (workflow inputData must satisfy the start schema).
  4. Run the target (agent.generate or workflow.start) directly with the same item to reproduce the root error outside the experiment runner.
  5. If a tool is the culprit, test the tool in isolation with the same request context.

Example fix

// before: experiment fails with opaque target error
const item = { input: { topic: 123 } }; // workflow expects { topic: string }
// after: validate input before running the experiment
const parsed = workflow.inputSchema.parse({ topic: 123 }); // throws a clear Zod error first
const item = { input: parsed };
Defensive patterns

Strategy: try-catch

Validate before calling

// before running the experiment, validate the target and inputs
if (isWorkflow(target)) target.inputSchema.parse(item.input);
if (!isWorkflow(target) && !item.input && !item.inputs?.length && !item.turns?.length) {
  throw new Error('Dataset item has no input for agent target');
}

Type guard

function hasValidAgentInput(item) {
  return Boolean(item.input || (Array.isArray(item.inputs) && item.inputs.length > 0) || (Array.isArray(item.turns) && item.turns.length > 0));
}

Try / catch

try {
  await mastra.getExperiment({ target, scorers, data }).run();
} catch (e) {
  if (e?.id === 'RUN_EXPERIMENT_TARGET_FAILED_TO_GENERATE_RESULT') {
    console.error('Target failed:', e.cause, 'item:', e.details?.item);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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