How Do I Extract Tables from a PDF for LLMs?
AI Workflows

How Do I Extract Tables from a PDF for LLMs?

DocuShell TeamJuly 6, 20267 min read

The answer in one sentence

To extract tables from a PDF for an LLM, preserve the relationships that make the table meaningful: column headers, row labels, merged cells, captions, footnotes, and page location. A flat stream of numbers is not a table. It is a pile of values the model has to guess how to reconnect.

Use DocuShell Parse PDF to produce structured JSON for machines and Markdown for model context. Keep both versions. JSON gives your application a predictable record; Markdown gives the model a readable table.

Table-extraction rule: if a value cannot be traced to a row label, column label, unit, period, and page, it is not ready for an LLM or an automated decision.

Choose the extraction strategy by document type

Source table Best first pass Main failure to test Required evidence
Native financial statement Layout-aware parser Merged cells and continued pages Caption, units, period, page
Scanned bank statement OCR plus table reconstruction Digit and decimal errors Cell image, confidence, page
Product comparison grid Structured rows and Markdown Lost checkmarks or icons Legend, row label, source box
Legal schedule Clause-aware table extraction Footnotes detached from rows Schedule title, footnote, page
Form-like PDF Field-value extraction Wrong label association Field label, value, coordinates

Why copy and paste fails

PDFs store content by position. A value can sit under a heading visually without being linked to it in the file. Basic text extraction may read across columns, repeat headers, or move footnotes into the middle of a row.

That damage is easy to miss in a short prompt. It becomes costly when an LLM compares quarterly revenue, checks an eligibility matrix, or answers from a pricing table.

A reliable extraction workflow

Start with layout-aware parsing. For every table, retain:

  • the section heading and table caption
  • column and row labels
  • page number and source coordinates
  • units, currency, and date range
  • footnotes and continuation markers

Then store two representations. Use structured JSON for filters, calculations, and QA. Use a Markdown table for retrieval and generation. Link both with the same table ID and source metadata.

Chunk the table as one idea

Do not split a table every few hundred tokens without considering its shape. A chunk containing only the last four rows may omit the header that explains every value.

Keep a small table intact. For a long table, repeat the column headers in every chunk and attach the same caption, section path, and page range. Add nearby prose when it changes how the figures should be read.

Handle scanned tables carefully

A scanned PDF needs OCR before table reconstruction. OCR can confuse 0 and O, drop decimal points, or merge adjacent cells. That is acceptable for search discovery, but not automatically safe for financial calculations or compliance decisions.

Use the OCR accuracy guide to improve the source, then review high-impact cells against the original page.

Make answers auditable

Require the LLM to cite the table title and page. For important outputs, validate generated numbers against the structured JSON rather than trusting the prose response alone.

The goal is simple: a reviewer should be able to move from an answer to the exact table, row, and source page without reconstructing the pipeline.

Example: preparing a quarterly revenue table

Suppose a report contains revenue by region for 2025 and 2026. The visible page also says “USD in millions,” and a footnote explains that one region was reclassified. A weak extractor sends the model twelve numbers. A useful pipeline creates one table record containing the title, unit, periods, row labels, values, footnote, page, and source coordinates.

The LLM can then answer “Which region grew fastest?” by retrieving the table, while application code calculates the percentage change. The response cites the page and mentions the reclassification instead of presenting a misleading comparison.

This division of labor matters. Models are good at explaining evidence. Deterministic code is better for arithmetic and schema checks.

A compact table record can look like this:

{
  "table_id": "revenue-by-region-p18",
  "title": "Revenue by Region",
  "unit": "USD millions",
  "periods": ["2025", "2026"],
  "rows": [
    { "region": "EMEA", "values": [31.4, 33.9] }
  ],
  "source": { "page": 18, "bbox": [72, 216, 540, 376] },
  "notes": ["Prior-year regions were reclassified"]
}

Table-extraction quality checklist

Before indexing the output, check that:

  • every value still has a row and column label
  • units and reporting periods are explicit
  • negative numbers and parentheses are preserved
  • repeated headers are not stored as data rows
  • multi-page tables have been joined only when their schemas match
  • captions and footnotes remain attached
  • page citations open the correct source region

For a broader ingestion design, read PDF Parse API for LLM and RAG. If the source is image-only, start with how to parse scanned PDFs into Markdown and JSON. When the table will feed a retrieval system, use the citation-preserving PDF chunking guide.

Financial filings need additional controls for periods, units, amendments, and deterministic calculations; use the guide to parsing financial reports and 10-K tables for AI for that workflow.

When not to automate the final decision

Do not let extracted tables automatically approve payments, reject claims, change pricing, or make regulated decisions without validation. Table structure can look correct while one OCR error changes a key value.

Use field-level rules where possible: expected column count, numeric formats, totals, date ranges, and allowed units. Send failures and material discrepancies to a reviewer with the original page beside the extracted record.

Frequently Asked Questions

Use Markdown for model-readable context and keep a structured JSON copy for validation. Both should retain the table heading, page number, and nearby notes.
Sometimes, but flattened text can detach values from their row and column labels. Structured extraction is safer for financial, legal, and operational data.
Run an OCR-capable parse first. Review low-confidence cells before using the table in calculations or high-stakes answers.

Free Tool

PDF to JSON

Turn PDFs into structured, source-aware data for RAG, review, and automation.

Try PDF to JSON
extract tables from pdfpdf tables for llmpdf to jsontable extractionrag tables
D

DocuShell Team

The DocuShell editorial group writes and maintains guides for everyday PDF workflows, with updates made when tool behavior or documented limits change. See our editorial standards for the process behind each article.

Focus: Structured PDF extraction and document AI pipelines

Questions or feedback? Get in touch.

Related Articles