Document Intelligence With LLMs: Extracting Tables and Forms From PDFs

Document intelligence with LLMs turns PDFs into structured data. Compare Azure, LlamaParse and Unstructured, and build a pipeline that validates every number.

By Galactic News Editorial · Published 2026-11-25T16:38:22+00:00 · Updated 2026-11-25T16:38:22+00:00

Document intelligence LLMs PDF extraction of tables and forms

Document Intelligence With LLMs: Extracting Tables and Forms From PDFs

Document intelligence with LLMs turns PDFs into structured data. Invoices, contracts, forms and reports become rows, fields and tables a program can use. The trick is pairing the right parser with the right model. A layout-aware parser extracts the structure. A language model reads the meaning. This guide explains the pipeline, compares the main tools, and shows how to build one that holds up in production.

Why PDFs Are Hard for LLMs

A PDF is a print format, not a data format. It stores where ink goes on a page, not what the text means. A table in a PDF is a set of lines and text fragments. A form is a set of labels and boxes. A plain text extractor returns the words in reading order, or worse, in the order they were drawn. Merged cells, multi-page tables, scanned pages and handwriting all break naive extraction.

That is why document intelligence has two stages. First, parse the page: recover layout, tables, key-value pairs and selection marks. Second, reason over the result: map fields to a schema, resolve ambiguities, and validate the output. The first stage needs layout models or vision models. The second stage is where LLMs earn their keep. Skipping the first stage and feeding raw text to a model produces plausible-looking errors. The model fills gaps with guesses, and nobody notices until the numbers are wrong.

The Main Approaches to PDF Extraction

There are four practical approaches. Each suits a different document mix.

Managed layout services. Azure Document Intelligence extracts text, key-value pairs, tables and document structure from PDFs, images and forms. It uses OCR tuned for documents and returns table row and column structure. It offers prebuilt models for common document types such as invoices and receipts, and custom models that learn a document's structure from five samples. It is now part of Azure Content Understanding in Foundry Tools. LLM-powered analyzers handle complex, unstructured and multimodal content alongside the deterministic extraction.

Vision-based parsing APIs. LlamaParse is LlamaIndex's document parsing service. It uses vision-language models to understand page layout and extract structured content, including tables rendered as proper Markdown, image descriptions and hierarchical sections. It returns tables in several forms at once: as part of the page Markdown, and as typed table items with rows, CSV, HTML and Markdown representations. It can also write every table into an XLSX workbook, one sheet per table. It offers four tiers: fast, cost_effective, agentic and agentic_plus. The fast tier runs no AI model. Agentic is the default recommendation for real tables and scanned pages. Agentic_plus suits dense financial reports and complex tables.

Open-source partitioning. Unstructured is an open-source library that partitions documents into typed elements: text blocks, tables, images and headers. It uses layout detection models, including YOLOX, and can infer table structure. It runs locally, which suits teams that cannot send documents to a cloud API. It is a general-purpose, self-hosted option, and its table quality is good rather than excellent. It pairs well with an LLM that cleans and validates the output.

Direct vision LLM calls. Send page images to a vision model with a structured-output schema. This works for unusual layouts that parsers miss. Use it as a fallback for pages where the parser fails, not as the primary path.

Document Intelligence LLMs PDF Extraction: The Pipeline

A production pipeline has six stages. Each one catches errors the previous stage missed.

  1. Classify the document. Identify the type: invoice, contract, form, report or statement. Route each type to its own schema and parser settings. A single generic prompt for all types is the most common failure.
  2. Parse layout and tables. Run the parser. For mostly-text documents with simple tables, LlamaParse cost_effective is enough. For real tables, scanned pages or merged cells, use agentic or higher. For self-hosted work, use Unstructured with table inference enabled.
  3. Extract fields with a schema. Give the LLM a strict output schema: field names, types and required fields. Ask it to return only the fields in the schema. Structured output, not free text, is what makes the result usable downstream.
  4. Validate every number. Check that table rows sum to the stated total. Check that dates parse. Check that currency symbols match the expected currency. Flag anything that fails validation for human review instead of passing it through.
  5. Handle multi-page tables. Tables that continue across pages are a classic failure. LlamaParse can merge a continued table into one, with metadata noting the source pages. If your parser does not merge, detect continuation headers and join the rows yourself.
  6. Keep the evidence. Store the page number, the bounding box and the raw extracted text for every field. When a value is questioned later, the evidence settles it. An extraction without provenance is a guess.

