Building with AILesson 16 of 80

Contents

Building with AI

Lesson 16 of 80. Sign in to keep your place.

Module 2 · Prompting as engineering

Making the model quote before it answers

9 min read

Why an answer without a quote cannot be checked

Give a model ten passages and a question, and it will produce an answer that blends what it read with what it already knew from training. Both sources produce the same confident prose. Nothing in the output tells you which sentence came from where, and neither will the model if you ask it afterwards: it will generate a plausible attribution the same way it generated the answer.

The fix is structural rather than persuasive. Make quoting a required step that happens before the answer, and then verify the quote in code. That converts an unfalsifiable claim into a testable one.

The quote-then-answer pattern

Text
You are answering strictly from the passages below.

Step 1. Copy out, word for word, every sentence from the passages that
bears on the question. Put them inside <evidence> tags, each with its
passage id. Copy exactly; do not paraphrase or correct.

Step 2. Answer using only what is inside <evidence>. If <evidence> is
empty, output exactly INSUFFICIENT_CONTEXT.

<passages>
[p1] ...
[p2] ...
</passages>

Question: {{ q }}

Three properties follow from that ordering.

The extraction is easy and the model does it well: copying is a much simpler operation than synthesising. The answer is then conditioned on a short, relevant subset instead of ten passages, which measurably improves it. And you now hold a string that either does or does not appear in your source text.

Verify in code, not in the prompt

This is the step people skip, and it is the whole point.

Python
import re

def norm(s):
    return re.sub(r"\s+", " ", s).strip().lower()

def check(evidence, passages):
    bad = [q for q in evidence
           if norm(q.text) not in norm(passages[q.pid])]
    return bad          # non-empty means fabricated or altered

Normalise whitespace and case, because models reflow line breaks and fix capitalisation without being asked. Beyond that, be strict. A quote that does not appear verbatim in the passage it names is either invented or silently edited, and both are disqualifying for anything you would put in front of a user as fact.

In practice, on ordinary retrieval workloads, a small percentage of quotes fail this check, and it is a different small percentage than the answers a human reviewer would flag. It catches a failure mode nothing else catches: the confident answer built on a sentence that does not exist.

What to do with a failure is a product decision. Retry once, fall back to the sentinel, or show the answer with a warning. Whatever you choose, count it. That count is a real quality metric you can watch move.

Citations the user can use

Once you have verified quotes with passage ids, rendering citations is bookkeeping. Two things make the difference between a citation that builds trust and one that erodes it.

Deep-link to the exact place, not to the document. policy.pdf is not a citation; policy.pdf#page=14, with the quoted sentence highlighted, is. A user who clicks and lands on a 60-page PDF has been given the appearance of evidence and none of the substance.

Cite per claim, not per answer. A paragraph with one footnote at the end tells the reader nothing about which of its four assertions the source supports. If three sentences come from three passages, mark three.

The limits, stated honestly

Verified quoting is the strongest cheap defence available, and it is not a truth guarantee. Four gaps you should know about:

  • A correct quote can support a wrong conclusion. The sentence exists; the inference from it does not follow. Verification catches fabrication, not bad reasoning.
  • Selective quoting misleads. Quoting the exception while ignoring the rule above it is technically grounded and substantively false.
  • Your source can be wrong or stale. Grounding in a document from 2019 grounds you in 2019.
  • Nothing here helps if retrieval missed the relevant passage. The model can only quote what you gave it, and the honest output in that case is the sentinel, which is why the sentinel and the quoting rule belong in the same prompt.

A reasonable reading of those limits: verified quoting takes you from unknowable to auditable. That is a large step, and it is not the same as correct. Say so in your interface. “Answers are drawn from your documents and every claim links to its source” is true and useful. “Answers are accurate” is a promise no amount of prompt engineering lets you keep.

Every lesson here is open. Your progress is recorded once you pass the Python, from Zero, for AI exam.

Check your understanding

A grounded assistant produces an answer whose quotes all verify against the source passages, yet the answer is wrong. What does this show about the technique?

Pick the one you would defend. Your answer stays private.

Next lesson · 8 minScope, refusals, and a voice that stays put

Stuck on something?Ask Sayali, your AI tutor

How to cite: Addaly (2026) ‘Making the model quote before it answers’, in Building with AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/building-with-ai/grounding-and-citations (Accessed: 13 October 2026).