Not every question requires the same answer shape. One question demands a single number with a citation; another needs a list with one item per row; a third expects a yes or no with a caveat. Forcing all of them through a single generation call degrades each shape. The solution is a small set of generation patterns—one per answer shape.
This article is a companion to Enterprise Document Intelligence, a series whose philosophy is outlined in Amplify the Expert. It focuses on brick 4 (generation) of the four-brick architecture and pushes back on the vocabulary teams use when a RAG answer is wrong.
Hallucination, in the strict sense, is a fabrication from the model’s parametric memory: the LLM invents a fact without any grounding in the input. In RAG, the model reads the context; when the answer is wrong, the cause is upstream, in the extraction chain (parsing, question, retrieval, or the generation contract itself). Calling every failure a hallucination closes the debate on where to act. Naming the real cause reopens it.
The mainstream narrative sees generation as send retrieved chunks + question to the LLM, get an answer string back. We reject this framework entirely. The answer is not a string. It is a typed Pydantic object with citations, fidelity flags, and self-assessment fields. The LLM is a function, not an oracle. The schema is the contract. The validator runs before the user sees anything.
📓 Reproduce the seven patterns in the shipped notebook: fill the typed AnswerWithEvidence schema on a broker-corpus question, watch each self-assessment flag flip, then rerun with the schema decomposed to see how a small model catches up to a frontier one. Repo → doc-intel/notebooks-vol1.
The naive baseline this article pushes back on
The naive pipeline asks the LLM for an answer and trusts what comes back. There is no separation between found and invented, no place to record confidence, and no way to flag not found as a first-class outcome. We fill the schema instead: every field is a question the pipeline asks, and every answer is checkable.
Below are the seven patterns that keep generation on the typed-contract side. The first six are the contract itself. The seventh names a constraint the contract must respect when the model is small.
Pattern 1 – The LLM is a function, not an oracle
The answer schema is a contract: structured retrieval in, a typed Pydantic object out, with citations, fidelity flags, and pipeline-feedback fields, never “the answer as a string”. Everything the generation step produces must be structured, checkable, and traceable. In 2026, as models shrink and deployment scales, this disciplined design becomes essential: it allows validation, debuggability, and safe fallback behavior without relying on the model's internal confidence.
