4.4.15 · D4Alignment, Prompting & RAG

Exercises — Hallucination mitigation

2,634 words12 min readBack to topic

Before we start, one reminder of the two core formulas the parent note built, so this page stands on its own.

Two kinds of hallucination reappear all over this page, so we pin them down once here (the parent note only names them):

See the parent: Hallucination mitigation. Prerequisites you may want open: RAG pipeline, Model calibration, Chain-of-thought reasoning, Evaluation metrics for LLMs.


Level 1 — Recognition

L1.1 Classify each error as factuality (fails against real-world truth) or faithfulness (contradicts the given context).

  • (a) Context says "the merger closed in 2019"; model writes "the merger closed in 2021".
  • (b) No context given; model writes "The capital of Canada is Toronto".
  • (c) Context lists three authors; model cites a fourth author not in the context.
Recall Solution
  • (a) Faithfulness. The model contradicts the provided text, regardless of what's true in the world. The source is the ground truth here.
  • (b) Factuality. No context to be faithful to; it just contradicts reality (the capital is Ottawa).
  • (c) Faithfulness. The claim is unsupported by the given context — it added information not present, which is an unfaithful extrapolation. Rule of thumb: Is there a source to check against? If yes and it contradicts → faithfulness. If the failure is only against the real world → factuality.

L1.2 For each described technique, name which of the three walls it belongs to: Wall 1 Grounding (before), Wall 2 Constrained generation (during), Wall 3 Verification (after).

  • (a) Inserting retrieved passages into the prompt.
  • (b) Requiring [source] tags on every claim.
  • (c) Sampling 5 answers and taking the majority vote.
Recall Solution
  • (a) Wall 1 (Grounding). It happens before generation — you feed facts in. This is RAG.
  • (b) Wall 2 (Constrained generation). Citations shape how the model writes while generating.
  • (c) Wall 3 (Verification). Self-consistency compares outputs after they are produced.

Level 2 — Application

L2.1 An answer decomposes into these atomic claims, marked supported (✓) or not (✗): {Einstein born 1879 ✓, born in Ulm ✓, developed relativity ✓, won Nobel in 1921 ✓, won Nobel for relativity ✗ (it was the photoelectric effect), emigrated to the USA ✓}. Compute , , the HallucinationRate, and Faithfulness.

Recall Solution

Count claims: there are 6 → . Supported ones: 5 → . Sanity check: the two must sum to 1 → . ✓

L2.2 Given these five answered questions : . Compute Coverage and Risk at .

Recall Solution

Step 1 — apply the threshold. Keep only : that's . So 3 of 5 are answered. Step 2 — count errors among answered. Of the kept three, the was wrong. So 1 wrong out of 3. Note and were abstained (below ), so their correctness never enters Risk — that's the point of selective risk.


Level 3 — Analysis

L3.1 Using the same five questions from L2.2, sweep over the three "interesting" cut-offs where the answered set changes: , , . For each, give (Coverage, Risk). Then state which a medical deployment (wrong answers very costly) should prefer, and why.

The figure below plots this sweep so you can see the trade-off before reading the numbers. How to read it: the horizontal axis is Coverage (fraction of questions the model attempted), the vertical axis is Risk (error rate among only the attempted ones). Each orange dot is one value of , labelled beside it. The teal line connects them in order of increasing ; the orange arrow marks the direction grows. As you slide up, the dot moves left (fewer answered → lower Coverage) and down (fewer of those are wrong → lower Risk). The dashed plum line is the medical Risk cap of : only the rightmost point that sits below that line is acceptable.

Figure — Hallucination mitigation
Recall Solution

Data recap: .

  • : answered = all 5. Wrong = 2 (the and ). Coverage , Risk .
  • : answered = = 3. Wrong = 1. Coverage , Risk .
  • : answered = = 1, correct. Coverage , Risk . Trend: as rises, Coverage falls monotonically and Risk (usually) falls too — you trade attempting fewer questions for fewer mistakes among those you attempt. This is the risk–coverage curve, and matches the down-and-left motion of the dots in the figure. Medical choice: pick — a wrong medical answer is catastrophic, so we accept low coverage (only answer the surest case) to drive Risk to 0, the only point below the plum cap. The abstained questions get escalated to a human. See Model calibration.

L3.2 Temperature is a knob on the model's randomness during generation. Concretely, the model produces a score for each possible next token and turns those scores into probabilities; rescales the scores before that conversion. Large flattens the probabilities (all tokens become more equally likely → more randomness); sharpens them until all probability piles onto the single highest-scoring token (pure greedy, no randomness). Explain, using the two hallucination sources defined at the top of this page, why setting removes decoding-randomness hallucinations but not knowledge-gap hallucinations. Give a one-line concrete failure of .

