4LLM

PyMuPDF4LLM
now ships with Layout.

TRY DEMO

PDF: The Most Trustworthy Hallucination in the Stack

July 13, 2026

The AI industry has one answer to hallucination: grounding. Don't trust the model, retrieve from the documents. That is the entire pitch of RAG. The model guesses; the document knows.

Now open the PDF document.

A PDF does not contain words. It does not contain sentences, paragraphs, tables, or reading order. (Yes, tagged PDF exists; Word even tags by default. But measured tagging rates in scholarly corpora run 1 to 16 percent, and sometimes the tags that exist are the exporter's autogenerated guesses. One more inference, not ground truth.) What a PDF contains is drawing instructions: put these glyphs, in this font, at these coordinates. It is a printer instruction stream that outlived printers. Even the space between two words is often not there; no space character exists in the file, just a horizontal gap between two runs of ink, and something has to decide that the gap means "space."

Don't take my word for it. This is the complete text-drawing instruction from a working, 614-byte PDF:

[(A Ferrari F2004) -278 (Formula One car)] TJ

The -278 is the space. Not a character: a TJ positional adjustment, in thousandths of text-space units, subtracted from the pen position, so a negative value moves the pen right. And 278 is no accident; it is exactly Helvetica's space width, so the gap renders indistinguishably from a real space. Search the file for a space character between F2004 and Formula and you will find nothing, yet every viewer displays one, and a good extractor returns one, because it decided that the gap was wide enough to mean a word break.

That something is an extractor, and everything it produces is inference. Words are stitched together from glyph runs. Paragraphs are guessed from gaps. Tables are reconstructed from ruled lines and alignment. Reading order is an algorithm's opinion about a coordinate soup. Every "ground truth" a RAG pipeline retrieves from a PDF was hallucinated back into existence by the extractor.

So the anti-hallucination stack rests on a hallucination.

The reason the stack doesn't collapse is that not all guessing is the same kind. An LLM hallucinates without bounds: it fills gaps with whatever is plausible, differently each time, and there is nowhere to attach a debugger. Extraction guesses inside bounds. Same file, same output, every time. Every extracted word traces back to specific ink at specific coordinates. And when it's wrong, it's wrong in a fixable way.

A recent example from our own work. While testing a new chunking feature for PyMuPDF4LLM, a test document came back reading F2004Formula where the page clearly showed F2004 Formula. The cause was exactly the phantom-space problem above: the space existed only as a geometric gap between two text spans, one regular and one bold, and the chunker was joining spans without accounting for it. The bug was traced to a single span-joining rule, and the fix is a single rule. Once it lands, that bug is dead everywhere, forever. Try doing that to a hallucination.

That is the honest description of the modern document-AI stack: nothing in it hands you truth, only interpretations of what sits below. Quality is not the absence of guessing but the discipline of the guesses. Deterministic, auditable inference at the bottom; probabilistic generation at the top. Confuse the two, or assume the bottom is trivial, and your pipeline ends up confidently citing text that never existed.

It is also why, as AI systems start facing evals, audits, and compliance reviews, the unglamorous bottom of the stack suddenly matters. A vision-model parser can be made deterministic these days, if you pay a throughput tax to make its answers reproducible (batch-invariant kernels, for those who followed that saga). And when it points at the page, the bounding box it returns is one more model prediction, a guess about where the text sits. Extraction's coordinates are not a guess. They are the numbers the PDF itself used to draw the glyphs, reachable through the actual text operators, font metrics, and spans, and the procedure that turns them into words is code you can read, not weights. Same input, same output by default, and every output traceable to specific coordinates on a page. That combination is worth more every year.

Everyone grounds their AI in documents. Documents themselves need grounding. Somebody has to turn ink coordinates back into meaning, and do it with discipline. That work is the grounding under the grounding: the most trustworthy hallucination in the stack.



Discuss This Article with the Community

Have a question, a different approach, or something you built after reading this? Share it on the forum or join the Discord, we'd love to hear from you.

PyMuPDF Logo

© 2026 Artifex Software Inc. All rights reserved.