An AI agent can quote every visible word of a PDF and still be wrong about what the document says. The cause is often not language-model reasoning: it is document geometry. A two-column page can be extracted line by line across both columns, a footer can land inside a sentence, a scanned figure can contain unrecognised text, and the printed page label can differ from its position in the file. If an agent then cites “page 10” without distinguishing labels from physical pages, a reader may never find the evidence.
A safe PDF-reading system preserves the original document identity, physical page index, printed page label, reading sequence, text or image region, table structure, and uncertainties from extraction. It compares the proposed reading order with the rendered page before asserting a citation. This is practical AI-agent engineering, not evidence that artificial superintelligence already exists. The model is only one component; the extraction and verification contract determines whether the answer can be audited.
Contents
- The job is source reconstruction, not just text collection
- Why PDF storage order differs from reading order
- Physical pages, labels and visible numbers are three things
- Build a source map before answering questions
- Tagged PDF offers structure, but tags need validation
- Inspect the reading sequence in a page viewer
- Reading order must preserve grammatical neighbours
- The two-column failure case
- An end-to-end citation for the worked case
- Table cells are not ordinary paragraphs
- Headers, footers and repeated navigation text
- Footnotes can change the whole comparison
- Figures require description, not imaginary text
- Scans and OCR introduce a different uncertainty
- Mixed PDFs need page-by-page methods
- Hyphenation and wrapped words
- Unicode, scripts and mathematical notation
- Document versions must remain distinguishable
- Retrieval chunks need anchored boundaries
- Search hits are suggestions, not verified evidence
- Separate extraction confidence from claim confidence
- An error taxonomy that leads to repair
- The test oracle needs a human-readable answer
- A practical audit using precision and coverage
- Review budgets should follow consequence
- Privacy and permission boundaries
- Citations should survive a reader test
- A changed-context transfer problem
- When an automated answer should abstain
- Frequently asked questions
- Sources and learning routes
The job is source reconstruction, not just text collection
When someone uploads a report and asks “What changed between 2024 and 2025?”, they expect the agent to find the relevant table, interpret its headers, calculate the difference and cite a location they can inspect. Simply collecting all printable characters into a string does not supply those relationships. Layout conveys semantics through columns, indentation, alignment, captions, footnotes, headings and the ordering of fragments. An extraction system that flattens away structure may destroy the very evidence required for the question.
A useful design starts with two layers: a faithful representation of what the document contains and an interpreted layer that supports search or questions. The faithful layer should not be silently rewritten when the model guesses a better reading order. Keep original bytes or an appropriately governed source reference, stable document identity, page-indexed renderings where permitted, extracted units with locations and explicit transformation records. The interpreted layer can then be corrected without inventing a new original.
Why PDF storage order differs from reading order
PDF is primarily a page-description format, capable of placing text and graphics at coordinates. The order in which drawing instructions or character runs occur in a file does not necessarily match the order a person reads. A creator may draw every heading first, then the body text, or write two newspaper columns as alternating fragments. Copying raw text can therefore yield “Revenue Cost grew fell” where the visually intended statements are separate sentences in separate columns.
This issue is not hypothetical software folklore. The Apache PDFBox PDFTextStripper API documents that text tokens can be out of visual order and exposes position-sorting controls. Sorting coordinates helps some pages but cannot solve every semantic ambiguity: across columns, sidebars, charts and unusual scripts, a simple top-to-bottom rule can be exactly the wrong rule.
Physical pages, labels and visible numbers are three things
A PDF page index is a position in the file, usually zero-based in programming interfaces. A physical page number can be reported to humans as index plus one. A document may also provide a page label such as “iv”, “A-2” or “10”; the label printed inside the page may not match either one. A robust citation can identify all relevant coordinate systems without pretending that they are interchangeable.
Consider a fictional 17-page annual report. The first three physical pages are preliminary pages labelled i, ii and iii; the subsequent 14 physical pages are labelled 1 through 14. Printed page 10 is therefore the thirteenth physical page, whose zero-based PDF index is 12. A citation saying only “page 10” may be correct for a human reading the report but wrong for a viewer that jumps to physical page 10. Write “printed p. 10; file page 13 of 17” when the reader needs both. The arithmetic is 3 + 10 = 13, and the index is 13 − 1 = 12.
Build a source map before answering questions
For each extracted evidence unit, record a stable document ID, immutable revision or file fingerprint when permitted, physical page index, observed printed label, bounding region or tagged structural path, extraction method, ordered text, detected language, and uncertainty markers. Page labels should be fields rather than substitutions for indices. If a report is later replaced with another file of the same name, a source map bound only to its filename is not sufficient.
The source map lets reviewers ask not merely “Where did this answer come from?” but “Which bytes and which page region produced this sentence?” A citation can then connect a claim to a span, table cell or figure. This does not require publishing private source files or exposing their hashes to everyone. It requires the system to retain enough authorised traceability internally and to produce a reader-usable reference appropriate to access rights.
Tagged PDF offers structure, but tags need validation
A properly tagged PDF can include a logical structure tree representing headings, paragraphs, tables and other relationships. Assistive technologies use such structures to present content in meaningful sequence. The W3C guidance on meaningful sequence explains the principle: where sequence affects meaning, a correct reading sequence must be programmatically determinable. This is a valuable foundation for trustworthy agent extraction as well as accessibility.
Do not assume that the presence of tags proves their correctness. Automated tagging can misclassify a figure, skip a decorative element that actually carries meaning, or put a caption in the wrong place. A PDF may also be untagged. An agent should record whether it relied on tags, coordinates, OCR or a human-verified correction. The extraction method is evidence provenance, not an invisible implementation detail.
Inspect the reading sequence in a page viewer
A visual page can have multiple plausible linear reading sequences when independent callouts or sidebars exist. The agent’s job is to preserve relationships that change meaning, not force every object into one arbitrary top-to-bottom chain. For a two-column article, finishing the left column before starting the right may be essential. For a table, walking each complete row with its header associations is normally more meaningful than reading all numbers in the left half followed by all numbers in the right half.
The Adobe Acrobat Reading Order tool guidance describes checking highlighted regions and correcting logical sequence. We cite that official explanation for the concept, not as a claim that this article’s fictional report was opened in Acrobat. A review process can compare the agent’s proposed order with the rendered image and capture exceptions that require manual attention.
Reading order must preserve grammatical neighbours
If “not” appears at the end of one extracted text run and “approved” at the start of the next, losing one run reverses the decision. If a line break inserts a new paragraph between an adjective and its noun, a reader or model may invent a separate claim. An extractor should preserve normal word spacing and punctuation while retaining enough raw location data to check surprising joins. It must not treat a high language-model confidence score as proof that the reconstruction is faithful.
A useful diagnostic is a round-trip reading exercise. Select short, high-impact passages in the extracted text, display their regions on the source page and ask whether every negation, unit, qualifier, heading and reference belongs where the extracted sequence places it. If a sentence cannot be reconstructed from the visible source without guessing, label it uncertain or omit it from the asserted answer. That is a better outcome than confidently fabricating the connection.
The two-column failure case
Imagine a fictional PDF page with two columns. The left column reads “2024: 60 complete out of 120 inspected”. The right reads “2025: 90 complete out of 150 inspected”. A naive line-sorting extractor might emit “2024: 60 2025: 90 complete out of 120 complete out of 150 inspected inspected”. A language model could then accidentally pair 90 with 120 or claim there were 150 completions. Both errors come from losing column boundaries before doing mathematics.
The intended computations are 60/120 = 0.50 = 50% in 2024 and 90/150 = 0.60 = 60% in 2025. The change is 60 − 50 = 10 percentage points; the relative increase in the completion rate is (0.60 − 0.50)/0.50 = 0.20, or 20%. These are different descriptions, and neither follows from the raw numbers unless the column headers and denominator associations are preserved.
An end-to-end citation for the worked case
In the fictional 17-page report, suppose the comparison appears inside a table on printed page 10, physical page 13, PDF index 12. A suitable answer says that completion rose from 50% (60/120) in 2024 to 60% (90/150) in 2025, a 10-percentage-point increase, and identifies the table, printed label and file page. This provides a path for a person to recompute the claim. The citation should not use a fabricated public URL for a fictional document.
A machine-readable evidence record can additionally contain the coordinates of the four numeric cells and their row and column headers, perhaps with a table identifier and an extraction confidence flag. If the header “Completed” is uncertain, the agent should not bury that uncertainty beneath correct arithmetic. Arithmetic over mislabelled quantities remains an incorrect interpretation. Verification begins with the object meanings, not with the calculator.
Table cells are not ordinary paragraphs
Tables express relationships by position and header scope. A numeric value of 150 means little unless the cell is attached to the right year, measure and unit. Merged headers, multi-line labels and repeated header rows complicate parsing. A safe document workflow represents table cells as structured records and preserves header hierarchy rather than concatenating row text into vaguely readable sentences. The reader should be able to inspect which cell supplied the numerator and which supplied the denominator.
Our related agent HTML table extraction article discusses spanning headers and verified cells in web pages. PDF geometry introduces different technical problems, but the evidence contract is similar: no numerical claim without a reliable mapping from value to label. Where a PDF table is visually encoded but not structurally tagged, additional verification is warranted.
Headers, footers and repeated navigation text
A report may repeat its organisation name, copyright notice, document code and running page heading across every page. A naive index can make these fragments appear far more important than the actual content because they are repeated dozens of times. Conversely, removing every repeated line may strip a necessary section label or qualification. Do not discard repeated material just because it looks like boilerplate.
Design a detection rule that records repetitions and proposes exclusions without erasing their source locations. Then sample the affected pages. A footer that says “All values are preliminary” changes interpretation if it qualifies a displayed table. A repeated title may be navigational; a repeated unit such as “SGD thousands” may be essential. If the classifier cannot determine the distinction, retain the qualifier or flag it to the reviewer.
Footnotes can change the whole comparison
Imagine the table’s footnote states “2025 denominator excludes 12 cases pending inspection.” A correct interpretation may require reporting the exclusion or recalculating only when the intended comparable populations are defined. Never quietly put 12 in the denominator merely because the footnote mentions it. If the 12 pending cases are outside the 150 inspected, their eventual outcomes are unknown; an alternative all-assigned denominator would be 162, but only if the document explicitly defines 150 + 12 as the assigned population.
The right answer is often two numbers with two labels: inspected-case completion 90/150 = 60%, while an all-assigned rate is not yet defined without completion outcomes for the pending cases. A citation should point to the footnote as well as the table body. This is a powerful example of why a visually small text region can carry large analytical weight.
Figures require description, not imaginary text
A chart may contain critical annotations drawn as vectors or embedded in a raster image. Text extraction may recover a title but omit the axis labels and trend entirely. The system can use authorised image analysis to inspect the rendering, but it must distinguish visual estimation from precisely reported data. Reading a plotted point near 60 is not equivalent to finding an exact number 60 in the source data.
When a question depends on a chart, prefer an accompanying underlying data table if available. Otherwise give an appropriately approximate result, explain the uncertainty and cite the figure. A bar graph with a cropped baseline or logarithmic axis cannot be interpreted correctly from visual height alone. For high-stakes numerical use, manual confirmation or direct data export may be necessary; the existence of a computer-vision step does not remove these limitations.
Scans and OCR introduce a different uncertainty
In a scanned PDF, the visible page may be an image with no useful machine-readable text. Optical character recognition can suggest text and coordinates, but numbers, accents, minus signs and mathematical notation are vulnerable. The character “1” can be confused with “l”; “0” with “O”; a missing decimal point can turn 1.5 into 15. Such a mistake may be catastrophic when a model then computes with the incorrect value.
Treat OCR output as a hypothesis about the image. Preserve the image region and the OCR candidate, and use a visual check for decision-critical quantities. Do not replace the source bitmap with a clean-looking reconstruction and lose the ability to inspect it. If a page contains handwriting, stamps or degraded text, a human reviewer may be the only defensible verifier. OCR is a tool, not a certificate.
Mixed PDFs need page-by-page methods
A single file can mix born-digital text, scanned pages, vector drawings and photographs. An all-or-nothing policy — “run OCR over everything” or “never use OCR” — may be wasteful or inaccurate. A page-level classifier can check for a text layer, assess its plausibility, inspect important image regions and choose the least invasive extraction method. But it should never conclude that a text layer is complete simply because some characters exist.
Store method provenance per page and, where necessary, per region. A digital page might need coordinate-based column reconstruction, while a neighbouring scan needs OCR plus visual validation. The answer can then say when evidence was read from embedded text versus inferred from an image, so users understand why some citations are more uncertain than others.
Hyphenation and wrapped words
PDF line endings can split words, especially in narrow columns: “inter-” at the end of one line followed by “national” on the next. Rejoining them as “international” may be appropriate, but blindly removing every line-ending hyphen corrupts words that intentionally include a hyphen. The decision depends on dictionaries, layout, neighbouring text and possibly domain-specific terminology. Preserve an audit trail of normalization rather than applying irreversible cleanup.
This matters for search. A user looking for “data-driven” may miss a phrase wrongly recombined as “datadriven”, while a naive extractor may split a technical identifier into unrelated fragments. Index both a conservative original sequence and a documented normalized version when permitted. Highlight which source span supported a hit. Retrieval quality improves when normalization is reversible and grounded.
Unicode, scripts and mathematical notation
A visual PDF can contain characters that look the same but have different Unicode code points. Ligatures, superscripts, minus signs and bidirectional text add complexity. Converting “≤” into “<”, or dropping a subscript in a chemical formula, changes meaning. A right-to-left line mixed with Latin product IDs can be particularly fragile if display order and logical order are confused.
Record the encoding transformation and retain original glyph positions for suspicious spans. Avoid over-aggressive ASCII conversion. A model can produce fluent English paraphrases, but fluency cannot verify a mathematical inequality copied from a page. When a critical formula or non-Latin label is present, quote the exact source carefully or cite a cropped source region subject to permissions and privacy rules.
Document versions must remain distinguishable
Two PDFs may have the same filename and visually similar front pages while containing different revised figures. If a retrieval system merges their chunks under one label, it may cite a statement from version A while describing version B. A stable source identity should include a revision key such as an authorised content fingerprint, issue date and repository identifier. If the document is replaced, previously issued citations must remain bound to the original revision or be explicitly marked stale.
Consider a report whose 2024 denominator was corrected from 120 to 125 in a revision. The original 60/120 = 50%, while the corrected 60/125 = 48%. An answer that uses “50%” alongside a link to the revised report is misleading even though the calculation was once correct. Require the source revision to match the referenced data and recompute derived figures when the authoritative source changes.
Retrieval chunks need anchored boundaries
Many AI systems split documents into chunks so they can search relevant passages. A naive fixed-length chunk can place the sentence containing a claim in one chunk and the necessary footnote or heading in another. A good chunking strategy respects pages, section headings, tables and logical reading regions where practicable. It also stores connections across boundaries so the system can fetch adjacent context before answering.
Do not build citations from chunk indices alone. Chunk 17 in one processing version may become chunk 18 after an extractor fix; such identifiers are poor external references. Anchor chunks to stable document IDs, page indexes and source spans. For every presented sentence, the system should identify the original evidence rather than just the transient retrieval object that happened to contain it.
Search hits are suggestions, not verified evidence
A semantic search engine might retrieve a paragraph saying “Table 4 summarises the result” without fetching Table 4. It might surface a footnote detached from the figure it qualifies. These are useful leads but not sufficient evidence. An agent should inspect the full region, reconstruct the table or figure relation and verify that the source actually supports the final wording.
If the user asks “Did the completion rate improve?”, retrieving a sentence containing “improved” may seem enough. Yet the sentence might refer to a different measure, or a later page might correct the preliminary number. Verification must check measure identity, time window, denominator and final-versus-draft status. Avoid mistaking retrieval relevance for factual confirmation.
Separate extraction confidence from claim confidence
An OCR engine might be 99% confident in the characters “90”, while the link from that number to the heading “2025 completions” is uncertain. A model might be highly confident that 90/150 is 60%, yet uncertain whether those are the intended paired quantities. These confidence dimensions must not be fused into one opaque percentage. Keep extraction reliability, association reliability, arithmetic validity and source recency conceptually separate.
A practical reviewer card can show: source page 13; printed label 10; cell text “90”; row “2025”; column “Complete”; denominator cell “150”; extraction method “born-digital text + visual grid check”; arithmetic 90/150 = 0.6; outstanding qualifier “pending cases excluded.” The card encourages targeted correction. It should not report invented machine-measured confidence scores when the system has not calibrated them.
An error taxonomy that leads to repair
Classify failures by mechanism: wrong document version, wrong page map, out-of-order columns, dropped qualifier, header-to-cell misassociation, OCR character error, unit conversion error, clipped figure, chunk boundary loss, or generated citation not present in the source. Each category suggests a different repair. More prompting cannot fix an absent page image; a better OCR model cannot fix a mislabeled document revision.
For each failure record the smallest reproducible example. A sample might contain one source page, its intended reading sequence, extracted sequence, expected cell associations and the incorrect downstream sentence. Add it to regression tests for the relevant stage. This turns a vague “AI hallucinated” complaint into a concrete engineering task with a measurable acceptance check.
The test oracle needs a human-readable answer
To test an extractor, build a small curated collection with ground-truth reading paths, page labels, sections and key values. The test should check whether the parser reconstructs meaning, not just whether character recognition yields a high match percentage. A document can have almost perfect token recall while swapping two cells in a medical table. A mismatch on a high-impact link should outweigh dozens of harmless punctuation differences.
Use separate tests for extraction correctness and for the model’s answer reasoning. In the fictional report, the extractor should return 60 attached to 120 and 2024, and 90 attached to 150 and 2025. The reasoning stage should then derive 50%, 60% and +10 percentage points. If the final answer is wrong, the staged traces reveal which contract failed.
A practical audit using precision and coverage
Suppose a curated test set contains 80 required evidence units across several sample pages. The parser retrieves 74 candidates; 68 are correctly associated with source meaning and 6 are wrong. Then precision among retrieved units is 68/74, about 91.9%, and recall against all required units is 68/80 = 85%. Those denominators answer distinct questions. Character accuracy or keyword matching may produce other numbers, but they should not be substituted without definition.
If 10 of the required units involve numerators and denominators and the parser correctly associates only 7, a 70% high-impact cell-association rate may be unacceptable despite the overall 91.9% precision. Design severity-aware release checks rather than declaring success from a single average. This worked example is fictional; it illustrates measurement logic, not a benchmark claim about a particular extraction library.
Review budgets should follow consequence
Not every extracted paragraph deserves equal manual review. A table used for a public financial claim, safety instruction or medical number warrants more scrutiny than a decorative subtitle. Allocate reviewer effort to high-consequence uncertainties and to patterns known to fail, such as multi-column tables, low-resolution scans and cross-page notes. Sample ordinary pages too, since a targeted-only review can miss systematic errors elsewhere.
Risk-based review is not permission to fabricate lower-risk content. When evidence is uncertain, label uncertainty. When a page is inaccessible, explain that it was not read. When a source cannot be cited because of access restrictions, provide an authorised internal reference or ask for an accessible excerpt rather than inventing a public link. Strong guardrails make limited review useful; they do not make omitted verification vanish.
Privacy and permission boundaries
A PDF may include names, identification numbers, financial details or restricted contractual terms. Source provenance must not become a back door for exporting private page snippets into logs, search indexes or public answers. Access controls should be checked at retrieval and at presentation, with retention rules for extracted text, OCR images and reviewer exports. A user permitted to ask about one folder should not gain the ability to cite another folder just because chunks share an index.
Permission handling belongs in the architecture before a model is asked to summarise. Do not post confidential images to external OCR services unless authorised. Store diagnostic artifacts only within an approved environment and avoid unnecessarily copying full files into observability traces. The agent file ingestion guide covers another part of that boundary: malicious files and parser isolation.
Citations should survive a reader test
A useful PDF citation should help an ordinary reader find the relevant passage quickly. Ideally it names the document version, physical and printed page, section or table, and perhaps a stable internal viewer link. A bare citation such as “PDF page 10” without context can be ambiguous; a generated “source link” that does not open is worse. Test a sample of citations in the actual intended reader workflow, including mobile or assistive access where relevant.
Never assume that a citation generated by a model corresponds to a real anchor. Validate it against the source map before release. If an application constructs a deep link, make sure it uses the viewer’s documented page convention and does not confuse zero-based programming indexes with one-based page navigation. If a deep link cannot be verified, a plain descriptive page reference is preferable to false precision.
A changed-context transfer problem
A student reads a different fictional PDF with 21 physical pages. The first five pages are labelled A-1 through A-5, and the body begins on the sixth physical page with printed page 1. A quote is on printed body page 12. What physical page and zero-based index should the student’s citation use? The solution is 5 preliminary pages + 12 body pages = physical page 17, so the index is 16. This applies the mapping method to a new numbering scheme rather than memorising “subtract three.”
Suppose the PDF viewer opens physical page 12 by default when the student types 12. The displayed page will not contain the target quote. The repair is not to edit the quote or blame the viewer: record “printed body p. 12; physical p. 17 of 21,” open the seventeenth page and check the visible passage. If a file’s own PageLabels dictionary differs from the printed labels, record that disagreement as a further mapping field rather than silently choosing one.
When an automated answer should abstain
An agent should decline to assert a precise source-based claim when the relevant file is incomplete, the required figure is unreadable, conflicting revisions cannot be resolved, or the mapping from value to header is uncertain. Abstention can be local rather than total. The agent might accurately say “The report has 17 physical pages and the target table appears on printed page 10, but I cannot confidently read its final column,” leaving the uncertain numerical conclusion out.
This approach is more useful than a blanket “PDFs are unreliable.” Many PDFs support excellent automated retrieval. The principle is proportionality: preserve the parts you can establish, clearly identify the missing evidence, and ask for a higher-quality source or human check only where necessary. A trustworthy system makes its evidence limits navigable rather than hiding them.
Frequently asked questions
Is OCR always necessary? No. Born-digital text may be more accurately extracted directly, although figures and structure still need attention. Is sorting text by position enough? No; columns, callouts, tables, scripts and tags can require richer reconstruction. Does a tagged PDF guarantee correct reading order? No; tags must be checked against actual meaning. Can an LLM repair a garbled page? It may suggest a plausible sequence, but that suggestion is not proof of fidelity.
Why keep both physical pages and printed labels? Because readers, code libraries and PDF viewers often use different conventions. Should every sentence receive coordinates? Not necessarily; consequential claims and direct quotes warrant traceability, while a narrative summary may cite a section or page range. Is the method specific to superintelligent systems? No. These are practical principles for present-day AI agents and document-processing systems; claims about hypothetical future ASI should remain explicitly speculative.
Sources and learning routes
Use the W3C Meaningful Sequence guidance, W3C PDF3 reading-order technique, Adobe’s official PDF reading-order documentation and Apache PDFBox text-extraction API for the standards and developer mechanisms underlying this guide. Each URL is an actual technical reference, not a fabricated citation to the fictional report.
To connect document evidence with system design, continue at the How Super Intelligence Works hub. For the wider principle that learning should transfer from one example to a changed problem, visit The Gold Standard of Education. The disciplined habit is simple: show what the source contained, show how the system reconstructed it, and show where a reader can check the result.