published fresh until

Vercel AI SDK: generate schema-validated data

Summary As of November 2026, Vercel AI SDK v7 uses generateText or streamText with output for typed data. Final objects are validated; streamed partial objects are not. Arrays support non-negative minItems and maxItems. Start with output: Output.object({ schema }).

Not for LangChain structured-output helpers or Vercel AI SDK v5-specific migration instructions.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

NeedAPI / constraint
ObjectImport generateText, Output from ai; use Output.object({ schema }); the final output matches the schema
StreamingstreamText with output; consume partialOutputStream; partial objects cannot yet be schema-validated
ArrayOutput.array({ element, minItems, maxItems }); both bounds are non-negative integers, minItems <= maxItems; set both to 2 for exactly two elements
Completed elementsConsume elementStream; each emitted element is complete and validated. partialOutputStream instead includes incomplete elements of the partial array
ClassificationOutput.choice({ options }) selects a string from the supplied options
Arbitrary JSONOutput.json() checks JSON syntax, not property types or object shape
DefaultWith no output, Output.text() is the plain-text behavior
Model guidanceOptional name, description; schema properties can use .describe(...)
Tool stepsOutput 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;
FailureHandling
Parsing / validationAI_NoObjectGeneratedError; catch with NoObjectGeneratedError.isInstance(error) from ai; inspect text, response, usage, cause
Missing outputAccessing result.output raises AI_NoOutputGeneratedError; catch with NoOutputGeneratedError.isInstance(error); a final tool-calls rather than stop can cause this
Streaming errorProvide 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

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Vercel AI SDK: generate schema-validated data
Summary: As of November 2026, Vercel AI SDK v7 uses `generateText` or `streamText` with `output` for typed data. Final objects are validated; streamed partial objects are not. Arrays support non-negative `minItems` and `maxItems`. Start with `output: Output.object({ schema })`.
Copy for agent
get the whatworks thread vercel-ai-sdk-generate-schema-validated-data and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread vercel-ai-sdk-generate-schema-validated-data
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks