Citations in Scanned PDF Tables: Cite the Cell, Gate the Cell, Keep the Proof
A bank's scanned fee table has one smudged cell, and the assistant answers 9.5 percent, page 47, which is the Plus row, not Premium. Extract cells with headers and boxes, gate on structure and confidence (0.41 under a 0.90 line), abstain, and prove it on a 1,200-cell golden set (synthetic numbers).
What you will learn
- Explain why plain OCR flattens a table and loses the row a number belongs to
- Extract cells with row header, column header, page, box and confidence, and repeat headers in every chunk
- Gate every value on structure and confidence, and abstain or send it for review when the scan is unreadable
- Build an audit record and a golden set that measure cell accuracy, slipped errors and review load
Before you start
- Loading and Parsing Real Documents for RAG
- Citations and Abstention
A scanned page is not text. It's a picture of text, and a machine has to read it first. In a table, a number only means something together with its row, its column and its page. And when the scan is too poor to read, the right answer is to say so. This is how you keep citations honest in that case.
Right page, wrong row
Our analyst answers questions about big PDFs, and this customer is a bank. It's regulated, so every answer must point to its source. The bank uploads its fee schedule, but it's a scan of a printed page, and one cell is smudged.
A user asks: what is the overdraft rate on the Premium plan? The answer reads "9.5 percent, see page 47", and page 47 really is the fee table. But when a reviewer follows the Premium row with a ruler, the rate is smudged. 9.5 percent belongs to the Plus plan, one row above. The page is right, the number is real, and the row is wrong. For a bank, that's a wrong answer with a citation on it.
How would you preserve citations in scanned PDF tables for a regulated customer?
- Layout-aware extraction. Extract cells, not lines. Every cell keeps its row header, its column header, its page and its position on the page.
- Confidence gates. When a cell is unreadable or a row is missing a cell, abstain or send it to a person. Never guess.
- Auditability. Every answer leaves a record that shows the exact cell, and the customer accepts the system on their own documents before it goes live.
In short: cite the cell, check the cell, and keep the proof.
The photocopied ledger
Picture an auditor holding a photocopy of an old ledger. A number on it, say 1,200, means nothing on its own. So she lays a ruler along the line and reads the row name on the left and the column name on top. Where the copy is smudged, a careful auditor doesn't guess from the line above. And she puts a tick on the exact spot she checked, so anyone can find it again. Value, headers, confidence and a box on the page: that's the whole design.
How plain OCR flattens a table
OCR is the step that turns the picture into text. Plain OCR reads the page line by line, left to right, like a sentence. Every row turns into a run of words, and all the rows end up in one flat strip of text. The smudged cell gives nothing at all. It doesn't leave a gap. It just disappears.
Now look at the strip. "9.5%" sits right before the word "Premium", and nothing after "Premium" says otherwise. A model reading this chunk picks the nearest rate. The words are all there, but the positions are gone, and in a table the position is the meaning.
Cells, not lines
A strong system finds the table first, then the grid of rows and columns inside it. Each cell becomes a record: value 9.5 percent, row Plus, column overdraft rate, page 47, and a box with the exact position of the cell on the page image. It also keeps the OCR confidence score for the cell.
When you build chunks, repeat the headers with every value, so the chunk reads "plan Plus, overdraft rate 9.5%". A row now makes sense on its own. And the citation points to the cell, not just the page, so the screen can draw a box on the scan right where the number is. A reviewer sees it in a second. (For the general parsing step, see Loading and Parsing Real Documents.)
Two gates before any answer
Before any value reaches an answer, it passes two gates. All numbers here are synthetic.
- Structure gate. The header has three columns, but the Premium row has only two cells. Something is missing, so the gate fails.
- Confidence gate. The smudged cell scores 0.41, and the line is 0.90. It stays below the line.
So the system abstains: "The Premium overdraft rate on page 47 is unreadable in the scan, and it has been sent for review." The review card shows a person the crop of that one cell, so they can fix it in seconds. For a regulated customer, that answer is correct. A wrong rate with a page number on it can turn into a complaint or a fine. The same "cite or say you don't know" rule for ordinary text is in Citations and Abstention.
Where weak answers go wrong
| Weak answer | Why it fails |
|---|---|
| "We run OCR, then our normal RAG pipeline" | Normal RAG chunks plain text; the table structure is gone before the first chunk is made |
| "Every answer cites the page" | The page was right in our example. A page citation on a table can still point to the wrong row |
| "A better OCR model fixes it" | Fewer mistakes, but no model reads every scan, so you still need the gates |
The strong answer extracts cells with headers and boxes, cites the cell and shows its crop, keeps the gates, and measures them. The question is never just "can we read it?" It's "how do we know when we can't?"
What the auditor and the customer see
Every answer writes a record: the question, the answer, the cell ids it used, a hash of the page image, the extraction version, the confidence, and the reviewer if there was one. Months later a regulator asks why the assistant said this. You open the record, and it draws the same box on the same page image. The hash proves the page hasn't changed since.
Then there's customer acceptance. Before the system goes live, you test it on the customer's own scanned pages. They agree on the confidence line, and they sign it off. That's what the interviewer is really asking a forward deployed engineer here: can the customer trust it, and prove it?
How you prove it works
Build a golden set (synthetic numbers): 50 scanned pages from the customer, with 1,200 table cells labelled by people.
| Metric | Result |
|---|---|
| Cell accuracy | 1,164 of 1,200 right, 97%, so 36 wrong |
| Caught by the gates | 30 of the 36 |
| Slipped through | 6 wrong cells, 0.5% of all cells |
| Review load | 72 cells to people (the 30 wrong plus 42 right but unsure), 6% |
The confidence line is a trade-off. Raise it and fewer wrong cells slip through, but people review more. For the failure test, smudge one cell on a test page and ask about it. It passes only when the system abstains or sends it for review, never when it answers with the value from a neighbouring cell.
- How do you choose the confidence line? From the golden set. Plot slipped errors against review load; the customer picks the point that fits their risk and signs it off.
- Rotated pages or handwritten notes in the margin? Detect them at page level, give them low confidence, and route them to review instead of reading them as table cells.
- The customer uploads a new scan? New version, new extraction. Run the golden set again, and flag answers that cite the old version.
Recap
| Layer | What to do |
|---|---|
| Layout | Extract cells, not lines; keep row, column, page and box with every value |
| Gate | Structure and confidence checks; abstain or send for review when unreadable |
| Audit | A record that redraws the exact cell, on a system the customer tested and accepted |
Try it yourself
Using the golden-set numbers above, say what you'd expect to happen to the 6 slipped cells and the 72 reviewed cells if the customer raised the confidence line from 0.90 to 0.95, and which number you'd ask them to watch.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
What an Embedding Actually Is: Meaning as Numbers, Search by Closeness, and Where Hand-Made Numbers Break
A customer types "I cannot log in" and keyword search finds nothing, although a password-reset article exists. Turn meaning into numbers by hand, find the nearest point with math.dist, build a three-topic toy embedder that finds the right article at 1.00, and watch it score 0.00 on "I can't get into my account".
The RAG Pipeline Explained: 7 Stages From Documents to a Cited Answer
Ingest, chunk, embed, store, retrieve, rerank and generate, in one Python file. Follow one question through a 26-chunk employee handbook to an answer that cites its source.
Similarity Search: Finding the Closest Vectors with NumPy and NearestNeighbors
Ask one question of a whole collection of vectors: which items are closest to this one? Normalise, score every row with one matrix multiply, keep the top k or everything above a threshold, and check it with NearestNeighbors.
Why RAG Exists: The Problem It Solves, Compared With Pasting Everything and Fine-Tuning
A smart model has never read your company's files, and they change every month. Three ways to give it the facts: paste everything, fine-tune, or retrieve only the right pieces. Follow a refund-policy question through all three and see why RAG wins when documents change.
