Document question answering

Also known as: document visual question answering

On this page 7

Document question answering (also called document visual question answering) is the task in which an AI system receives a document, such as a scanned form, invoice, report or PDF, together with a natural-language question, and returns an answer grounded in that document. Within Document AI, it differs from plain text question answering because the model must interpret text, layout and visual cues together: a value is often meaningful only because of its position next to a label, inside a table cell or under a heading.

The answer can be an extracted span copied from the page, a generated phrase, a yes or no, or a value computed from several fields. Modern systems combine optical character recognition, layout-aware language models and, increasingly, multimodal large language models.

How document question answering works

A document question answering system works by converting the page into a representation that preserves words and their positions, then matching the question against that representation to locate or generate the answer. Three broad architectures dominate.

ArchitectureHow it reads the pageRepresentative models
OCR plus layout modelOCR tokens with bounding boxes and image featuresLayoutLMv3, LiLT
OCR-free encoder-decoderPixels directly to answer textDonut, Pix2Struct
Multimodal LLMPage image or parsed text in a long contextGeneral vision-language models
Retrieval pipelineChunks retrieved from parsed documentsRAG with layout-aware parsing
Main architectures for document question answering

In the classic pipeline, an OCR engine such as Tesseract or PaddleOCR produces words with bounding box coordinates. A layout-aware model embeds each token with its 2D position, predicts the start and end tokens of the answer span, and returns the text in between. OCR-free models skip this step and learn reading and answering jointly from images.

Types of questions and answers

Questions differ sharply in difficulty depending on where the evidence sits and how much reasoning is needed. Benchmarks and production systems usually classify them along the lines below.

Question typeExampleMain difficulty
Key-value lookupWhat is the invoice number?Matching label to nearby value
Table lookupWhat was revenue in 2023?Row and column alignment
Multi-hop or numericWhat is the total excluding tax?Combining and computing values
Visual or layoutWhat does the checked box say?Reading marks, logos, signatures
Multi-pageWhich clause sets the notice period?Locating evidence across pages
UnanswerableWho approved it? (not stated)Abstaining instead of guessing
Question types in document question answering

Extractive answers are easier to verify because they point to exact text on the page. Generative and computed answers are more flexible but require stronger safeguards against unsupported output.

Benchmarks and evaluation metrics

Progress in document question answering is measured mainly on DocVQA, a dataset of roughly 50,000 questions over about 12,000 industry document images. Related benchmarks cover infographics, charts and multi-page documents, each stressing a different skill.

The standard metric is ANLS (average normalized Levenshtein similarity), which gives partial credit for answers that differ from the reference by small character errors, typically with a threshold of 0.5 below which the score drops to zero. Exact match and F1 are also reported, and production teams add field-level accuracy, abstention rate and human review rate.

MeasureWhat it capturesLimitation
ANLSSimilarity tolerant of OCR noiseMay reward nearly correct numbers
Exact matchStrict string equalityPenalizes harmless formatting differences
Evidence accuracyWhether the cited region is correctRequires bounding box annotation
CalibrationWhether confidence matches correctnessNeeds held-out labeled data
Evaluation measures for document question answering

For financial or legal values, ANLS can be misleading: an answer that differs by one digit scores well but is factually wrong, so numeric fields are usually evaluated with exact match after normalization.

Relation to extraction and retrieval tasks

Document question answering overlaps with key information extraction but is query-driven rather than schema-driven. Extraction fills a fixed set of fields for every document, while question answering accepts arbitrary questions at run time, which makes it suitable for exploratory review and long-tail queries.

For long contracts or document collections, systems combine it with retrieval-augmented generation. Documents are parsed with layout preservation, split into chunks, embedded and indexed; the retriever finds relevant passages, and the reader model answers from them. Poor parsing of tables and reading order is the most common root cause of wrong answers in such pipelines.

The choice between approaches depends on volume, layout variety and verification needs. A fixed extraction schema is cheaper and easier to audit when the same fields are needed from every document, whereas question answering pays off when users ask unpredictable, document-specific questions. Many production systems combine both, extracting standard fields automatically and offering question answering for exceptions.

SituationRecommended approachReason
Same fields on every invoiceKey information extractionStable schema, simple validation
Ad hoc contract reviewDocument question answeringQuestions change per case
Large document archiveRetrieval plus question answeringEvidence must be found first
Regulated numeric valuesExtraction with human reviewErrors carry high cost
Choosing between extraction and question answering

Deployment practices and failure modes

Reliable production systems treat each answer as a claim that must be traceable to evidence. Common practices include returning the page number and bounding box with each answer, setting confidence thresholds for human review and validating values against business rules.

  • OCR errors on low-quality scans propagate into answers; preprocessing such as deskewing and binarization helps.
  • Hallucinated answers from generative models appear when the document lacks the information; models should be prompted and tested to abstain.
  • Reading order mistakes in multi-column layouts mix unrelated text.
  • Table misalignment returns values from the wrong row or column.
  • Prompt injection hidden in document text can manipulate LLM-based readers and must be treated as untrusted input.

Privacy also matters: documents often contain personal data, so organizations decide carefully whether pages may be sent to external model APIs or must be processed on premises.

A non-technical view

Document question answering lets you ask a question about a document and get the answer without reading it yourself. You might ask a scanned invoice for its due date. The system finds the date and shows you where it is.

It works like a careful assistant who reads both the words and the page design. A number next to the word Total means something different from the same number in a phone field. A good system also admits when the answer is not there instead of guessing.

A concrete example

A logistics company receives about 15,000 supplier documents a month, including invoices, delivery notes and customs forms in varied layouts. Accounts payable staff previously searched each PDF by hand to answer questions such as the payment terms, the delivery address or whether a document carried a signature.

The company deployed a document question answering service that parses pages with layout-aware OCR and answers questions through a multimodal model. Each answer is returned with its page and highlighted region, and answers below a confidence of 0.85 go to human review. After three months, about 80 percent of queries were answered automatically, average lookup time fell from several minutes to seconds, and spot checks found that numeric errors came mostly from blurred faxed pages, which were then routed to manual handling.