vercel/ai · error · NoOutputGeneratedError
No output generated.
Error message
No output generated.
What it means
NoOutputGeneratedError thrown by the result object's `output` getter when generateText was called with an output specification (experimental_output) but the model finished without producing any usable output. The SDK guards the accessor so consumers get a clear error instead of undefined.
Source
Thrown at packages/ai/src/generate-text/generate-text.ts:1747
get responseMessages() {
return [
...this.initialResponseMessages,
...this.steps.flatMap(step => step.response.messages),
];
}
get request() {
return this.finalStep.request;
}
get usage() {
return this.totalUsage;
}
get output() {
if (this._output == null) {
throw new NoOutputGeneratedError();
}
return this._output;
}
}
View on GitHub (pinned to 69428b1f8b)
Solutions
- Check `result.finishReason` before reading `result.output`; handle non-text finish reasons separately.
- Ensure the prompt instructs the model to produce the final structured output rather than calling tools.
- Wrap the `result.output` access in try/catch for NoOutputGeneratedError and fall back to raw text.
- Check for content-filter/empty responses from the provider and retry with an adjusted prompt.
- Update packages — some empty-output handling was fixed in newer releases.
Example fix
// before
const data = result.output;
// after
let data;
if (result.finishReason === 'stop') {
data = result.output; // may still throw; see catch below
} else {
data = fallbackForFinishReason(result.finishReason);
}
try { data = result.output; } catch (e) { if (NoOutputGeneratedError.isInstance(e)) data = null; else throw e; } Defensive patterns
Strategy: try-catch
Validate before calling
// guard before accessing output
function hasOutput(result) {
return result.finishReason === 'stop' && typeof result.text === 'string' && result.text.length > 0;
} Type guard
import { NoOutputGeneratedError } from 'ai';
function isNoOutputGenerated(e): e is NoOutputGeneratedError {
return NoOutputGeneratedError.isInstance(e);
} Try / catch
let output;
try {
output = result.output;
} catch (e) {
if (NoOutputGeneratedError.isInstance(e)) {
output = null; // handle empty generation, e.g. retry or fall back to result.text
} else throw e;
} Prevention
- Check result.finishReason before reading result.output.
- Raise maxOutputTokens to avoid truncated/empty generations.
- Handle tool-call and content-filter finish reasons explicitly.
- Retry on empty responses before giving up.
When it happens
Trigger: Accessing `result.output` after generateText with `experimental_output`/output spec when the step produced no text content or the output was never assigned (e.g. finishReason was tool-calls, content-filter, or the model returned an empty response).
Common situations: Model refused or returned empty completion; finishReason is 'tool-calls' so no text output was generated; content filter blocked the response; prompt asked for tool use while an output schema was also expected.
Related errors
- No video generated.
- AI_EmptyResponseBodyError
- Amazon Bedrock returned no images. Status: ${response.status
- VERTEX_VIDEO_GENERATION_ERROR
- Tool "${toolName}" did not return structuredContent or parse
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/2d5c7e9a4fa41704.
Report an issue: GitHub.