Skip to main content

What is a Schema?

A schema defines the structure of data you want to extract from your documents. Parsefy uses JSON Schema to understand exactly what fields to extract, their types, and any validation rules.
If you’re using our SDKs, you can define schemas using Pydantic models (Python) or Zod schemas (TypeScript) instead of raw JSON Schema.

Basic Structure

Every Parsefy schema is a JSON object with these key properties:

Schema Properties

Add description to each field to help the AI understand what to extract. Field-level descriptions are much more valuable than top-level schema descriptions.

⚠️ Required vs Optional Fields (Critical for Billing)

All fields are required by default in both SDKs. This significantly impacts your costs because required fields that return null or fall below the confidence threshold trigger the expensive fallback model.

How It Works

Why This Matters

If a required field returns null or falls below the confidence_threshold:
  1. The API automatically triggers the fallback model (Tier 2)
  2. Tier 2 is significantly more expensive
  3. Your costs increase unexpectedly

Best Practice: Mark Optional Fields

Rule of thumb: If a field might be missing in >20% of your documents, mark it as optional.

Field Types

Parsefy supports all standard JSON Schema types:
For integers only:

Complete Financial Document Schema

Here’s a comprehensive invoice extraction schema with proper required/optional fields:

Best Practices

Use Descriptions

Always add description fields. They help the AI understand what to look for and where.

Be Specific

“Invoice date in YYYY-MM-DD format” is better than just “date”.

Mark Optional Carefully

Fields missing in >20% of documents should be optional to avoid costly fallbacks.

Use Appropriate Types

Use number for amounts, integer for counts, string for text.

Do’s and Don’ts

The _meta Field

Parsefy automatically injects a _meta field into every extraction response with field-level confidence:
You don’t need to include _meta in your schema; it’s added automatically.

Next Steps

Extraction Rules

Learn how to use custom rules to improve accuracy

Confidence Scores

Understanding the confidence scoring system