Overview
Math Verification transforms Parsefy from a probabilistic extraction tool into a deterministic verification platform. When enabled, Parsefy automatically verifies that extracted numeric data is mathematically consistent.Validated output or fail loudly. Math verification ensures totals match subtotals + tax, line items sum correctly, and cross-field calculations are accurate.
How It Works
1
Schema Analysis
Parsefy scans your schema for verifiable fields (totals, subtotals, taxes, line items)
2
Rule Synthesis
Mathematical rules are automatically generated based on detected field roles
3
Secure Evaluation
Extracted values are verified against the synthesized rules
4
Result Reporting
Verification results are included in the API response
Enabling Verification
Verification Response
Whenenable_verification is set to true, the response includes a verification object:
Verification Status Values
| Status | Description |
|---|---|
PASSED | All math checks passed |
FAILED | One or more math checks failed |
PARTIAL | Some checks passed, some failed or couldn’t be verified |
CANNOT_VERIFY | Required fields are missing (not a math error) |
NO_RULES | No verifiable fields detected in schema |
Supported Verification Rules
| Rule Type | Formula | Example |
|---|---|---|
| HORIZONTAL_SUM | total = subtotal + tax | Invoice total verification |
| VERTICAL_SUM | subtotal = sum(items) | Line item sum verification |
Check Result Fields
Each check inchecks_run contains:
| Field | Type | Description |
|---|---|---|
type | string | Type of check: HORIZONTAL_SUM or VERTICAL_SUM |
status | string | Check status: PASSED, FAILED, or CANNOT_VERIFY |
fields | array | Fields involved in this check |
passed | boolean | Whether the check passed |
delta | number | Difference between expected and actual values |
expected | number | Expected value from the verification rule |
actual | number | Actual value extracted from the document |
Shadow Extraction
When verification is enabled and only a single verifiable field is requested (e.g., justtotal), Parsefy automatically extracts supporting fields in the background:
- User requests:
{ "total": { "type": "number" } }withenable_verification=true - Parsefy internally expands to include shadow fields:
subtotal,tax,line_items - LLM extracts all fields
- Math verification runs
- Shadow fields are removed before response
Best Practices
Include Verification Fields
For best verification, include
subtotal, tax, and total in your schemaUse for Financial Data
Enable verification for invoices, receipts, and bills where math accuracy is critical
Handle Failures Gracefully
When verification fails, flag for manual review rather than rejecting outright
Check Individual Results
Review
checks_run to identify which specific calculations failed