Skip to main content

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 financial documents (invoices, receipts, bills).
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 a rules 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:
Remember: Fields in the required array that return null or fall below confidence_threshold trigger the expensive fallback model. Only require fields that are always present.

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

Using Rules with SDKs

Python (Pydantic)

Use json_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.

Next Steps

Confidence Scores

Understanding extraction quality metrics

API Reference

See the full extract endpoint documentation