Kognita
All posts
Engineering2026-09-09·8 min read

Table extraction from PDFs for RAG: tools and traps

Tables hold the exact numbers users ask about — and PDF parsers mangle them more than any other content. Here's why table extraction is so hard, and how to stop it from silently corrupting your knowledge base.

Tables are where the answers hide. Pricing, specifications, financial figures, comparison matrices — the exact facts users query are disproportionately in tables. And tables are also where PDF extraction fails most catastrophically. A parser that handles prose flawlessly will turn a clean table into a jumble of numbers with no idea which value belongs to which row and column. The failure is silent: ingestion succeeds, the text is there, and it's wrong in a way that produces confidently incorrect answers. Here's why it's hard and how to handle it.

table extraction from PDFs for RAG

Why tables break parsers

Prose is a one-dimensional stream — read left to right, top to bottom, done. A table is two-dimensional: a cell's meaning comes from its position, the intersection of its row and its column header. That structure is the whole point of a table, and PDFs don't store it.

A PDF records where characters are painted on the page, not that "this block is a table" or "this number sits under the Q3 column." So a naive text extractor reads the table like prose — left to right across the page — and produces something like:

Product    Q1    Q2    Q3
Widget     100   120   140
Gadget     90    95    110

...flattened into: Product Q1 Q2 Q3 Widget 100 120 140 Gadget 90 95 110. Now the structure is gone. Is 120 a Widget number or a Gadget number? Which quarter? A human can sometimes reconstruct it; an embedding cannot, and a model reading this run-on line will happily associate the wrong number with the wrong label. The value that was the answer is now noise — or worse, a plausible wrong answer.

The specific traps

  • Column association lost. The core failure above — values detached from their headers. This is the one that produces wrong answers rather than merely missing ones, which makes it the most dangerous.
  • Multi-column page layouts. A page with two text columns confuses reading order, and a table within a multi-column layout compounds it. Extractors scramble the order and interleave unrelated content.
  • Merged and spanning cells. Cells that span multiple columns or rows (common in headers) break the neat grid assumption most extractors rely on.
  • Borderless tables. Tables laid out with whitespace instead of visible lines are hard even to detect as tables, so they get read as ordinary paragraphs.
  • Tables split across pages. A long table continuing onto the next page loses its headers on the continuation, so the second half's cells have no column context at all.

Approaches that actually work

1. Layout-aware extraction, not plain text. Use PDF tools that detect table regions and recover their grid structure — identifying rows, columns, and cell boundaries — rather than dumping characters in reading order. This is the foundation; everything else assumes you've correctly detected and structured the table first.

2. Preserve structure into a text representation that keeps relationships. Once you have the grid, serialize it into a format that retains row/column association — Markdown tables, HTML tables, or key-value rows like "Widget: Q1=100, Q2=120, Q3=140". The goal is that each chunk of the table still encodes which value belongs to which header, so the embedding and the model can use it correctly.

3. Consider row-wise or cell-contextualized chunking. For retrieval, a useful pattern is to represent each row (or meaningful cell group) as a self-contained statement that includes its headers: "Widget quarterly revenue: Q1 $100k, Q2 $120k, Q3 $140k". This makes a specific figure retrievable with its context, instead of hoping a flattened table chunk survives.

4. For critical tables, consider a vision model. When accuracy really matters and layout extraction struggles, a multimodal model that can read the table as an image and output structured data can outperform geometry-based extractors on messy or borderless tables. It's more expensive, so reserve it for the high-value cases.

The verification trap

The most important operational point: table extraction fails silently, so you have to check it. Unlike a crash, a mangled table produces a successful ingestion with corrupted content. If you never look, you won't discover it until a user gets a confidently wrong number — the worst possible way to find out. Practical safeguards:

  • Spot-check extracted tables from a sample of documents against the originals during ingestion setup, especially for document types you'll ingest a lot of.
  • Treat table-heavy documents as higher-risk and validate them more carefully than prose.
  • Preserve provenance so that when a numeric answer is questioned, you can trace it back to the source table and verify — which is also why source linking matters doubly for tabular data.

The takeaway

Table extraction is the single most underestimated failure mode in document ingestion, precisely because it's silent and because tables hold the exact facts people query. The fix isn't one magic parser — it's a discipline: detect tables and recover their grid, preserve row/column relationships into your chunks rather than flattening them, reach for vision models on the hard ones, and verify the output because failure won't announce itself. Prose forgives sloppy extraction; tables punish it with wrong answers. Treat them as the special, high-stakes content they are, and you close off one of the most common sources of confident errors in a knowledge base.