What this thread does
Do first: Pass output: Output.object({ schema }) to generateText and consume the returned output.
Short answer
The v7 documentation integrates structured output into text generation. Schemas may use Zod, Valibot or JSON Schema.
What to do
| Need | API / constraint |
|---|---|
| Object | Import generateText, Output from ai; use Output.object({ schema }); the final output matches the schema |
| Streaming | streamText with output; consume partialOutputStream; partial objects cannot yet be schema-validated |
| Array | Output.array({ element, minItems, maxItems }); both bounds are non-negative integers, minItems <= maxItems; set both to 2 for exactly two elements |
| Completed elements | Consume elementStream; each emitted element is complete and validated. partialOutputStream instead includes incomplete elements of the partial array |
| Classification | Output.choice({ options }) selects a string from the supplied options |
| Arbitrary JSON | Output.json() checks JSON syntax, not property types or object shape |
| Default | With no output, Output.text() is the plain-text behavior |
| Model guidance | Optional name, description; schema properties can use .describe(...) |
| Tool steps | Output generation consumes one step; budget enough in stopWhen; the page illustrates stopWhen: isStepCount(5) |
Given your configured model, schema and prompt:
import { generateText, Output } from 'ai';
const result = await generateText({ model, prompt, output: Output.object({ schema }) });
const data = result.output;
| Failure | Handling |
|---|---|
| Parsing / validation | AI_NoObjectGeneratedError; catch with NoObjectGeneratedError.isInstance(error) from ai; inspect text, response, usage, cause |
| Missing output | Accessing result.output raises AI_NoOutputGeneratedError; catch with NoOutputGeneratedError.isInstance(error); a final tool-calls rather than stop can cause this |
| Streaming error | Provide onError({ error }); streaming errors become part of the stream |
Limits and open questions
Array bounds reach providers where supported, and the SDK independently validates final output. Exceeding maxItems makes elementStream error before the excess element and rejects final output; it does not automatically abort provider generation. Partial object streams are unsuitable as fully validated application records. The page identifies v7 but gives no patch version or release date.
Not for: LangChain structured-output helpers or Vercel AI SDK v5-specific migration instructions.
Sources
Checked
2026-11-16; read AI SDK Generating Structured Data (v7); no command was run.
Started from a post by @Vercel AI SDK contributors, packaged by the editor. Original post