Every RAG system is built on three engineering layers stacked over a single LLM call. Prompt engineering is the call itself: the system message, instructions, and schema that fix the output shape. Context engineering fills the model's window: retrieval, compression, and deliberate exclusion. Loop engineering governs what happens around the call: when the next call fires, when the loop stops, and how the system recovers from failed checks. Most debates about RAG are really about which layer you're discussing. Name the layer, and the confusion clears. This article serves as a map: what each layer owns, how they map onto the series, and why the tidy narrative of "one replaced the next" is only half true.
This article is a manifesto of Enterprise Document Intelligence, a series that builds an enterprise RAG system from four foundational components. It adopts the three-layer framing—prompt, context, loop—that has become the dominant narrative in 2026, and asks: is the evolution from one layer to the next a true sequence, or a retrospective story imposed on patterns that have always existed?

📓 The series' companion notebooks live on GitHub at doc-intel/notebooks-vol1. Each notebook runs a component end-to-end on a real PDF, letting you observe the three layers in action: the prompt that fixes the answer shape, the context assembled from a parsed question and retrieved pages, and the loop that retries when a check fails.

1. The Three-Layer Framing
Three disciplines stack on top of an LLM call. Each controls a different lever; together they describe most of what production teams do beyond "hello world."

Prompt engineering is the layer everyone encounters first. The model needs a system message establishing its role and constraints, a user message carrying the question and context block, and optionally a schema that locks the output shape. Crafting these three pieces well is the difference between a model that follows rules and one that improvises. This discipline emerged in 2022–2023 with GPT-3.5 and ChatGPT; the term "prompt engineering" entered public discourse around the same time.
Context engineering is the layer that becomes essential when the prompt alone is insufficient. The model has a finite context window; the practitioner decides what fills it. Retrieval selects relevant documents; compression removes noise; isolation keeps sub-agent outputs out of the main window. The four canonical strategies—LangChain's write, select, compress, and isolate—formalize what practitioners had been doing implicitly since the first RAG paper. The term "context engineering" gained traction in 2025, with public usage by Karpathy and Tobi Lütke, and Anthropic's canonical Effective context engineering for AI agents published that year.
Loop engineering is the layer that emerges when a single call is no longer sufficient. The model produces a plausible answer that fails schema validation. The listing returns twelve items, but the model flags the answer as incomplete. An API call times out, or the agent selects the wrong tool. The loop manages these failures through retries, error handling, and state tracking. In 2026, with multi-step agents becoming the norm, loop engineering has increasingly relied on deterministic frameworks (like DSPy and LangGraph) that explicitly plan and iterate over LLM calls.
These layers are not sequential steps but cumulative capabilities. A "hello world" RAG system might rely solely on prompt engineering; production-grade systems deploy all three, each refining the others.
2. Mapping the Layers to the Series
The Enterprise Document Intelligence series builds a RAG system from four components, each demonstrating one or more layers:
- Brick 1—Parsing: Converts PDFs into structured text, ensuring retrieval inputs are clean.
- Brick 2—Retrieval: Implements context engineering—selecting documents, compressing chunks, and isolating irrelevant data.
- Brick 3—Synthesis: Applies prompt engineering to generate answers conforming to expected schemas.
- Brick 4—Verification: Embodies loop engineering, checking outputs and triggering retries when validation fails.
Each notebook in the series demonstrates these layers in practice, showing how prompt, context, and loop interact to produce reliable answers.
3. Why the "Replacement" Story Is Half True
A common narrative suggests that prompt engineering gave way to context engineering, which then gave way to loop engineering—a linear progression. But this view obscures a critical reality: each layer builds on—and enhances—the others. A well-crafted prompt is useless without good context to fill the window; a robust retrieval pipeline fails without a loop to handle edge cases. In 2026, the most advanced systems weave all three together, using prompt engineering to guide retrieval, context engineering to inform loop decisions, and loop engineering to refine prompts for subsequent calls.
For example, a fail loop might detect an incomplete answer, trigger a new retrieval with adjusted parameters, and a revised prompt based on the partial output. The layers are interdependent, not sequential.
4. The Three-Layer Model in Practice
Consider a real-world RAG system for enterprise document processing. The prompt defines the answer format (e.g., JSON with specific fields). Context engineering retrieves and compresses relevant text from a database. Loop engineering monitors the output, checks for errors, and initiates retries if the schema is violated. This integrated approach is now standard in 2026, as teams recognize that no single layer suffices for production reliability.
As the AI field evolves—with models gaining longer context windows and multi-agent orchestration becoming common—the three-layer framing remains a stable foundation. The artifacts may change (e.g., context windows expand from 200K to 1M tokens), but the engineering disciplines persist.
5. Conclusion
The prompt, context, and loop layers form the backbone of every RAG system. By naming them, we resolve much of the confusion in current AI discussions. This map, along with the companion notebooks, gives engineers a practical toolkit to diagnose and improve their systems. The evolution from one layer to the next is not a replacement; it's an accumulation. In 2026, building robust RAG systems means mastering all three.
