TL;DR
CACHE-ED2 transforms Large Language Models (LLMs) from expensive "instance-level analysts" into efficient "system-level developers." By having an LLM write a reusable, deterministic program (DocExDSL) for every new document format it encounters, the system achieves near-perfect extraction accuracy while slashing token costs by ~62% compared to standard LLM prompting.
What Problem Does This Paper Address?
Extracting structured data from visually rich documents (like invoices or receipts) at an enterprise scale is a "pick two" problem: you can have reasoning capability, efficiency, or scalability, but rarely all three.
Standard LLMs are great at reasoning but are prohibitively expensive and slow if you query them for every single document. On the other hand, traditional template-based systems are fast but brittle—a slight tilt in a scan or a minor OCR error can break the extraction logic. The authors' previous work, CACHE-ED, tried to bridge this by "caching" LLM reasoning, but it suffered from "template fragility," where minor visual perturbations caused cache misses and forced expensive LLM re-calls.
Methods
CACHE-ED2 introduces a "compile-once, execute-many" architecture consisting of four main innovations:
- DocExDSL: A custom, imperative domain-specific language. Instead of the LLM outputting raw data, it outputs a Python-embedded program that encodes extraction strategies (e.g., "look to the right of 'Total'"), disambiguation logic, and validation rules.
- Contrastive Document Format Encoder: Built on the LiLT (Language-Independent Layout Transformer) architecture, this encoder creates robust "format embeddings." Unlike previous graph-matching methods, this is highly resistant to OCR noise and scan skews, ensuring that documents of the same format always trigger the correct cached program.
- Multimodal ReAct Generation Agent: This is the "developer" LLM. When it sees a new format, it uses a ReAct (Reason + Act) loop to write, execute, and debug its own DocExDSL code against the document image until the extraction is perfect.
- HITL Feedback Analysis Agent: A "critic" agent that listens to human corrections. Instead of just fixing a single field, it analyzes the error to update the underlying DocExDSL program, effectively learning new business rules (SOPs) on the fly.
Datasets
The researchers evaluated CACHE-ED2 on a mix of public and private data:
- CORD v2: A public benchmark of over 11,000 receipt images.
- FATURA: A public invoice dataset with 10,000 images across 50 distinct layouts.
- Real-World Corpus: 5,000 production invoices from five major vendors, used to test complex business logic like derived due dates and service periods.
Key Insights and Ideas
- LLMs as Compilers, Not Clerks: The most significant shift is moving the LLM out of the "hot path" of inference. By using the LLM to synthesize logic rather than retrieve values, the system gains the reasoning power of a frontier model (like Claude 3.5 Sonnet) with the sub-second execution speed of a deterministic script.
- Closing the Loop with Self-Debugging: The Generation Agent doesn't just "guess" the code. It uses the execution engine as a tool, running its generated DSL and checking the results against its visual "reading" of the document to fix its own bugs before the program is ever cached.
- Learning SOPs from Corrections: The system can infer complex business rules—like "the service period start is always the first day of the month of the billing end date"—simply by observing how a human analyst corrects a single field.
Key Results
- Near-Perfect Accuracy: CACHE-ED2 achieved an average extraction accuracy of 0.99 and a 1.0 extraction rate across 50+ templates.
- Perfect Format Detection: The new contrastive encoder achieved a 100% cache hit rate, a massive improvement over the 47% average of the original CACHE-ED.
- Massive Cost Savings: Over a sequence of 1,000 documents, CACHE-ED2 reduced cumulative token consumption by ~2.6x (62%) compared to a standard LLM baseline. As the volume of documents increases, these savings grow even further because cached documents cost zero LLM tokens to process.
- Speed: Once a program is cached, extraction happens in sub-second latency without any model inference.
Limitations and Future Work
While highly effective, the authors note a few areas for growth:
- Multi-page Context: The current format encoder primarily looks at the first page. Future versions could incorporate multi-page visual features for more complex document types.
- Cross-Vendor Pollination: Currently, programs are cached per vendor/format. The authors suggest that the system could eventually learn to synthesize common patterns across different vendors within the same industry (e.g., all utility companies) to reduce "cold-start" latency.
- DSL Evolution: As the agent identifies patterns it can't currently express, the DocExDSL itself will need to evolve to handle increasingly complex extraction scenarios.
Summary updated