What Is Structured Output?
Structured output lets you define exactly how you want your AI responses formatted. Instead of parsing free-form text, you get clean, predictable data structures that are ready to use in your application.Type-Safe Responses
Define schemas and get responses that match your expected structure
No Parsing Required
Skip the regex and string parsing - data comes pre-formatted
Provider Validation
Providers like OpenAI enforce schema compliance at generation time
Works With Tools
Combine structured output with tool calls for powerful workflows
Quick Start
To enable structured output, override thegetSchema() method in your agent:
app/Agents/MovieReviewAgent.php
Using the Structured Agent
Available Schema Types
Vizra ADK uses Prism PHP’s schema system. Here are all available types:StringSchema
For text values of any length.NumberSchema
For integers and floating-point numbers.BooleanSchema
For true/false values.EnumSchema
For values restricted to a specific set of options.ArraySchema
For lists of items following a specific schema.ObjectSchema
For complex nested structures. This should be your root schema.AnyOfSchema
For flexible data that can match one of several schemas.Real-World Examples
Data Extraction Agent
Extract structured data from unstructured text:app/Agents/ContactExtractorAgent.php
Sentiment Analysis Agent
Analyze text sentiment with detailed breakdown:app/Agents/SentimentAnalysisAgent.php
Content Classification Agent
Classify content into categories with tags:app/Agents/ContentClassifierAgent.php
Nullable Fields
Mark fields as nullable when they might not have a value:Nullable Fields
OpenAI Strict Mode: When using OpenAI’s strict mode, all fields must be listed in
requiredFields. Use nullable: true to indicate optional fields that can have null values.Nested Schemas
For complex data structures, nest ObjectSchemas:Nested Schemas
Combining With Tools
Structured output works seamlessly with tools. The agent can call tools to gather information, then return a structured response:app/Agents/WeatherReportAgent.php
Provider Considerations
Different providers have varying levels of structured output support:OpenAI Strict Mode
Enable strict mode for tighter schema validation:OpenAI Strict Mode
Anthropic Tool Calling Mode
For Anthropic, use tool calling mode for more reliable structured output:Anthropic Tool Calling
Best Practices
Use ObjectSchema as Root
Always use ObjectSchema as your top-level schema. Providers like OpenAI require this in strict mode
Write Clear Descriptions
Descriptive field descriptions help the LLM understand what data to provide
Mark Optional Fields Nullable
Use
nullable: true for fields that might not have valuesValidate Responses
Even with structured output, validate the response in your application
API Reference
Schema Types
Agent Method
ObjectSchema Parameters
Tools
Learn how to create tools for your agents
Agents
Understanding agent architecture