Overview
Your AI agents can already search and read the full contents of every file in a knowledge base. Extraction schemas add a structured index on top of that—a consistent set of fields extracted from each document that enables quick filtering and cross-document analysis. Think of it this way: without an extraction schema, answering “which contracts are worth over $1M?” requires the AI to open and read every contract. With an extraction schema that includestotal_value as a number field, that question becomes a simple filter.
Extraction schemas are most valuable for:
- Numeric fields you want to compare, aggregate, or filter (amounts, counts, percentages, dates)
- Categorical fields you want to group or filter by (document type, status, region, sector)
- Key identifiers that help locate the right documents quickly (deal names, parties, project codes)
Choosing What to Extract
Before writing your schema, ask yourself: “What questions do I want to answer across all my documents?”Prioritize fields that are
- Frequently used for filtering or sorting
- Needed for aggregations (sums, averages, counts)
- Used to categorize or group documents
- Key identifiers for finding specific documents
Skip fields that are
- Only useful when reading the full document (the AI can already do that)
- Highly variable or unstructured across documents
- Rarely needed for cross-document questions
Schema Basics
Extraction schemas use JSON Schema format. Your schema needs atype and, for an object, its properties. A required list is recommended:
Set a type
type field (usually "object").Define properties
properties field defining what to extract.List required fields (recommended)
required array listing the fields that should always be extracted.Field Types & Structures
The reference below covers every supported field type and the structures you can compose from them. Expand each section as you need it.Supported Types
Use these types for your schema fields:Making fields optional
Making fields optional
null to make fields optional:["type", "null"], the AI will return null if the information isn’t found in the document.Using enums
Using enums
null in the enum array if the field should be optional.Arrays
Arrays
Nested objects
Nested objects
Best Practices
1. Require fields whenever possible
1. Require fields whenever possible
2. Use enums for categories
2. Use enums for categories
3. Keep nesting shallow
3. Keep nesting shallow
4. Use descriptions to instruct the AI
4. Use descriptions to instruct the AI
description field is your primary way to guide the extraction AI. Think of descriptions as instructions telling the AI exactly how to interpret each field when analyzing the document:- Date and number formats:
"YYYY-MM-DD","in USD","as a decimal percentage (e.g., 0.15 for 15%)" - What to include or exclude:
"excluding taxes","only from the executive summary section" - How to handle missing data:
"Return null if not explicitly stated" - Where to look:
"from the signature block","as stated in the header" - Level of detail:
"one-sentence summary","verbatim quote","3-5 bullet points"
5. Test across multiple documents
5. Test across multiple documents
- Fields that don’t exist in all documents (should be optional with
null) - Categories that vary more than expected (broaden your enums)
- Format inconsistencies (clarify your descriptions)
- Edge cases you didn’t anticipate
Example Schemas
These are complete, copy-ready schemas for common document types. Switch tabs to see each one.Schema Depth: Index vs. Full Extraction
When designing your schema, consider how your agent will actually use the data.- Summary-level (index and filter)
- Deep (work directly from extracted data)
extracted_data.json to find the right files, then reads their .md content for line items, notes, and other detail. This is simpler to maintain and works well when documents vary in structure.How to decide
Setting Up Extraction
Open Knowledge Bases
Create or edit a knowledge base
Configure structured data extraction
- Choose an Extraction Model (optional) from your organization’s models
- Paste your schema into Extraction Schema (JSON)
Save and upload
Viewing Extracted Data
After processing completes:Open a file
View the extracted data
list_kb_files tool, which returns each file’s extractedData, or in Python from kb/{id}/extracted_data.json. (search_knowledge_base searches text passages and doesn’t return extracted fields.)
Troubleshooting
"Invalid JSON" error
"Invalid JSON" error
- Missing commas between properties
- Missing closing braces
} - Trailing commas (not allowed in JSON)
"Must have a type field" error
"Must have a type field" error
type. Usually this should be "object":"Must have a properties field" error
"Must have a properties field" error
type is "object" needs a properties object listing the fields to extract.Empty or missing extracted fields
Empty or missing extracted fields
- Ensure the field is marked as
requiredif it should always be extracted - Check that your field names clearly describe what to extract
- Verify the document actually contains the information
Extraction taking too long
Extraction taking too long
- Breaking into multiple smaller knowledge bases
- Removing non-essential fields
- Using a faster extraction model