Structured output
Validated JSON responses with zod. No more regex-parsing the model's guess.
When you need a data payload, don't parse prose. Give the model a schema and let the adapter enforce it.
import { z } from 'zod'
import { runtime } from '@agentskit/runtime'
const Ticket = z.object({
priority: z.enum(['low', 'medium', 'high', 'urgent']),
summary: z.string().max(140),
tags: z.array(z.string()).max(5),
})
const result = await runtime.run(userMessage, {
responseFormat: Ticket,
})
// result.data is fully typed — z.infer<typeof Ticket>Note
Providers that support structured output natively (OpenAI response_format, Anthropic tool_use, Gemini responseSchema) get first-class treatment. Others fall back to zod validation on the generated text with automatic retry on parse failure.
Pitfall
Keep schemas flat when you can. Deeply nested objects increase the chance of parse failures on smaller models, which forces retries and burns tokens.
Explore nearby
- PeerCookbook
Copy-paste recipes for the things every agent app needs. Each recipe stands on its own.
- PeerStreaming chat
useChat + abort + back-pressure. The minimum viable streaming chat, production-ready.
- PeerTools + memory together
The "chat with state and actions" loop — persistent memory plus tool execution.