mastra-ai/mastra · error · Error
Root agent span has no output
Error message
Root agent span has no output
What it means
transformTraceToScorerInputAndOutput throws this when the root agent_run span exists but has no `output`. The scorer output is derived directly from the root span's output payload, so scoring cannot proceed without it.
Source
Thrown at packages/core/src/evals/scoreTraces/utils.ts:274
// Find the root agent run span
const rootAgentSpan = spanTree.rootSpans.find(span => span.spanType === 'agent_run') as SpanRecord | undefined;
if (!rootAgentSpan) {
throw new Error('No root agent_run span found in trace');
}
return { spanTree, rootAgentSpan };
}
export function transformTraceToScorerInputAndOutput(trace: TraceRecord): {
input: ScorerRunInputForAgent;
output: ScorerRunOutputForAgent;
} {
const { spanTree, rootAgentSpan } = prepareTraceForTransformation(trace);
if (!rootAgentSpan.output) {
throw new Error('Root agent span has no output');
}
// Build input
const primaryLLMSpan = findPrimaryLLMSpan(spanTree, rootAgentSpan);
const inputMessages = extractInputMessages(rootAgentSpan);
const systemMessages = extractSystemMessages(primaryLLMSpan);
// Extract remembered messages from LLM span (excluding current input)
const currentInputContent = inputMessages[0]?.content.content || '';
const rememberedMessages = extractRememberedMessages(primaryLLMSpan, currentInputContent);
const input = {
inputMessages,
rememberedMessages,
systemMessages,
taggedSystemMessages: {}, // Todo: Support tagged system messages
};
View on GitHub (pinned to 75dd419e61)
Solutions
- Only trigger scoring after the agent run completes successfully and output is persisted
- Check the storage adapter persists span output payloads (including large ones)
- Re-run the generation and score the new trace
Example fix
// before
await scoreTrace({ trace: runningTrace });
// after
await agentRunPromise; // wait for completion with output
await scoreTrace({ trace: await getTrace(traceId) }); Defensive patterns
Strategy: validation
Validate before calling
const { rootAgentSpan } = prepareTraceForTransformation(trace);
if (!rootAgentSpan.output) throw new Error('Agent run incomplete: no output to score'); Type guard
function hasRootOutput(t: TraceRecord): boolean {
const root = buildSpanTree(t.spans).rootSpans.find(s => s.spanType === 'agent_run');
return !!root && root.output != null;
} Try / catch
try {
const { output } = transformTraceToScorerInputAndOutput(trace);
} catch (e) {
if (e instanceof Error && e.message === 'Root agent span has no output') {
logger.warn('Skipping scoring: agent run produced no output', { traceId: trace.traceId });
} else throw e;
} Prevention
- Trigger scoring only after the agent run resolves successfully
- Verify storage adapters persist span output payloads fully
- Avoid scoring in-flight or cancelled runs
- Re-run generations whose traces lack output
When it happens
Trigger: Scoring a trace whose root agent span has output === null/undefined — e.g. the agent run was cancelled or errored before producing output, output persistence failed, or spans were trimmed before the run finished.
Common situations: Scoring aborted/failed agent runs; storage adapters dropping large output payloads; running scorers against in-flight traces before output is written.
Related errors
- Trace is null or undefined
- Trace must have a spans array
- Trace has no spans
- No model generation span found in trace
- Span ${span.spanId} references non-existent parent ${span.pa
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/65a3e227844d69a4.
Report an issue: GitHub.