Vibeleaderboard
← All Intel
Intel / article

Extract Tables From Pdf Llm

Source
openrouter.ai
Author
OpenRouter editorial sitemap
Date

Context

An OpenRouter tutorial on pulling tables out of PDFs with a reports that, in its tests, the models' reading was not what failed. Every model that read the PDF directly got every cell right, and the errors came from the route the file took to reach the model, including two failures that returned an ordinary successful response. The method in the guide is one API request: the PDF goes in as a file attachment, along with a strict JSON schema that describes a single row of the table, and the model returns a list of rows with typed fields.

The schema does the cleanup that would otherwise need custom code. With strict structured outputs, providers that support strict mode hold the response to the schema, so every row has every field with the right type. Short descriptions on each field handle accounting conventions: a value written as (3,878) comes back as -3878, footnote markers are removed from names, and a category cell merged across several rows is repeated on each row it covers. A table that runs onto a second page comes back as one list.

OpenRouter generated five test PDFs from known data so every cell could be checked: an invoice, a quarterly report, a 58-row shipment log spanning two pages, a scanned purchase order and a deliberately rough scan with merged cells, 644 cells in all. GPT-6 Luna, Claude Haiku 5.5 and Gemini 3.8 Flash, which read PDFs directly, got all 644, at an extrapolated $0.77, $1.00 and $8.04 per 1,000 pages. DeepSeek V4.1 Flash cannot read files, so the PDF has to be converted first. Through the mistral-ocr parser, which runs optical character recognition and adds $2 per 1,000 pages, it got 642 cells. Through the free cloudflare-ai text parser it got 434, with the digital files right and both scans entirely wrong.

The two quiet failures explain the checks the guide insists on. A scan has no text layer, so the free parser passed the model nothing, and the model correctly reported an empty table with a normal finish and no error; a pipeline would store zero rows and move on. A long table can also stop at the output limit. Plain JSON parsing then raises an error, but with OpenRouter's Response Healing plugin turned on the repaired output parsed into 5 of the 58 rows without complaint. The guide's code therefore rejects any response with no rows and any response whose finish reason is length, and it suggests budgeting about 150 output tokens per expected row after measuring 43 to 133 in its runs.

These results describe six synthetic pages run once per route, at OpenRouter's prices as of October 8, 2026, measured by the company that sells access to all of these routes. The guide itself says to test a sample of your own documents before choosing. For digital PDFs with simple headers, it found the free pdfplumber library located every table, but returned cells as text, split a two-level header into two rows, broke the two-page log into two tables and found nothing in either scan.

Key takeaways · AI-distilled
  • In OpenRouter's tests on five generated PDFs, two of them scans, every model that read the PDF directly got all 644 cells right. Every failure came from the parser route the file took to reach the model, not from the model's reading.
  • OpenRouter handled a category cell merged down six to nine rows purely through the schema's field description, telling the model to repeat the value on every row it covers. All three PDF-reading models then filled the category on all 30 rows of a rough scan.
  • OpenRouter's 58-row shipment log used 2,500 to 7,700 output tokens depending on the model, 43 to 133 per row, so it suggests budgeting about 150 tokens per expected row. With Response Healing on, a cut-off output parsed cleanly but held only 5 of 58 rows, with no error.
  • On OpenRouter's test pages, GPT-6 Luna cost about $0.77 per 1,000 pages and Claude Haiku 5.5 about $1.00, both with every cell right. Gemini 3.8 Flash matched accuracy at 8 to 10 times the cost; the mistral-ocr route adds $2 per 1,000 pages and kept footnote markers.
  • In OpenRouter's tests, pdfplumber found every table in the digital PDFs but returned cells as strings like '(3,878)', split a two-level header into two rows with None, broke a two-page table in two, and found nothing in scans, so it suits only simple digital tables.
Terms in this piece · Glossary
  • LLM — A large language model — the neural network behind tools like Claude and ChatGPT, trained on huge amounts of text to predict what comes next.
  • token — The chunk of text a model reads and writes in — roughly three-quarters of a word — and the unit AI usage is billed in.
Read the source openrouter.ai
More from OpenRouter editorial sitemap
Recommended reads
Comments

Checking sign-in…

Loading comments…