{"record":{"id":"e08a722cd5c54f27","repo":"vercel/ai","slug":"no-object-generated-could-not-parse-the-response-e08a72","errorCode":null,"errorMessage":"No object generated: could not parse the response.","messagePattern":"No object generated: could not parse the response\\.","errorType":"validation","errorClass":"NoObjectGeneratedError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-text/output.ts","lineNumber":133,"sourceCode":"    responseFormat: resolve(schema.jsonSchema).then(jsonSchema => ({\n      type: 'json' as const,\n      schema: jsonSchema,\n      ...(name != null && { name }),\n      ...(description != null && { description }),\n    })),\n\n    async parseCompleteOutput(\n      { text }: { text: string },\n      context: {\n        response: LanguageModelResponseMetadata;\n        usage: LanguageModelUsage;\n        finishReason: FinishReason;\n      },\n    ) {\n      const parseResult = await safeParseJSON({ text });\n\n      if (!parseResult.success) {\n        throw new NoObjectGeneratedError({\n          message: 'No object generated: could not parse the response.',\n          cause: parseResult.error,\n          text,\n          response: context.response,\n          usage: context.usage,\n          finishReason: context.finishReason,\n        });\n      }\n\n      const validationResult = await safeValidateTypes({\n        value: parseResult.value,\n        schema,\n      });\n\n      if (!validationResult.success) {\n        throw new NoObjectGeneratedError({\n          message: 'No object generated: response did not match schema.',\n          cause: validationResult.error,","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-text/output.ts#L115-L151","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nconst result = await generateText({ model, experimental_output: Output.object({ schema }) });\n// after\nconst result = await generateText({ model, maxOutputTokens: 2000, experimental_output: Output.object({ schema }), prompt: 'Return only raw JSON matching the schema.' });\ntry { const obj = result.output; } catch (e) { if (NoObjectGeneratedError.isInstance(e)) console.log(e.text); }","handlingStrategy":"validation","validationCode":"// validate the raw text is JSON before trusting result.output\nfunction isParseableJson(text) {\n  if (typeof text !== 'string' || text.length === 0) return false;\n  try { JSON.parse(text); return true; } catch { return false; }\n}\n// usage: if (!isParseableJson(result.text)) retry();","typeGuard":"import { NoObjectGeneratedError } from 'ai';\nfunction isNoObjectGenerated(e): e is NoObjectGeneratedError {\n  return NoObjectGeneratedError.isInstance(e);\n}","tryCatchPattern":"try {\n  const obj = result.output;\n} catch (e) {\n  if (NoObjectGeneratedError.isInstance(e)) {\n    console.error('Raw model text:', e.text, 'finishReason:', e.finishReason);\n    // retry with stricter prompt or repair e.text\n  } else throw e;\n}","preventionTips":["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."],"tags":["json-parse","structured-output","no-object-generated"],"backgroundTag":"invalid-json-response","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}