What are Schemas?
Schemas serve multiple purposes:- Define structure: Specify fields, types, and nesting
- Guide extraction: Help the AI understand what to look for
- Validate output: Ensure extracted data matches expected format
- Enable type safety: Generate TypeScript types from schemas
Schema Structure
Schemas follow the JSON Schema specification (draft-07):Key Schema Properties
description
The most important property for extraction quality. Descriptions tell the AI what to look for and where to find it:
required
Fields that must be extracted. If a required field cannot be found, the extraction may fail or return null:
type
Data type for the field:
format
String format hints that help the AI understand expected patterns:
date: ISO date (YYYY-MM-DD)time: Time (HH:MM or HH:MM:SS)date-time: ISO 8601 datetimeemail: Email addressuri: URL/URI
enum
Restrict values to a specific set:
nullable
Allow a field to be null when data is not present:
Different providers handle nullable differently. The SDK automatically translates
nullable: true to the appropriate format for each provider (e.g., anyOf with null type for OpenAI).pattern
Regular expression pattern for string validation:
Using Schemas
Inline Schema
Pass the schema object directly to the extract node:Schema Reference
Reference schemas stored in the registry by ID and version:id@version (e.g., bdn@1.0.0, invoice@2.1.0).
Enhanced Schema
Add examples and extraction guidance alongside the schema:Schema Registry
The SDK includes a schema registry for storing and retrieving versioned schemas.Local Registry
Register and retrieve schemas in memory:Remote Registry (Cloud)
Fetch schemas from Doclo Cloud with automatic caching:Schema Asset Structure
A schema asset includes metadata alongside the schema definition:Built-in Schemas
The SDK includes pre-built schemas for common document types:
Access via the schema registry:
Schema Best Practices
Write Detailed Descriptions
The description is the most important property for extraction accuracy:Specify Where to Find Data
Help the AI locate fields in the document:Handle Optional and Missing Data
Use nullable types for fields that may not exist:Structure Nested Data Logically
Group related fields into objects:Define Array Item Schemas
Always specify the structure of array items:Handle Data Format Variations
Provide guidance for common format variations:Use Enums for Known Value Sets
Constrain values to valid options:Add Validation Constraints
Use validation keywords for data quality:TypeScript Integration
Infer Types from Schemas
Use TypeScript’sas const for type inference:
Use Zod Schemas
The SDK automatically converts Zod schemas to JSON Schema:Provider Considerations
Different providers have varying schema support. The SDK handles translation automatically:
The
SchemaTranslator class handles these conversions:
Validation
The SDK includes a lightweight JSON Schema validator that works in all environments including Edge Runtime:Next Steps
Extract Node
Use schemas for data extraction
Flows
Build document processing pipelines