Tables: The Hardest Part

Tables fail more than any other element. The failure modes are consistent. Merged cells break row alignment. Borderless tables hide their boundaries. A table that spans pages splits into two unrelated tables. A header row repeats on each page and gets counted twice.

Choose the parser tier by table complexity, not by document length. The LlamaIndex documentation recommends cost_effective for mostly-text documents with simple tables, agentic for real tables and scanned pages, and agentic_plus for dense financial reports and complex tables. The fast tier runs no AI model, so pick cost_effective or higher when tables have merged cells, continue across pages, or lack borders.

Output format matters too. Markdown pipe tables are simpler, but they cannot represent merged cells. HTML tables can, with colspan. If your downstream system needs exact structure, request the HTML or CSV representation and keep the Markdown only for display. For financial reports, the XLSX export gives one sheet per table, which auditors and analysts can check directly.

For Unstructured, the key option is infer_table_structure. It extracts the table structure and returns the table as HTML in the element metadata. Combine it with a layout model and a validation pass. The open-source path costs more engineering time and less per-page money. The managed path costs the reverse.

Forms: Key-Value Pairs and Selection Marks

Forms are a different problem from tables. The value is a label and a filled field: name, date, amount, checkbox. Azure Document Intelligence returns key-value pairs directly, and its layout model extracts selection marks such as checkboxes. That is the right tool when forms dominate your document mix.

With an LLM approach, the pattern is to extract the form as text first, then prompt the model to map each label to its value. The risk is label drift: the model pairs a value with the wrong label when the layout is dense. Anchor the mapping to the parser's layout output. If the parser says a value sits next to a label, trust the geometry over the model's guess.

Handwriting is the hardest case. Azure Document Intelligence supports printed and handwritten forms, and it supports multiple languages including English, French, German, Italian, Spanish, Portuguese, Dutch, Chinese, Japanese and Korean. For handwritten forms, expect lower accuracy and plan a human review step. No current tool reads handwriting reliably enough to skip review.

Choosing the Right Tool

ToolOpen sourceTablesOCRBest for
Azure Document IntelligenceNo, managed APIStrong, with prebuilt and custom modelsYes, document-tunedForms, invoices, high-volume structured documents
LlamaParseNo, APIExcellent, VLM-basedYesComplex layouts, financial reports, RAG ingestion
UnstructuredYesGood, ML-basedYesSelf-hosted, general-purpose partitioning
Direct vision LLMDepends on modelVariableYes, via visionUnusual layouts, fallback for parser failures

Most teams end up with two tools. A managed parser handles the bulk of documents. A vision LLM handles the pages the parser fails on. The split keeps costs down and quality up. Measure the split: if more than a fifth of pages fall back to the LLM, the parser tier or the document mix is wrong.

Accuracy, Cost and Evaluation

Do not trust a demo. Build an evaluation set before you commit to a tool. Take fifty representative documents from your real workload. Extract them by hand, or at least verify the key fields by hand. Run each candidate tool over the set. Score field accuracy, table accuracy and the rate of silent errors. Silent errors are the ones that matter. A tool that fails loudly is safe. A tool that returns a wrong number with confidence is dangerous.

Cost follows page count and tier. The fast tier is cheapest and weakest. Agentic tiers cost more per page and handle complex tables. Managed services charge per page. Self-hosted open source costs engineering time and compute. For a RAG pipeline, extraction quality is also retrieval quality: a table mangled at parse time is unfindable at query time.

One more pattern helps retrieval. Generate a natural language summary of each table and embed the summary, while storing the original table for the model to read. The summary is what you search against. The original is what you pass to the model. This multi-vector retriever pattern decouples retrieval from presentation, and it works for images too.

Bottom Line

Document intelligence with LLMs works when the parser and the model each do the job they are good at. Let a layout-aware parser recover tables, forms and structure. Let the LLM map fields to a schema and resolve meaning. Validate every number, keep the evidence for every field, and route the hard pages to a human. Start with fifty real documents, score the tools against them, and pick the one with the fewest silent errors. The pipeline is only as good as its worst page.