Structured Output
Genkit allows you to generate structured JSON data that maps directly to your programming language’s type system. This ensures type safety and makes it easy to use AI-generated data in your applications.Basic Structured Output
Define a schema and get type-safe JSON output:Schema Annotations
Use schema annotations to guide the model’s output:Complex Schemas
Create nested structures for complex data:Structured Output in Flows
Create flows that return structured data:Dynamic Prompts with Structured Input
Use structured input to build complex prompts:Streaming Structured Output
Stream structured data as it’s generated. See the Streaming guide for details.Best Practices
Use Descriptive Field Names
Choose clear, self-explanatory field names that help the model understand what to generate.Add Schema Descriptions
Usejsonschema tags (Go) or .describe() (TypeScript) to provide additional context:
Go
Use Enums for Categories
Constrain outputs to specific values using enums:Go
Handle Optional Fields
Mark fields as optional when they may not always be present:Go
Next Steps
- Learn about Streaming to stream structured data
- Explore Tool Calling for dynamic capabilities
- Check out Prompts for advanced templating