How to Split Long Documents for Extraction: Batches, Overlap and Reassembly
How to split long documents for extraction: size batches from measured tokens per page, choose section or page windows, overlap pages, carry table headers, reconcile conflicts across batches and reassemble with provenance.
- To split a long document for extraction, divide it into the smallest batches that keep every field and its evidence together, sized from tokens per page you measured on your own pages, never from a published figure.
- Section boundaries are the better split for documents with real structure, while fixed page windows are the fallback for unstructured scans, and both need overlap pages so a table or total that crosses a break lands whole in one call (author design).
- When the same field is found in two batches, apply a written precedence rule and flag disagreements for review, because silent last-write-wins hides exactly the conflicts a long document produces (author design).
- Reassembled long-document records should carry per-field provenance, meaning page references, a batch id, and parser, model and schema versions, so one failed batch can be retried without re-running the whole document (author design).
- A document that fits comfortably in one call should not be split at all, because every extra batch adds a reconciliation step and a new place for a boundary error (author inference).
Splitting long documents for extraction means cutting a file into batches small enough to fit the model's context and output budget, while keeping each field's evidence inside one batch. The Document Extraction and Parsing for Agents reference (updated 2026-09-28) treats parsing and field extraction as separate stages, and splitting sits between them. The AI document extraction pipeline pillar covers the whole system; this piece covers only how to size and recombine the unit. Anything not cited to a reference is author inference or author design, labelled as such. Numbers in the examples are illustrative, not measurements.
Do not split a document that fits in one call with room left for the output, because each batch adds a boundary and a reconciliation step. A single call sees every page, so a total on page 9 and its line items on page 3 meet naturally. Split only when measured tokens, the output budget or the accuracy on late pages forces it (author inference). Run the pilot below on your longest documents first; if they fit, stop here.
Size a batch by measuring tokens per page on your own pages, then dividing the usable budget by that figure. The Multimodal Agents reference (updated 2026-10-04) says image tokens scale with resolution and that formulas differ by provider and model version, so a number borrowed from another setup will mislead. The method is author design:
- Take a pilot of 20 or more real documents, including your longest and densest.
- Count input tokens per page at the resolution you will ship, using the provider's own counter, for both parsed text and page images.
- Run the schema on those pages and record output tokens per page, and per densest table.
- Compute the pages per batch from both limits and take the smaller result.
| Quantity | Where it comes from | Notes |
|---|---|---|
| Input tokens per page | Pilot count at shipped resolution | Pages vary; use the high end of the range, not the mean |
| Fixed prompt and schema tokens | Count once per call | Paid again on every batch |
| Output tokens per page | Pilot run of the schema | Dense tables dominate |
| Safety margin | Your choice | Leaves room for the page you did not sample |
Illustration only: if a pilot showed 1,800 input tokens per page at the high end and 40,000 usable input tokens after the prompt, that gives 22 pages by input; if output ran 700 tokens per page against a 4,000-token output limit, that gives 5 pages by output. The output limit wins, so batches would be 5 pages. Those numbers are invented to show the arithmetic. How batch count feeds cost is in cost per page for document extraction.
Prefer section boundaries when the document has reliable structure, and use fixed page windows only when it does not. The rule from OCR versus vision model versus hybrid document parsing is to size the call to the smallest span containing all the evidence for a field. Splitting at sections is that rule applied to a long file; this is extraction-unit sizing, not retrieval chunking, which is in chunking documents for RAG.
| Split | Strength | Weakness |
|---|---|---|
| Section boundaries | Related fields stay together; batches map to schema parts | Needs trustworthy headings or a table of contents; sections can exceed the budget |
| Fixed page windows | Predictable cost and batch count | Cuts tables and totals; ignores meaning |
| Section first, windows inside oversized sections | Keeps structure, bounds size | Two code paths to test |
The third row is the usual compromise (author inference). If section detection is itself a model call, treat its output as unverified and fall back to windows when it returns gaps.
Decide the overlap from the evidence your pilot shows, and keep it small. The neighbouring-page rule for a table or total cut by a page break is already set out in OCR versus vision model versus hybrid document parsing; what a long document adds is that every batch edge now needs it. Page overlap here is a whole-page repeat between extraction calls, unlike the token overlap used for retrieval in chunking documents for RAG. Extend the overlap when the pilot shows a table running further than one page (author design). Overlap costs tokens on every batch and creates duplicate candidates, so each overlapped page needs the reconciliation rules below.
Carry the header row into every batch the table touches, and tell the model which rows are continuations. Give each batch the table's column names and the last row index seen, then emit rows with their page numbers so reassembly can stitch them. Do not rely on the model to infer headers on page 7 of a table that started on page 3 (author design). Merging fragments, dropping repeated headers and checking row counts and totals are covered in table and form validation for document extraction; this section only gets the rows to that step intact.
Reconcile with a written precedence rule and a conflict flag, never with the order in which batches happened to finish. Last-write-wins is silent: it picks one value and discards the evidence that another batch disagreed. The rule below is author design.
- Equal values: keep one, record both sources.
- Different values, one labelled: prefer the batch where the field appears with its label and surrounding evidence, such as the page that prints "Total due".
- Different values, no clear winner: keep none, mark the field conflicted, and send it onward as a review reason.
- Present in one batch only: accept it, since absence in an unrelated batch is not disagreement.
Store the losing candidate and its page reference beside the winner. Routing conflicts to people is the job of human review fallback for document extraction; here the flag simply has to exist.
Reassemble in page order, attach provenance to every field, and refuse to emit a record until the page ledger is complete. For each field keep page references, the batch id, and the parser, model and schema versions that produced it. The same stamps are what a later migration needs, as described in extraction schema versioning for document pipelines.
{
"field": "invoice_total",
"value": "1240.00",
"pages": [9],
"batch_id": "doc-7f3a:p07-p10:v3",
"parser": "parser-x@1.4",
"model": "model-y-2026-09",
"schema": "invoice@3",
"conflict": null
}
The identifiers above are placeholders. Completeness checks are the part teams skip. ChangeGamer runs no document extraction, but its build loader in src/lib/articles.ts is a useful analogy: as of October 2026 it throws on a missing or duplicate targetQuery, requires every sub-article to link its pillar, and marks a cluster complete only if the pillar links every sub and the sub count equals the planned total. Reassembly deserves the same posture: a record is complete only when every expected page and batch is accounted for.
Give every batch a deterministic id built from the document id, the page range and the schema version, so the same batch always has the same key. Retrying then overwrites that batch's result instead of adding a second one, and the reassembler can tell a retried batch from a new one. The delivery side of this idempotency, writing to a system of record, is in feeding extraction output into a system of record. Include the parser and model versions in the id only if you want a version bump to invalidate stored batches (author design).
Build a ledger of expected pages before any call, and fail the document if a page is missing, duplicated or out of sequence. Pages can go missing or arrive out of order between scan and upload, and extraction will still return plausible-looking values for the pages it was given. Compare the parser's page count with the file's and the printed page numbers where they exist, and sort by page index, not by arrival time (author inference).
Treat any max_tokens stop reason as a failed batch. The Structured Outputs and JSON Mode reference (updated 2026-09-26) states that refusal and max_tokens stop reasons bypass the schema guarantee, so a cut-off object may not match the schema (author inference: it may also be incomplete without any error). Retry with fewer pages or a larger output budget, sized from the densest table in the pilot; provider settings and failure branches for the schema itself are in schema-constrained field extraction from documents. Count these retries separately, because a rising truncation rate means the batch size no longer fits the documents (author inference).
Frequently asked questions
- How many pages should each extraction batch contain?
- The number of pages per extraction batch has no universal value; compute it from tokens per page measured on a pilot of your own documents, plus the output tokens your schema needs per page, against the context and output limits of the model you pin. Image-token formulas differ by provider and model version, so measure with the provider you actually call (author design).
- Should I split a long document by section or by fixed page count?
- Split by section when the document has reliable structure such as headings or a table of contents, and fall back to fixed page windows with overlap when it does not. Section boundaries keep related fields together, while fixed windows are predictable but can cut a table or total in half (author inference).
- What happens when the same field appears in two batches?
- When a field appears in two batches, a written precedence rule should pick one value and a conflict flag should be raised if the values differ. Typical rules prefer the batch where the field has its label and the most surrounding evidence, and never overwrite silently (author design).
- How do I handle output truncation on long extractions?
- Treat a max_tokens stop reason as a failed batch, not a partial success, because the structured-outputs reference says max_tokens bypasses the schema guarantee. Retry that batch with fewer pages or a larger output budget, and size the budget from the densest table you expect.
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.