Skip to content

Type Alias: Structure

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / Structure

Structure = JSONSchema | ZodLike

Defined in: src/types/schema.ts:222

Structure input type that accepts either JSON Schema or Zod schemas.

When a Zod schema is provided, it will be automatically converted to JSON Schema before being sent to the provider.

import { z } from 'zod';
// Using Zod schema directly
const model = llm({
model: anthropic('claude-sonnet-4-20250514'),
structure: z.object({
name: z.string(),
age: z.number(),
}),
});
// Using JSON Schema
const model = llm({
model: anthropic('claude-sonnet-4-20250514'),
structure: {
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'number' },
},
required: ['name', 'age'],
},
});