Recall Solution

Why it fixes decoding randomness: at the probability collapses onto the single highest-probability next token (greedy). No low-probability token can be sampled, so sampling-induced (variance) fabrications vanish entirely. Why it does NOT fix knowledge gaps: if the model's most likely token is itself wrong (because the fact was rare/absent in training, so it interpolated a plausible-but-false fill-in), greedy decoding will confidently emit that wrong token — every single time, deterministically. This is a bias problem, and only touches variance. Concrete failure: Ask an obscure "What year did [tiny company] IPO?" — at it will state one specific wrong year, confidently, on every run.


Level 4 — Synthesis

L4.1 You must deploy a customer-support bot over a fixed knowledge base, target Risk ≤ 0.05 among answered questions, and maximize Coverage subject to that. Design a pipeline using the three walls, and justify each component by the specific hallucination source it attacks.

The diagram below is the pipeline you should end up describing — trace a question left to right through the three walls into abstention.

Figure — Hallucination mitigation
Recall Solution

First, one term this problem leans on:

  • Objective mismatch: LLM training rewards likely (fluent) continuations, not true ones — a smooth lie scores as well as a clunky truth. So the model has no built-in incentive to prefer facts; we must impose one externally. That is exactly what grounding + verification do.

A defensible design (order matters):

  1. Wall 1 — RAG grounding: retrieve top- passages, instruct "answer only from context; else say you don't know." Attacks: knowledge gaps + objective mismatch — it supplies the missing fact and forces the reward to depend on the supplied text, converting a hard factuality task into an auditable faithfulness task.
  2. Wall 2 — quote-then-answer with [source] citations and low for factual turns. Attacks: decoding-randomness (low ) and makes ungrounded claims visible (uncited → filterable).
  3. Wall 3 — claim verification against retrieved text (each atomic claim must be supported by a cited passage) + self-consistency on borderline cases. Attacks: the model ignoring/misreading context (faithfulness), and unstable fabrications.
  4. Calibrated abstention: derive a confidence score (e.g. fraction of claims that were verified, or self-consistency agreement) and pick threshold = the smallest whose empirical Risk on a held-out set. This maximizes Coverage while respecting the risk cap — you move down as far as the risk budget allows. Key justification: no single wall suffices — RAG can fetch wrong passages (so verify), verification needs something to check (so cite), and even good pipelines have residual errors (so abstain). This is the mnemonic G-C-A-V.

Level 5 — Mastery

L5.1 (Edge cases of the rate formula). Handle every degenerate input.

  • (a) An answer with atomic claims (e.g. "I'm not sure, could you clarify?"). What are HallucinationRate and Faithfulness?
  • (b) , . Rate and Faithfulness?
  • (c) , . Rate and Faithfulness?
  • (d) A single claim () that is unsupported.
Recall Solution
  • (a) Both undefined (0/0). With no factual claims, both and are — there is nothing to be right or wrong about, so neither ratio is defined. Convention: report a pure abstention as HallucinationRate and Faithfulness (it makes no unsupported claim, but also earns no supported claim), and instead record this answer as an abstention that lowers Coverage, not something that enters Risk. This is why abstention and hallucination must be tracked as separate axes.
  • (b) Rate ; Faithfulness . Perfectly grounded.
  • (c) Rate ; Faithfulness . Every claim is a fabrication.
  • (d) Rate . A single lie yields rate 1 — the formula has full resolution even at . Bounds: for any , since , the rate always lies in and Rate Faithfulness exactly.

L5.2 (Self-consistency is a majority vote). You sample independent answers to a factual question; each is correct with probability and, when wrong, gives a fixed alternative wrong answer. Under majority voting, the final answer is correct if at least 3 of 5 samples are correct. Compute the probability the voted answer is correct, and compare to the single-sample .

Recall Solution

Why binomial? Each sample is an independent yes/no ("correct") trial with success prob . The count of correct samples out of 5 follows a Binomial. Majority (≥3 of 5) is correct. Compute term by term:

  • Sum . Interpretation: voting lifts accuracy from to — because correct answers are the stable attractor and the scattered wrong ones rarely reach majority. This only works when ; below that, voting would amplify the error instead.

Active recall

Recall One-line answers (hide, then check)
  • Rate for ? ::: .
  • As rises, Coverage does what? ::: Falls (you attempt fewer questions).
  • Does fix knowledge-gap hallucinations? ::: No — it makes the confident wrong answer deterministic.
  • Self-consistency helps only when per-sample accuracy is...? ::: Greater than .
  • Rate + Faithfulness equals? ::: Exactly (for ).