new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

AI SDK · Core · all subjects

generateobject & structured output

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Output.object for streaming objects with schema

Output.object({ schema }) generates and streams a single structured object matching the provided Zod schema. The object arrives as partial data during streaming, requiring null-safe checks in the UI.

Output.array for streaming array elements one at a time

Output.array({ element: schema }) streams an array of objects where each element conforms to the provided schema. Elements arrive one at a time during streaming, useful for generating lists of items progressively.

Output.json for unschema'd JSON generation

Output.json() generates JSON data without requiring a predefined schema. The model generates JSON based on the prompt alone. On the client, use z.unknown() as the schema with useObject when using Output.json().

Server-side streaming array generation example

```typescript import { streamText, Output, createTextStreamResponse, toTextStream } from 'ai'; import { notificationSchema } from './schema'; export const maxDuration = 30; export async function POST(req: Request) { const context = await req.json(); const result = streamText({ model: 'openai/gpt-4.1', output: Output.array({ element: notificationSchema }), prompt: `Generate 3 notifications for a messages app in this context:` + context, }); return createTextStreamResponse({ stream: toTextStream({ stream: result.stream }), }); } ``` This example demonstrates using Output.array to stream array elements one at a time from the server.

Output.object schema parameter

The Output.object() function accepts a schema parameter that defines the structure of the object to be generated. The schema is defined using Zod schema validation.

Output.object parameter for structured streaming

Output.object() accepts an object with a schema property containing a Zod schema definition. The schema defines the structure of the object to be streamed back to the client.

generateText Output specification for structured outputs

The output parameter controls how text is parsed. The Output specification provides methods for: - Output.text(): Output specification for text generation (default). - Output.object({ schema: Schema<OBJECT>, name?: string, description?: string }): Output specification for typed object generation using schemas. When the model generates a text response, it will return an object that matches the schema. - Output.array({ element: Schema<ELEMENT>, name?: string, description?: string }): Output specification for array generation. When the model generates a text response, it will return an array of elements. - Output.choice({ options: Array<string>, name?: string, description?: string }): Output specification for choice generation. When the model generates a text response, it will return one of the choice options. - Output.json({ name?: string, description?: string }): Output specification for unstructured JSON generation. When the model generates a text response, it will return a JSON object.

jsonSchema helper function description

jsonSchema() creates AI SDK compatible JSON schema objects.

zodSchema helper function description

zodSchema() creates AI SDK compatible Zod schema objects.

streamText parameter: output

The 'output' parameter is of type Output and is optional. It specifies parsing of structured outputs from the LLM response. Available output specifications: Output.text() for text generation (default), Output.object({ schema, name?, description? }), Output.array({ element, name?, description? }), Output.choice({ options: Array<string>, name?, description? }), and Output.json({ name?, description? }).

Give your agent this brain