mastra-ai/mastra · error · MastraError

AGENT_GENERATE_MALFORMED_RESULT

AGENT_GENERATE_MALFORMED_RESULT

Error message

Execution workflow produced a result without getFullOutput

What it means

Agent.generate() expects the execution workflow's result to expose getFullOutput(). If result.result exists but lacks that method, Mastra throws AGENT_GENERATE_MALFORMED_RESULT. Unlike most agent errors this is categorized SYSTEM, meaning it points to an internal contract violation rather than user input.

Source

Thrown at packages/core/src/agent/agent.ts:8054

          {
            id: 'AGENT_GENERATE_FAILED',
            domain: ErrorDomain.AGENT,
            category: ErrorCategory.USER,
          },
          // pass original error to preserve stack trace
          result.error,
        );
      }
      throw new MastraError({
        id: 'AGENT_GENERATE_UNKNOWN_ERROR',
        domain: ErrorDomain.AGENT,
        category: ErrorCategory.USER,
        text: 'An unknown error occurred while streaming',
      });
    }

    if (typeof result.result?.getFullOutput !== 'function') {
      throw new MastraError({
        id: 'AGENT_GENERATE_MALFORMED_RESULT',
        domain: ErrorDomain.AGENT,
        category: ErrorCategory.SYSTEM,
        text: 'Execution workflow produced a result without getFullOutput',
      });
    }

    const fullOutput = await result.result.getFullOutput();

    const error = fullOutput.error;

    if (error) {
      throw error;
    }

    return fullOutput;
  }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Remove any mocks/monkey-patches of the internal execution workflow and use the real result object.
  2. Align all @mastra/* package versions so core internals share one contract.
  3. If subclassing Agent, ensure overridden execute paths return the workflow result with getFullOutput().

Example fix

// before (test mock)
vi.spyOn(agent as any, '#execute').mockResolvedValue({ status: 'success', result: {} });
// after
.mockResolvedValue({ status: 'success', result: { getFullOutput: async () => output } });
Defensive patterns

Strategy: type-guard

Type guard

function hasFullOutput(r: unknown): r is { getFullOutput: () => Promise<unknown> } {
  return typeof (r as any)?.getFullOutput === 'function';
}

Try / catch

try {
  await agent.generate(prompt);
} catch (e) {
  if (e instanceof MastraError && e.id === 'AGENT_GENERATE_MALFORMED_RESULT') {
    logger.error('Internal result contract violated — check for mocks/version mismatch', { e });
  }
  throw e;
}

Prevention

When it happens

Trigger: The workflow returned by #execute() resolves to an object without a getFullOutput function — e.g. a mocked/shimmed workflow result, an incompatible custom workflow implementation, or an internal version mismatch.

Common situations: Patching or mocking the internal execution workflow in tests with a partial result shape; mixing @mastra/core versions (e.g. server/core mismatch); subclassing Agent and overriding #execute or related internals incorrectly.

Related errors


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