Skip to main content
Define reusable JSON Schemas for structured AI outputs with Claude’s native JSON Schema support.

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

Response:

How to Reference in Ensembles

There are three ways to reference schemas in your ensembles: Use the schema:// 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:
In YAML:

Provider Support

Anthropic (Claude)

Claude natively supports JSON Schema for structured outputs:
Models with schema support:
  • claude-opus-4 - Best for complex schemas
  • claude-sonnet-4 - Balanced performance
  • claude-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 the ctx 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:
  1. Check schema exists: edgit list schemas
  2. Verify version: edgit tag list invoice
  3. Use local file path for testing: ./schemas/invoice.json

Invalid JSON Output

Issue: AI returns text instead of JSON Solutions:
  1. Lower temperature: temperature: 0.1
  2. Use more capable model: claude-sonnet-4 or claude-opus-4
  3. Add explicit instruction in prompt:

Schema Too Complex

Issue: AI struggles with complex nested schemas Solutions:
  1. Break into multiple agents with simpler schemas
  2. Use claude-opus-4 for complex schemas
  3. Simplify schema structure
  4. Provide examples in the prompt

Next Steps

Think Operation

Learn about AI reasoning operations

Component Versioning

Version control for components

JSON Schema

JSON Schema specification

Playbooks

Browse real-world examples