What Are Extraction Rules?
Extraction rules are custom instructions you can add to any field in your schema. They tell the AI exactly how to find and extract specific data, improving accuracy for complex or ambiguous documents.Rules are a Parsefy extension to JSON Schema. They’re not part of the standard spec but are fully supported by our API.
Adding Rules
Add arules array to any field definition:
Rule Examples
Finding Specific Fields
Handling Ambiguity
Date Formatting
Table Extraction
Complete Example
Here’s a receipt extraction schema with comprehensive rules:Rule Writing Tips
Be Specific
Mention exact labels and positions the AI should look for.
Handle Edge Cases
Include fallback instructions for when the primary approach doesn’t work.
Prevent Confusion
Explicitly state what NOT to extract to avoid mixing similar fields.
Keep It Short
Each rule should be one clear instruction. Multiple short rules beat one long paragraph.
Effective Rule Patterns
- Location Hints
- Label Alternatives
- Format Instructions
- Negative Rules
Using Rules with SDKs
Python (Pydantic)
Usejson_schema_extra to add rules:
TypeScript (Zod)
Use.describe() with detailed instructions:
The Zod SDK doesn’t directly support rules arrays, but you can include rule-like instructions in the description. The AI will follow them.
