Overview
Schema components enable you to:- Get structured outputs from AI models using JSON Schema
- Version schemas with edgit for consistency
- Share schemas across multiple agents and ensembles
- Validate outputs against well-defined schemas
Quick Start
1. Create a Schema Component
Create a JSON Schema file:2. Reference the Schema
Use the schema in your ensemble:3. Get Structured Output
How to Reference in Ensembles
There are three ways to reference schemas in your ensembles:1. URI Format (Recommended)
Use theschema:// URI format to reference versioned schema components:
2. Template Expression Format
Use${components.schema_name@version} to embed schema references:
3. Inline Schema
For simple operations or during development, define the schema directly in YAML:Example Schemas
Invoice Schema
Sentiment Analysis Schema
Schema Versioning
Schema components follow semantic versioning:Provider Support
Anthropic (Claude)
Claude natively supports JSON Schema for structured outputs:claude-opus-4- Best for complex schemasclaude-sonnet-4- Balanced performanceclaude-haiku-4- Fast for simple schemas
OpenAI
OpenAI supports structured outputs via function calling:Cloudflare Workers AI
Best Practices
1. Use Descriptive Field Names
2. Add Descriptions
3. Use Enums for Categories
4. Set Constraints
5. Version Schemas Carefully
6. Test with Different Temperature
Common Patterns
Extraction with Validation
Multi-Schema Workflow
Using ctx API in Agents
When building custom agents with TypeScript handlers, you can access schemas through thectx API:
ctx.schemas.get(name)
Get a schema by name:ctx.schemas.validate(name, data)
Validate data against a schema. Throws an error if validation fails:ctx.schemas.isValid(name, data)
Check if data is valid without throwing errors (returns boolean):Complete Example
Troubleshooting
Schema Not Found
Error:Failed to resolve schema "schemas/invoice@v1"
Solution:
- Check schema exists:
edgit list schemas - Verify version:
edgit tag list invoice - Use local file path for testing:
./schemas/invoice.json
Invalid JSON Output
Issue: AI returns text instead of JSON Solutions:- Lower temperature:
temperature: 0.1 - Use more capable model:
claude-sonnet-4orclaude-opus-4 - Add explicit instruction in prompt:
Schema Too Complex
Issue: AI struggles with complex nested schemas Solutions:- Break into multiple agents with simpler schemas
- Use
claude-opus-4for complex schemas - Simplify schema structure
- Provide examples in the prompt

