Source documents and the extraction contract
Document extraction produces three distinct results: recognized characters, reconstructed relationships and interpreted fields. An invoice needs more than its words: parties, line items and totals must remain distinguishable. The extraction contract specifies what must survive, including the evidence supporting each value.
A born-digital document originates electronically; scans and photographs encode page appearance as images. One PDF can contain both. Optical character recognition, or OCR, recognizes text in images. A PDF text layer supplies extractable characters, sometimes invisibly over a page image. Its presence does not establish complete recognition or preservation of the original typography.
File coverage and submission completeness
ExampleProcessing available pages does not supply a missing document.
Read the diagram as text
- Inspect submission.
- Process available pages.
- Unavailable or partial.
- Reconcile expected documents.
- Submission complete.
- Receipt missing.
- Inspect submission → Process available pages: Readable input.
- Inspect submission → Unavailable or partial: Inspection fails.
- Process available pages → Unavailable or partial: Page processing fails.
- Process available pages → Reconcile expected documents: All available pages processed.
- Reconcile expected documents → Submission complete: Expected membership satisfied.
- Reconcile expected documents → Receipt missing: Required receipt absent.
A two-page invoice supplies a running example. Its application contract separates three responsibilities.
- Required information — Extract invoice INV-1042, its parties, date, currency, line items and stated total. Preserve unresolved fields. These requirements express fitness for purpose.
- Source identity — Retain original revision r1, distinguish its two pages from rendered images, and record whether opening required repair.
- Production history — Provenance records origins and production history. Bind derived locations to their source revision; retain extraction-attempt identity. Collection, identity and permitted use explains the broader responsibility.
A manifest records expected membership. For this submission, it requires the invoice and a delivery receipt. Enumerating both invoice pages establishes coverage of that file; it cannot establish that the missing receipt arrived. Document identity and page accounting must therefore remain separate from submission completeness.
Text recovery and transcription fidelity
Native extraction reads encoded text. Image recognition locates text regions and identifies their characters; implementations can combine these operations. A modular converter can reuse native text and coordinates while analyzing rendered images for layout and tables, avoiding unnecessary retranscription.
Deskewing rotates crooked text toward horizontal lines. Noise, uneven backgrounds, stroke thickness, skew and unsuitable borders can disrupt recognition. Segmentation settings distinguish a page from a line or isolated word. Language and dictionary configuration also matter: sentence-oriented corrections can damage identifiers. These are documented Tesseract considerations, not universal resolution thresholds.
| Observed problem | Mechanism and inspection |
|---|---|
| Duplicated text | OCRmyPDF 17.11 fixed removal that missed Form XObjects—embedded page-content containers—and consequently stacked another OCR layer. |
| Text damaged during archival conversion | Version 17.8 guards against substitution of non-embedded CID fonts, which use character identifiers, corrupting searchability during PDF/A conversion. PDF/A is an archival PDF format. |
| Incorrect search results after rewriting | Version 17.6 removes an embedded search index made stale by rewriting. Stale search metadata is different from an obsolete transcription. |
| Searchable PDF appears to contain spaces | Tesseract's FAQ describes reader-specific interpretation of hidden text. Checking another reader helps distinguish this from recognition failure. |
| Poor handwriting recognition | The Tesseract 4-era FAQ attributes this limitation to an engine designed for printed text; it does not characterize every document model. |
Preserve literal recognition before repair. If the invoice identifier is recognized as INV-1O42, replacing the letter O with zero creates an interpretation requiring evidence. A plausible identifier is not necessarily the printed identifier. Image-based recognition methods belong in Vision AI.
- Reprocessing changes preservation — Skipping text-bearing pages can leave image text unrecognized. Redo replaces recognized text; force rasterizes content. Text replacement can invalidate structural tags, and force can flatten interactive content.
- Inspect intermediate artifacts — Compare the rendered page, preprocessed OCR input and recognized text. On mixed pages, the OCR artifact need not contain all page text.
Document structure and reading order
An intermediate representation connects content records with structural relationships before export. DoclingDocument, for example, separates content items from body and furniture trees; furniture includes headers and footers. Parent-child links express containment, while ordered children express sequence. Representation-local pointers do not promise stable identity after regeneration.
Reading order is the meaningful sequence of content. Reading across two columns can join correctly recognized fragments incorrectly.
Same regions, different reading order
ExampleThe joins change while recognized text stays fixed.
Column-wise
A → B → C → D
Scroll sideways if the figure extends beyond the screen.
- 1. A
- 2. B
- 3. C
- 4. D
- 5. First join
- 6. Second join
- 7. Third join
Read coordinates and regions as data
X: 0–100 pixels; Y: 0–100 pixels, increasing down. Equal scale on both axes.
(8, 20); (45, 20); (45, 35); (8, 35)
(8, 55); (45, 55); (45, 70); (8, 70)
(55, 20); (92, 20); (92, 35); (55, 35)
(55, 55); (92, 55); (92, 70); (55, 70)
(26.5, 36); (26.5, 54)
(46, 62.5); (54, 27.5)
(73.5, 36); (73.5, 54)
A: Bill to: (26.5, 28)
B: Elm Lab: (26.5, 63)
C: Ship to: (73.5, 28)
D: West Depot: (73.5, 63)
Row-wise
A → C → B → D
Scroll sideways if the figure extends beyond the screen.
- 1. A
- 2. B
- 3. C
- 4. D
- 5. First join
- 6. Second join
- 7. Third join
Read coordinates and regions as data
X: 0–100 pixels; Y: 0–100 pixels, increasing down. Equal scale on both axes.
(8, 20); (45, 20); (45, 35); (8, 35)
(8, 55); (45, 55); (45, 70); (8, 70)
(55, 20); (92, 20); (92, 35); (55, 35)
(55, 55); (92, 55); (92, 70); (55, 70)
(46, 27.5); (54, 27.5)
(54, 35); (46, 55)
(46, 62.5); (54, 62.5)
A: Bill to: (26.5, 28)
B: Elm Lab: (26.5, 63)
C: Ship to: (73.5, 28)
D: West Depot: (73.5, 63)
| Representation | What it contributes |
|---|---|
| Plain text or ordinary Markdown | Readable exports need not retain geometry or every structural relationship; keep the richer representation when those connections matter. |
| hOCR | An HTML-based OCR format. A bounding box is a rectangle locating content; hOCR uses pixel coordinates from the image's top-left corner. |
| ALTO XML | A layout-and-text schema with ordering and processing references. |
Containment, sequence and association answer different questions. A picture belongs to a page, follows a paragraph and has a caption. Retaining the picture, caption and embedded text separately preserves those distinctions; a generated image description is another artifact.
Layout analysis assigns element roles and regions. Uncertain footnote links or cross-page continuations should remain inspectable candidate relationships, rather than disappearing into an irreversible text join.
Evidence spans and coordinate mappings
An evidence span selects source text. Text-position selectors use inclusive starts and exclusive ends. Store the text version and counting convention with those offsets: changing the representation can invalidate them. A polygon is a multi-sided spatial region useful when a rectangle fits poorly.
Coordinates require an origin, units and a reference image or page. PDF page coordinates use points; rendered images use pixels. Conversion depends on the actual page transform, including cropping and rotation. Normalized coordinates express positions relative to dimensions, but still need the associated frame. The example below uses image pixels throughout.
Locate evidence after crop and resize
ExampleLocal coordinates change; the supported source region remains identifiable.
Original render
Locate orange evidence inside the blue crop.
Scroll sideways if the figure extends beyond the screen.
- 1. Crop
- 2. Evidence
Read coordinates and regions as data
X: 0–400 pixels; Y: 0–400 pixels, increasing down. Equal scale on both axes.
(100, 200); (200, 200); (200, 280); (100, 280)
(120, 220); (160, 220); (160, 240); (120, 240)
(100,200): (100, 190)
Processed crop
Compare transformed regions with the original.
Scroll sideways if the figure extends beyond the screen.
- 1. Crop
- 2. Evidence
Read coordinates and regions as data
X: 0–400 pixels; Y: 0–400 pixels, increasing down. Equal scale on both axes.
(0, 0); (200, 0); (200, 160); (0, 160)
(40, 40); (120, 40); (120, 80); (40, 80)
Text editing needs a separate map. In USD 7.50, the amount occupies character span [5,9); after collapsing the doubled space, it occupies [4,8). Retain the source and destination spans. ICU's edit maps support this correspondence, but arbitrary replacements may provide only span-level alignment rather than exact internal character matches.
One field can need several text segments or page polygons. Its literal mention and normalized value remain separate. Located evidence establishes where to inspect, not whether the interpretation is correct.
Table structure and contextual meaning
Table structure organizes cells into rows and columns. Detection locates the table; structure recognition recovers cells, including cells spanning several rows or columns. Assigning text and interpreting header roles are further tasks. Accurate characters alone cannot establish correct records.
| Page | Item | Quantity | Unit price | Line amount |
|---|---|---|---|---|
| 1 | Cable | 2 each | 12.50 | 25.00 |
| 2 | Adapter | 1 each | 7.50 | 7.50 |
A price needs several relationships
ExampleCell text alone does not identify its meaning.
Read the diagram as text
- 7.50.
- Adapter.
- Unit price.
- USD.
- Table T1.
- Page-1 fragment.
- Page-2 fragment.
- 7.50 → Adapter: Row identity.
- 7.50 → Unit price: Column meaning.
- Unit price → USD: Currency qualifier.
- 7.50 → Page-2 fragment: Located in.
- Page-1 fragment → Table T1: Part of.
- Page-2 fragment → Table T1: Continues.
A cell may have several qualifying headers. Explicit associations retain row identity, column meaning and currency together. Attaching the correctly read 7.50 to Cable instead of Adapter produces a wrong record without changing a character.
For this fixture, page 2 continues the same table. Cross-page representations can group such rows, but automatic continuation still needs verification. Repeated headers, changed units and footnotes must be reconciled before joining unfamiliar fragments; documented multipage support is not evidence of reliable stitching.
Annotation rules must preserve different cell meanings.
- Blank versus zero — An empty cell is not the printed numeric value zero.
- Ditto versus unreadable — A repetition mark needs an identified antecedent; unreadable content remains unresolved.
Evidence-bearing fields and records
Key-value extraction associates a label with its value; repeated line items group related fields into records. These associations differ from containment. Textract illustrates the distinction with CHILD relationships for contained words and VALUE relationships between keys and values.
| Component | Value |
|---|---|
| Literal mention | 7.50 |
| Normalized interpretation | USD 7.50 per item; decimal point convention; currency supplied by the header |
| Evidence | Revision r1, page 2, price cell and qualifying header |
| State | Meaning |
|---|---|
| Absent | Expected field is not present in inspected content. |
| Illegible | Content exists but cannot be read. |
| Ambiguous | Several interpretations remain, as with an unqualified 03/04/2026 date. |
| Conflicting | Supported values disagree. |
| Extracted | A supported interpretation is recorded. |
Selection marks, such as checkboxes, encode visual state. Preserve selected or unselected status alongside the associated question and response option. No detection is not an unchecked mark: requested feature filtering can omit marks entirely.
Schema validation checks representation; semantic validation checks contextual rules. Neither independently proves factual correctness. Structured Outputs and Tool Calling owns these interface mechanisms. Here, reconciliation exposes a conflict while preserving both the stated and calculated totals.
Extraction routes and their evidence
| Route | Suitable condition | Evidence and limitation |
|---|---|---|
| Native parsing | Usable embedded text | Retains encoded text; image content may require separate recognition. |
| Modular conversion | Text and layout need separate recovery | Exposes intermediate regions and cells. Docling's original pipeline matches predicted cells to native PDF text, including borderless tables. |
| Template extraction | Stable, defined layouts | Uses visual layout cues; template changes reduce accuracy. |
| Image-to-structure | Task-specific page-image interpretation | Generates structured candidates; field coordinates and calibrated confidence are not automatic. |
A vision-language model processes visual and language information. OCR-free means no separate OCR dependency: Donut generates structured information from document images, but still learns to read them. Removing a separate recognition stage does not remove recognition errors.
Generated structure still needs evidence
ExampleAn integrated extraction route retains an acceptance boundary.
Read the diagram as text
- Page image.
- Structured candidates.
- Evidence and validation gate.
- Accepted.
- Unresolved.
- Page image → Structured candidates: Model generates.
- Structured candidates → Evidence and validation gate: Candidates submitted.
- Evidence and validation gate → Accepted: Required checks pass.
- Evidence and validation gate → Unresolved: Support missing or checks fail.
Routing can differ by page or region. Preserve surrounding headers when cropping, and retain disagreements between routes. In an extraction-first workflow, classifying a table as a picture sends it down the image path; downstream processing does not automatically restore the missing table relationships.
- Coverage versus processing cost — Optional OCR and image descriptions add work. Disabling them is appropriate only when their missing output is acceptable. The OpenRAG demonstration presents focused models and a document-specific VLM without a measured quality or latency comparison.
- Shared acceptance requirements — Evaluate every route against required fields and supporting evidence. Model architecture belongs in Vision AI; a simpler pipeline is not itself evidence of better extraction.
Correctness across recognition, structure and documents
For reference INV-1042 and prediction INV-1O42, one substitution among eight characters gives CER 12.5%. Treating each identifier as one word gives WER 100%. The differing scores describe counting units, not different errors.
Insertions are outside the reference-length denominator, so error rates can exceed one. Empty references need an explicit policy. Specify character units and word segmentation before comparing results.
| Check | Failure it can expose |
|---|---|
| Reading sequence | Correct words joined across unrelated columns. |
| Table relationships | Correct amounts attached to wrong rows or headers. GriTS separately evaluates topology, content and location. |
| Evidence localization | A field's text or page anchor points to the wrong supporting content. |
| Field-value matching | Missing, extra or incorrectly normalized values under an explicit matching rule. |
| Complete-document acceptance | Any required field, relationship or evidence check remains unsatisfied. Failed, partial and unresolved submissions remain in accounting. |
Normalization changes the evaluated task. Case folding, punctuation removal or whitespace changes can erase differences that raw scoring counts. Apply declared transformations consistently to reference and prediction; removing decimal punctuation is inappropriate when amount fidelity matters.
For exact field-value matching, precision is correct predicted pairs divided by all predicted pairs; recall is correct pairs divided by required reference pairs. A wrong value contributes an unmatched prediction and a missed reference pair. Abstention removes a prediction, not the requirement.
- Reference contract — Ground labels in source pages and document ambiguity rules. Reuse annotation and adjudication; report matching rules and denominators.
Uncertainty and accountable review
Recognition confidence concerns detected words; field confidence concerns associations. Neither alone establishes document acceptance. Missing important keys can require review regardless of scores.
An engine-specific score is not automatically a correctness probability. Calibration compares assigned probabilities with observed frequencies for a defined event. High-confidence structural mistakes also require validation and auditing.
Review is a route, not a result
ExampleMissing evidence and audits matter alongside scores.
Read the diagram as text
- Document checks.
- Accept.
- Targeted review.
- Alternative-attempt endpoint.
- Request resubmission.
- Unresolved or rejected.
- Document checks → Accept: Complete, passes, no audit selected.
- Document checks → Targeted review: Reviewable concern or audit sample.
- Document checks → Alternative-attempt endpoint: Alternative justified; budget remains.
- Document checks → Request resubmission: Required source unavailable.
- Targeted review → Accept: Resolved; all checks pass.
- Targeted review → Unresolved or rejected: Cannot resolve.
- Document checks → Unresolved or rejected: Unsupported; no recovery available.
- Review record — Retain source context, proposed value, failed check, reviewer decision and unresolved issues.
- Completion boundary — Abstention withholds an automatic result. Straight-through processing completes a case without manual review. Sending work to a reviewer completes neither extraction nor resolution.
Lower accepted error can result from accepting fewer documents rather than improving extraction. Report coverage alongside accepted error, unresolved outcomes and review workload. Compare thresholds on labeled cases representative of the intended document population.
Corrections and dependent outputs
A source revision changes the document; an extraction attempt changes its processing; a reviewer correction changes an interpretation. Preserve all three separately. Record parser, model, configuration and schema versions. Revision fields alone do not implement a correction lifecycle.
Use application identities to reconnect reviewed elements after regeneration. A corrected cell association invalidates dependent records, even if its text is unchanged. Recheck affected outputs without erasing the original observation or reopening unrelated decisions.
Correction invalidates dependent output
ExampleHistory remains; eligibility changes.
Retain observation.
Read the diagram as text
- Cell C17.
- Original: Cable.
- Reviewed: Adapter.
- Export e1.
- Previously eligible.
- Now stale.
- Export e2.
- Mapping validated.
- Cell C17 → Original: Cable: Observed.
- Cell C17 → Reviewed: Adapter: Corrected.
- Original: Cable → Export e1: Produced.
- Export e1 → Previously eligible: Status.
- Export e1 → Now stale: Status.
- Reviewed: Adapter → Export e2: Rebuilds.
- Export e2 → Mapping validated: Status.
- Original. Retain observation. Active: Cell C17, Original: Cable, Export e1, Previously eligible. New: Cell C17, Original: Cable, Export e1, Previously eligible.
- Corrected. Withdraw old eligibility. Active: Cell C17, Original: Cable, Export e1, Reviewed: Adapter, Now stale. New: Reviewed: Adapter, Now stale.
- Rebuilt. Validate replacement mapping. Active: Cell C17, Original: Cable, Export e1, Reviewed: Adapter, Now stale, Export e2, Mapping validated. New: Export e2, Mapping validated.
- Controlled replacement — Compare regenerated outputs with retained review decisions before restoring eligibility. Reproducible lineage supplies the broader versioning model; processing-history metadata does not guarantee this application policy.
Context-preserving downstream handoff
A chunk is a selected portion of document content; an index is a structure used to find content. Their implementation belongs in Search and Retrieval. Structure-aware handoff can retain headings and captions and repeat table headers so independently consumed rows keep their meaning.
| Payload | Required companion |
|---|---|
| Passage or record | Headings, headers, units and relevant footnotes |
| Derived information | Source revision, extraction version, evidence selectors, unresolved states and applicable access metadata |
Resolve exported content to evidence
ExampleSearchable derivatives remain connected to original content.
Read the diagram as text
- Exported record or summary.
- Headers, units, qualifiers.
- Version-specific evidence mapping.
- Original revision and page.
- Exported record or summary → Headers, units, qualifiers: Interpreted with.
- Exported record or summary → Version-specific evidence mapping: References.
- Version-specific evidence mapping → Original revision and page: Resolves to.
Generated descriptions remain model interpretations, separate from extracted captions and original pictures. Enrichment can add useful searchable language without replacing the evidence it describes.
Open questions
Reliable multipage continuation remains difficult when repeated headers resemble new tables or qualifiers change. Wrong joins corrupt whole records. Progress requires source-annotated unfamiliar layouts where continuation and separation decisions preserve row identity and units.
Corrections need durable correspondence across length-changing text edits and regenerated representations. Exact internal alignment may be unavailable, making automatic replay unsafe. Progress means identifying which reviewed spans still map uniquely and explicitly withholding ambiguous transfers.
Automatic acceptance under document drift remains unresolved when structural mistakes receive high scores. Lower acceptance can conceal rather than fix failures. Progress requires joint evidence on accepted error, coverage and review burden across new layouts, including audits of apparently successful cases.




