Loop Engineering with Adaptive Parsing in Action: Parsing Flat Tables with Azure and Figures with a Vision LLM

The evolution of enterprise-grade Retrieval-Augmented Generation (RAG) systems has hit a critical bottleneck: the "silent failure" of document parsing. While modern Large Language Models (LLMs) are increasingly capable of synthesizing information, the quality of their output remains strictly tethered to the structural integrity of the input data. In many enterprise environments, classic Optical Character Recognition (OCR) and basic PDF parsers recover individual words but quietly discard the structural context—such as tables, figures, and complex layouts—leaving the LLM to hallucinate answers based on a "pulp" of unstructured text. To address this, a new philosophy of adaptive parsing is emerging, utilizing a multi-stage escalation cascade that balances computational cost with absolute data accuracy.

The Economic and Technical Tension in Document Parsing
In the realm of Enterprise Document Intelligence, organizations face a stark choice between speed and precision. Low-cost parsers, such as PyMuPDF (fitz), can process a document page in approximately five milliseconds at effectively zero cost. These tools are highly efficient for plain prose but fail significantly when encountering complex visual data. At the other end of the spectrum, vision-capable LLMs and sophisticated layout-aware parsers like Azure Document Intelligence or IBM’s Docling can interpret complex tables and diagrams with high fidelity. However, these tools can cost ten thousand times more than their simpler counterparts and require several seconds of processing time per page.
Running the heaviest parser on every page of a million-page enterprise corpus is financially and operationally prohibitive. Conversely, relying solely on the cheapest parser leads to "plausible-looking nonsense," where an LLM answers a user’s question with full confidence based on a corrupted parse that nothing upstream flagged as an error. The solution currently being implemented in advanced RAG architectures is the feedback loop: a system that starts with the cheapest parsing method and escalates to heavier tools only when specific "checks" signal that the current parse is insufficient for the user’s query.

The Eight-Step Escalation Cascade: A Chronology of Validation
The implementation of adaptive parsing relies on a series of checks, ordered from cheapest and most deterministic to most expensive and probabilistic. This cascade ensures that the system only "pays" for high-intensity parsing when the complexity of the document or the specificity of the question demands it.
- Character Density and Integrity: Initial deterministic checks at the parsing stage to ensure text is readable and not corrupted.
- Flat-Table Fingerprinting: Identifying regions that appear to be tables but have been flattened into single-column text.
- Chunk Integrity: Ensuring that the retrieval units (chunks) maintain logical coherence.
- Intent-Aware Routing: Analyzing the user’s question during the "Question Parsing" phase to see if it specifically asks for tabular or visual data.
- Score-Gap Analysis: Checking the confidence scores of retrieved documents.
- Context-Gap Analysis: Evaluating whether the retrieved text contains the necessary entities to answer the question.
- LLM Self-Evaluation: The generating LLM evaluates its own input before presenting an answer, looking for structural risks.
- Post-Generation Groundedness: A separate LLM or Natural Language Inference (NLI) model verifies that the final answer is fully supported by the source citations.
While the first six steps are designed to catch failures before they reach the generation phase, steps seven and eight serve as the "last line of defense."

Case Study A: Recovering Table Structure via Azure Layout
A primary example of the necessity of this cascade can be found in the analysis of technical papers, such as the seminal "Attention Is All You Need" (Vaswani et al., 2017). When a user asks for a specific value within "Table 3: Variations on the Transformer architecture," a standard parser like PyMuPDF often flattens the table into a series of disconnected lines.
In a recent technical walkthrough, the question "What is the value of h for the base model?" was put to a RAG pipeline. The initial PyMuPDF parse returned the value "8," which was correct, but the LLM flagged the result with a context_structured=False trigger. Even though the answer was right, the LLM recognized that it had to "count" columns in a flattened header—a fragile process prone to error.

The system then triggered an escalation to Azure Document Intelligence. This secondary parse recovered the table as a structured markdown grid. With the structure restored, the LLM could confirm the answer with high confidence, anchoring the value "8" to the specific "h" column and "base" row. The cost of this escalation was approximately $0.003 and four seconds of latency, a small price to pay for moving from a "lucky guess" to a structurally verified fact.
Case Study B: Navigating Opaque Diagrams with Vision LLMs
The second failure shape often encountered is the "opaque diagram." In the same Transformer paper, Figure 1 illustrates the encoder-decoder architecture. A text-based parser sees this only as an image placeholder with no content. When a user asks, "What is the architecture of the Transformer?", the prose in the document provides only a partial answer.

In this scenario, the LLM’s self-evaluation (Check 7) identifies that a figure is referenced in the text but is missing from the provided context. The pipeline then routes the specific image coordinates to a vision-language model (such as GPT-4o). The vision model generates a structured text description of the diagram, detailing the residual connections, layer normalization, and multi-head attention blocks. This new data is appended to the document’s record, allowing the final generation pass to provide a comprehensive, high-confidence answer that would have been impossible with text parsing alone.
Supporting Data: The Unreliability of the LLM Signal
While the "LLM as a judge" is a powerful tool, recent stress tests involving 18 distinct runs across various models (GPT-4o, GPT-4o-mini, GPT-4.1) and parsers reveal a significant caveat: the LLM’s binary verdict on its own context is not always stable.

In testing "inheritance" questions—where the answer depends on understanding that a blank cell in a table inherits a value from the cell above it—weaker models frequently failed. Specifically, when a model provided a wrong answer, it almost never flagged the parse as problematic. Instead, it "fabricated" a logical path through the corrupted data and asserted that the structure was clean (context_structured=True).
The data showed that:

- Wrong answers were rarely flagged: Out of four incorrect responses in the stress matrix, zero were flagged by the models as having structural issues.
- Stronger models are more honest: GPT-4.1 was the only model to conservatively flag structural risks even when it managed to find the correct answer.
- Continuous scores are deceptive: Replacing a binary "True/False" flag with a 0.0 to 1.0 confidence score did not improve reliability. Scores for both right and wrong answers clumped around the 0.90 mark, making it impossible to set a functional threshold for escalation.
These findings suggest that the LLM’s rationale—the text explanation of why it thinks a parse is good or bad—is far more useful than its final verdict. A stable feedback loop should, therefore, apply deterministic rules to the LLM’s rationale (e.g., looking for keywords like "split headers" or "blank cells") rather than relying on a binary flag.
Operational Impact: The Data Model as a Dynamic Cache
A significant advantage of this adaptive approach is that the data model itself becomes a cache. When a page is escalated and re-parsed with a more expensive tool, the result is stored back into the system’s primary dataframes (line_df and page_df).

This creates a "learning" system. The most frequently queried documents and sections gradually "level up" to high-fidelity parses, while the vast majority of the "dark data" in the enterprise corpus remains stored in the cheaper, lower-fidelity format. This "lazy enrichment" ensures that the organization only spends its compute budget on the data that actually provides value to the end-users.
Broader Implications for Enterprise AI
The shift toward adaptive parsing represents a move away from "one-size-fits-all" data ingestion. As enterprise RAG systems move from experimental prototypes to production-ready tools, the ability to handle complex, real-world documents with the same precision as a human expert is paramount.

The integration of vision LLMs, layout-aware OCR, and multi-stage feedback loops allows organizations to build "Document Intelligence" that is both scalable and auditable. By maintaining a strict audit trail—where every answer can be traced back to a specific bounding box on a source PDF—enterprises can mitigate the risks of LLM hallucination and ensure that their AI initiatives are grounded in verifiable fact. The future of the field lies not just in better models, but in the engineering of more sophisticated loops that allow those models to recognize their own limitations and ask for better data when they need it.







