HeadlinesBriefing favicon HeadlinesBriefing.com

Loop Engineering for RAG Question Parsing

Towards Data Science •
×

Enterprise Document Intelligence introduces loop engineering as the discipline that wraps LLM calls in bounded iterations. This article examines the smallest useful loop: a single clarification turn in question parsing before retrieval. When a user asks "what is the premium?" on a 47-page insurance policy, the parser finds no "Premium" section in the TOC. Instead of scanning the entire document, it pauses and asks: "I don't see a 'Premium' section. Where should I look?" The user's reply — "General Info" or "try under coverages" — enriches the question, and the parser re-runs, filling the missing section_hint field.

The loop operates on a fixed schema of typed fields: keywords, intent, retrieval.section_hint, retrieval.layout_hint, and structural_hints.pages_hint. Only the missing field is requested; all others persist across parse calls. The flow detects a gap, asks the user, re-parses with the enriched input, and continues to dispatch unchanged.

Three cases demonstrate the pattern: missing section_hint (topic not in TOC), missing layout_hint (answer in a table or figure), and missing pages_hint (user pins specific pages). Each uses the same schema, no new fields invented. The fuller mechanic — candidate enumeration, proposed defaults, and caching — is developed in Article 6bis.

The framing has shifted twice: prompt engineering (2023) put burden on users, context engineering (mid-2025, per Tobi Lütke and Andrej Karpathy) moved work to engineers filling the context window, and loop engineering (2026) designs the iterative cycles around the LLM. As Lang Chain notes, "the potential in agents is in the loops you build around them." Reproducible notebooks live at doc-intel/notebooks-vol1.