Document Processing with AI Agents: Extraction and Reconciliation
Design document-processing agents that preserve field provenance, reconcile records, handle OCR uncertainty, and route meaningful exceptions for review.
Abhishek Raj · · 7 min read
Prepared with AI research assistance. Sources are linked throughout; worked examples are illustrative unless stated otherwise. Editorial approach.
Document processing with AI agents works best when extraction produces reviewable evidence and reconciliation determines what may enter a business system. A model can identify an unfamiliar invoice layout or resolve a label, but a plausible JSON object is not proof that the document supports its values.
This guide proposes a hypothetical accounts-payable intake system. Its records, rules, and numerical examples are illustrative architecture choices, not a tested reference implementation or measured performance claim. The same separation between observation, interpretation, and acceptance applies to many administrative document workflows.
Separate recognition, interpretation, and acceptance
Recognition identifies text and visual structure. Interpretation maps that material into business fields. Acceptance checks whether those fields satisfy the application's evidence and policy requirements. Combining these into one instruction such as “read the invoice and create the payable” makes it difficult to locate an error or recover from it.
Amazon Textract documents separate capabilities for text detection, forms and tables, queries, and specialized expense analysis. This is a useful reminder to choose a parser for the document task rather than assume that every input requires an open-ended agent. Amazon Textract overview.
In the proposed system, deterministic routing selects a known invoice parser when possible. A bounded agent investigates missing fields or an unfamiliar layout. Neither component receives authority to change bank details or initiate payment. The accepted output is a draft payable with evidence and unresolved issues, followed by a separate authorized business operation.
Preserve a source model before flattening fields
Keep the immutable original file and assign a document identifier, content hash, tenant scope, ingestion timestamp, and parser version. A replacement upload becomes another version, even when its filename matches an earlier file. A filename is a display label, not a reliable identity.
Retain page boundaries, text locations, table relationships, and extraction identifiers alongside recognized text. Textract's Block representation includes different structural types, relationships, geometry, and confidence; its block identifiers are only unique within one operation. Therefore an application reference should include the extraction operation, not only the block ID. Textract Block reference.
A proposed field record might look like this:
{
"field": "invoice_total",
"raw_text": "1,250.00",
"normalized": {"currency": "USD", "minor_units": 125000},
"source": {
"document_version": "doc_example_18@v2",
"extraction_run": "extract_example_7",
"page": 3,
"region_id": "region_example_91"
},
"interpretation_status": "candidate",
"issues": []
}
This is an application schema, not a provider response. The currency needs its own evidence; it must not be inferred solely from the punctuation in the amount. Store the transformation that produced minor_units, including locale assumptions, so a reviewer can reconstruct the conversion.
Normalize values without erasing ambiguity
A normalized value is useful for comparison, but the raw value explains how the comparison was made. Preserve both. For an ambiguous date such as 03/04/2026, record an unresolved interpretation unless the document's locale or a trusted business convention establishes the meaning.
Google Document AI exposes recognized text, text anchors, layout positions, extracted entities, and normalized representations for supported fields. Its documentation also notes that date and currency normalization depends on location information. A normalized field should therefore remain connected to its literal source and interpretation context. Handle a Document AI processing response.
Define missingness explicitly: absent, unreadable, not applicable, and conflicting are different states. An agent should not fill an unreadable purchase-order number from a nearby historical invoice merely because that produces valid JSON. If another source supplies the value, record that source and mark the field as reconciled rather than extracted.
Use structured-output validation for admissible shapes and semantic checks. Keep monetary arithmetic in integer minor units or an appropriate decimal representation. Make rounding policy explicit, and avoid silently converting one currency into another during extraction.
Design reconciliation as a set of independent checks
Reconciliation compares claims from the document with each other and with authoritative records. Build checks whose results remain visible rather than compressing everything into one confidence score.
| Check | Proposed evidence | Possible outcome |
|---|---|---|
| Arithmetic | Line amounts, tax, discounts, stated total | Consistent or arithmetic discrepancy |
| Identity | Supplier identifier and trusted supplier record | Matched, ambiguous, or unknown |
| Ordering | Purchase order and received quantities | Supported or quantity discrepancy |
| Duplication | Supplier, invoice number, amount, prior records | Unique candidate or possible duplicate |
| Payment details | Submitted details versus approved master data | Unchanged or requires separate review |
These checks need documented tolerances. A one-cent rounding allowance may be appropriate for a particular calculation, but it must not become a general permission to ignore mismatches. A matching total also does not prove that individual line items belong to the order.
When an external lookup fails, preserve “not checked.” Do not convert an unavailable supplier database into “supplier matched.” Keep verification state separate from the field's extraction state so operational outages cannot masquerade as evidence.
Walk through a hypothetical invoice discrepancy
Suppose an invoice lists 10 units at USD 120 each, tax of USD 60, and a total of USD 1,260. The purchase order authorizes 10 units, while the receiving system confirms only eight. The scan also shows a different bank-account suffix from the approved supplier record.
The arithmetic check passes: 10 times 120 plus 60 equals 1,260. The quantity check fails, and the payment-detail check requires independent review. These are separate findings; a strong OCR score on the total should not override either one.
The agent can retrieve the relevant order and identify which evidence is missing. It can prepare a review packet explaining that two units lack receipt confirmation. It cannot assume that the receiving system is outdated or accept the new account because the invoice appears professionally formatted.
If a reviewer confirms a delayed receipt, record the referenced receipt version and rerun the dependent quantity check. The account discrepancy remains unresolved until its separate authorization process completes. Approval of one issue must not implicitly clear every issue on the document.
After acceptance, creating the draft payable uses a stable business-action identity. A timeout may mean that creation succeeded without a response, so recovery queries the operation record instead of creating another payable. See idempotency for agent actions for that execution boundary.
Make the review queue preserve decision context
Route cases using risk and unresolved conditions, not confidence alone. A low-confidence postal address and a high-confidence bank-account change need different handling. AWS recommends choosing confidence thresholds according to the application's sensitivity and sending uncertain results for additional scrutiny. It does not establish one universally safe threshold. Textract best practices.
A proposed review item includes the original page crop, raw and normalized values, conflicting records, checks already performed, parser and rule versions, and the requested decision. Give reviewers structured choices such as correct field, request replacement document, reject, or accept a specific exception with a reason.
Use a claim or lease so two reviewers do not unknowingly resolve the same case. Bind the submitted decision to the document version and review-item revision. If another upload or external update changes relevant evidence, explain the change and require reconsideration rather than applying a stale decision.
Review corrections should produce attributed amendments. Preserve the machine candidate and reviewer correction separately; replacing the original value destroys information needed to evaluate extraction quality. Restrict sensitive page access and retention according to the application's actual requirements.
Evaluate the entire acceptance pipeline
Measure more than field accuracy. Track evidence-location correctness, line-item grouping, arithmetic-check coverage, false acceptance, unnecessary review, reviewer repair effort, and successful draft creation without duplicates. Separate results by document family and scan quality; an aggregate score can hide failure on a consequential layout.
Microsoft's response documentation distinguishes logical text spans from visual bounding regions and notes limitations around reading order. Test the mapping between your stored text offsets and displayed page evidence, especially for tables crossing pages and multi-column layouts. Document Intelligence response structure.
Create cases with missing pages, rotated scans, repeated headers, duplicate uploads, conflicting totals, altered supplier details, and tool outages. Inject failures after extraction, during review, and after downstream creation. Verify that an expired review lease or repeated queue delivery cannot silently change an accepted result.
Use a held-out collection with protected labels and document-family splits, following the principles in agent evaluation datasets. A correction collected during review can improve later regression tests, but it must not leak into the holdout used to claim improvement.
Frequently asked questions
Should an LLM replace OCR?
Choose the recognition method through representative evaluation. OCR and document parsers expose useful structural evidence; a language or vision model can assist interpretation. The acceptance contract should remain independent of which component produced a candidate.
Can a high confidence score eliminate human review?
Only a validated policy can decide which cases qualify for automated acceptance. Confidence about recognized text does not establish supplier authorization, purchase-order agreement, or safe payment details. Evaluate those conditions separately.
What should happen when a required field is missing?
Return an explicit unresolved state with available evidence. Request another document or route the case for review. Do not invent a value merely to satisfy a downstream schema or keep the queue moving.
Source reference list
Related reading
- Structured LLM Outputs: JSON Schema and Semantic Validation
Validate structured LLM outputs beyond JSON syntax with evidence checks, domain rules, refusal handling, bounded retries, and explicit action boundaries.
- Idempotency for AI Agent Actions: Preventing Duplicate Side Effects
Prevent duplicate AI agent actions with stable intent identities, immutable request fingerprints, durable ledgers, and recovery for uncertain outcomes.
- Building AI Agent Evaluation Datasets Without Data Leakage
Build AI agent evaluation datasets with controlled task families, protected holdouts, grounded labels, retrieval leakage checks, and evolving failure sets.