ChangeGamer

Table and Form Validation for Document Extraction: Row Counts, Totals and Required Fields

Part 3 of Document extraction pipelines in production · 1,572 words · ~7 min read · published · updated · Markdown variant

Validating table and form extraction from documents: rows split across pages, subtotal rows, exact money reconciliation, column sums, required-field maps per form type, cross-field checks and a failed-check-to-route table.

In short

  • Validating a table extracted from a document starts with classifying every row as item, subtotal, tax, total or repeated header before counting, because only item rows belong in the row count (author design choice).
  • Money reconciliation should compare exact decimal or integer minor-unit values, and a rounding tolerance is justified only when the document itself rounds per line, in which case the tolerance should be a stated number of minor units per row (author inference).
  • A required-field map per form type, with conditional-required fields such as a credit note needing the original invoice reference, turns "field presence" into a testable rule instead of a general instruction (author design choice).
  • The structured outputs reference lists no numeric or string constraints such as minimum or maxLength for Anthropic structured outputs, so amount reconciliation belongs in your own code (author inference).
  • As of October 2026 ChangeGamer parses no documents and has no extraction accuracy numbers, so the rules here are design inference to test on your own labelled sample.

Part of the AI Document Extraction in Production: Parse, Extract, Validate, Review guide.


Table and form extraction is valid only when you can prove four things after the model has answered: the right rows were counted, the money reconciles, the required fields for that form type are present, and the fields agree with each other. This article is the value-checking step that follows schema-constrained extraction and a parser chosen as in OCR vs vision model for document parsing. The AI document extraction pipeline pillar owns the validation layers; here is the table- and form-specific detail. Facts cite the Document Extraction and Parsing for Agents reference (updated 2026-09-28) and the Structured Outputs and JSON Mode reference (updated 2026-09-26). Everything else is author inference or a design choice, and says so.

Why do table checks belong in your code and not in the schema?

Table checks belong in your code because schema keywords are unlikely to express them. The structured outputs reference lists no numeric or string constraints such as minimum and maxLength for Anthropic's structured outputs, which rules out an amount-sum rule in the schema; that a schema also cannot say "this field is required when that one is set" is the author's inference. The extraction reference lists merged table cells among the hard cases to test, places complex table spans in its OCR-and-layout tier, and advises cross-validating high-stakes values. The rules below are the author's design for doing that.

How do you validate a table that continues across pages?

Merge the page fragments into one logical table first, then validate the merged result. A multi-page table repeats its header on each page, may split one row across a page break, and may restart row numbers or carry a "continued" marker (author inference, from how such documents are commonly laid out).

Suppose a purchase order table runs over three pages. A workable merge order, all design choice:

  1. Drop repeated headers. A row whose cells equal the first page's header cells is a header, not data.
  2. Join split rows. A page ends with a partial row (a description but no amount) and the next page starts with the remainder; join them when the first fragment lacks a required cell and the second lacks the first cell.
  3. Keep the page of origin on every row so a reviewer can find it.
  4. Compare counts. If the document numbers its lines, the highest line number should equal the item-row count; a gap or duplicate is a failure.

If the schema was filled per page, the merge belongs in code after extraction. If the whole table was extracted in one call, the same checks still apply to the output.

Which rows count as item rows?

Only rows that describe a billed thing count as item rows; subtotal, discount, shipping, tax and total rows are separate classes. Counting them together makes the row count wrong whenever a document prints a subtotal, and a total row summed with the items doubles the amount (author inference).

Row class Counts toward row count Counts toward item sum
Item Yes Yes
Subtotal No No (use as a check target)
Discount or shipping No Only if your rule says so
Tax No No (check separately)
Total / balance due No No (check target)
Repeated header No No

Make the class an explicit field in the extraction schema (an enum with an escape value, as sub 2 recommends) so the model labels the row and your code can disagree with it. A subtotal in the middle of a long table is also a checkpoint: validate each segment's sum against its own subtotal and you learn which page the error is on.

How should money be reconciled: exact or with a tolerance?

Compare exactly, using decimals or integer minor units, unless the document is known to round each line separately. Converting amounts to minor units (cents for two-decimal currencies) before comparing removes float noise, and the pillar already shows decimal arithmetic. A currency with a different number of decimal places (general knowledge, not from the corpus) needs its own scale, so derive it from the currency code rather than assuming two.

