vercel/ai · error · NoObjectGeneratedError
No object generated: could not parse the response.
Error message
No object generated: could not parse the response.
What it means
NoObjectGeneratedError thrown by the object output parser when safeParseJSON fails on the model's complete text response — the response text is not valid JSON. The SDK throws with the raw text, response metadata, usage and finishReason attached for debugging.
Source
Thrown at packages/ai/src/generate-text/output.ts:133
responseFormat: resolve(schema.jsonSchema).then(jsonSchema => ({
type: 'json' as const,
schema: jsonSchema,
...(name != null && { name }),
...(description != null && { description }),
})),
async parseCompleteOutput(
{ text }: { text: string },
context: {
response: LanguageModelResponseMetadata;
usage: LanguageModelUsage;
finishReason: FinishReason;
},
) {
const parseResult = await safeParseJSON({ text });
if (!parseResult.success) {
throw new NoObjectGeneratedError({
message: 'No object generated: could not parse the response.',
cause: parseResult.error,
text,
response: context.response,
usage: context.usage,
finishReason: context.finishReason,
});
}
const validationResult = await safeValidateTypes({
value: parseResult.value,
schema,
});
if (!validationResult.success) {
throw new NoObjectGeneratedError({
message: 'No object generated: response did not match schema.',
cause: validationResult.error,View on GitHub (pinned to 69428b1f8b)
Solutions
- Inspect err.text (attached to the error) to see exactly what the model returned.
- Raise maxOutputTokens so the JSON is not truncated.
- Add prompt instructions: 'Respond with raw JSON only, no markdown fences or commentary.'
- Use a provider/mode that supports native structured output instead of text-based JSON extraction.
- Retry the request; transient truncation can cause invalid JSON.
Example fix
// before
const result = await generateText({ model, experimental_output: Output.object({ schema }) });
// after
const result = await generateText({ model, maxOutputTokens: 2000, experimental_output: Output.object({ schema }), prompt: 'Return only raw JSON matching the schema.' });
try { const obj = result.output; } catch (e) { if (NoObjectGeneratedError.isInstance(e)) console.log(e.text); } Defensive patterns
Strategy: validation
Validate before calling
// validate the raw text is JSON before trusting result.output
function isParseableJson(text) {
if (typeof text !== 'string' || text.length === 0) return false;
try { JSON.parse(text); return true; } catch { return false; }
}
// usage: if (!isParseableJson(result.text)) retry(); Type guard
import { NoObjectGeneratedError } from 'ai';
function isNoObjectGenerated(e): e is NoObjectGeneratedError {
return NoObjectGeneratedError.isInstance(e);
} Try / catch
try {
const obj = result.output;
} catch (e) {
if (NoObjectGeneratedError.isInstance(e)) {
console.error('Raw model text:', e.text, 'finishReason:', e.finishReason);
// retry with stricter prompt or repair e.text
} else throw e;
} Prevention
- Prompt for raw JSON only; forbid markdown fences and commentary.
- Set maxOutputTokens high enough for the largest expected object.
- Prefer provider-native structured output over text-based extraction.
- Log err.text on failure to diagnose quickly.
When it happens
Trigger: Using generateText with an object output spec (experimental_output: Output.object) and the model's final text could not be JSON.parse'd (truncated stream, markdown-fenced JSON, prose wrapper, or empty response).
Common situations: Model wraps JSON in ```json fences; maxOutputTokens too low so JSON is truncated; model answers in prose instead of JSON; empty response due to content filter.
Understand the failure class
Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.
Related errors
- No object generated: could not parse the response.
- No object generated: response did not match schema.
- No object generated: response did not match schema.
- Harness 'claude-code' requires a JSON schema for structured
- Harness 'cline' requires a JSON schema for structured output
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/e08a722cd5c54f27.
Report an issue: GitHub.