A tolerance is justified only when line-level rounding exists in the document itself: tax computed and rounded per line, then summed, can differ from tax computed once on the subtotal. In that case allow a stated number of minor units per rounded row, and write the number down as a decision with an owner (design choice). Do not use a percentage: a percentage tolerance grows with the total and can hide a transposed digit on a large invoice. This site has no data on which tolerance suits which tax regime, so none is given.

What if the document states no total?

If no total is printed, the column sum becomes a consistency signal that cannot be verified, so say so in the record. Compute it, store it as computed_total, set total_stated to false, and route by the stricter rule for that document type. Never copy the computed sum into the stated-total field; a derived number presented as an extracted one is the error this check exists to prevent (design choice).

What does a required-field map look like per form type?

A required-field map lists, for each document type, the fields that must be present, the fields that must be present only when a condition holds, and the fields that may be null. The map is data, not prompt text, so it can be reviewed and versioned. This one is illustrative (design choice); your obligations differ by jurisdiction and customer.

Field Invoice Credit note Purchase order
Document number Required Required Required
Issue date Required Required Required
Currency Required Required Required
Original invoice reference Not applicable Required Not applicable
Tax identifier Required if tax amount is above zero Required if tax amount is above zero Optional
Delivery date Optional Not applicable Required if lines exist
Total Required Required Optional

The conditional entries are where schemas fail: an optional field that becomes required depends on another value. Express each as a small function over the whole record and return a reason code naming the unmet condition. Sub 2's nullable-field rule still holds, since "absent" must stay a valid answer; the map decides when absent is acceptable.

Which cross-field checks catch the errors that totals miss?

Cross-field checks catch errors that internal sums cannot, because a record can reconcile and still be wrong. Three are cheap (all design choice; the currency-decimals, shared-symbol and locale-separator facts are general knowledge, not from the corpus):

What route should each failed check take?

Each failed check should map to a named route in advance, chosen by what the failure means. The table classifies and names the route only; thresholds and queue design live in the review article of this cluster. Routes are the author's design.

Failed check Likely cause Route
Item-row count differs from the highest line number Dropped or duplicated row at a page break Re-extract with a changed scope, else review
Item sum differs from the stated subtotal Misread amount or a misclassified row Review, showing the page of the failing segment
Required field missing Absent on the document, or unread Review if the map requires it, otherwise accept null
Conditional-required unmet Missing dependent value Review with the reason code
Date check violated Date misread or swapped Review
Symbol and currency code disagree Ambiguous symbol Review
Total not stated Document design Stricter review route for the type

Re-extraction follows sub 2's one-retry cap; this table does not add a second retry.

What does ChangeGamer know first-hand about failing loudly?

As of October 2026 ChangeGamer parses no documents and has no extraction accuracy numbers, so none of the rules above is measured on its own data. One verifiable adjacent fact is how its build treats a broken reference: the cluster checks in src/lib/articles.ts throw when an article body links an /articles/ URL that does not exist, and the build stops. A failed reference check is a hard stop there, not a warning. That is the stance behind the routes above: a failed check should produce a named outcome, not a quiet pass.

Frequently asked questions

How do you validate a table that continues across several pages of a PDF?
Merge the page fragments into one logical table before checking anything, dropping repeated header rows and carrying a row that is split at a page break into a single record. Then run row counts and totals on the merged table, never per page (author design choice).
Should extracted invoice amounts be compared with a tolerance?
Compare exactly by default, using decimals or integer minor units. Allow a tolerance only when the document is known to round each line separately, and then express it as a fixed number of minor units per line rather than as a percentage (author inference).
What should a pipeline do when a table has no stated total to check against?
Treat the column sum as a consistency signal, not proof. A sum that matches nothing on the page cannot be verified, so record "total not stated" as a reason code and apply the stricter review route for that document type (author inference).
Can a JSON schema enforce required fields that depend on other fields?
Not reliably across providers. The structured outputs reference lists schema limits for Anthropic, including no numeric or string constraints, so conditional-required rules such as "credit notes need an original invoice reference" are safer as code that runs after parsing.

#document-extraction #validation #tables #forms #reconciliation #production

Put this corpus inside your own agents

This guide is free and stays free. The reference corpus behind it — machine-readable contracts, verified primary sources, continuously refreshed — is the paid product: a €5 starter key unlocks every premium reference for one agent via API; a €25 corpus license delivers the full corpus as RAG / fine-tuning data with an explicit AI-use grant; the €150 enterprise license adds commercial redistribution rights.

Agents: this page as Markdown · JSON · offers at /api/pricing.json · payment methods at /api/payment.json · single-resource access via HTTP 402 (how that works)