4.4.15Alignment, Prompting & RAG

Hallucination mitigation

2,044 words9 min readdifficulty · medium

WHAT is a hallucination?

Two flavors you must separate:

Type Fails against Example Main fix
Factuality real-world truth "The capital of Australia is Sydney" Retrieval (RAG), better data
Faithfulness the given context Doc says 2019; model says 2021 Grounding + citations

WHY do LLMs hallucinate?


HOW to measure it (so we can reduce it)

We treat the model as a classifier of claims into {supported, unsupported}.

Figure — Hallucination mitigation

The mitigation toolbox (ordered by 80/20 impact)

1. Retrieval-Augmented Generation (RAG)

Inject retrieved passages into the prompt and instruct: "Answer only using the context; if not present, say you don't know." This converts a factuality task into a faithfulness task, which is far easier to enforce and audit (citations). See RAG pipeline.

2. Force citations / quote-then-answer

Require [source] tags. Ungrounded claims become visibly uncited → easy to filter.

3. Lower temperature for factual tasks

T0T \to 0 makes decoding near-greedy, cutting low-probability invented tokens.

4. Self-consistency

Sample kk answers; keep the majority answer. Hallucinations are often unstable across samples, truths are stable.

5. Self-check / chain-of-verification (CoVe)

Model drafts → generates verification questions → answers them independently → revises. Independence prevents it from just re-justifying its own error.

6. Calibrated abstention

Train/prompt the model to output "I don't know" when evidence is missing; set threshold τ\tau via the risk–coverage curve above.


Worked examples


Common mistakes (Steel-man → Fix)


Active recall

Recall Quick self-test (hide, then answer)
  • Difference between factuality and faithfulness hallucination?
  • Why does high confidence NOT imply correctness in LLMs?
  • What does raising the abstention threshold τ\tau do to risk and coverage?
  • Why decompose answers into atomic claims?
Recall Feynman: explain to a 12-year-old

Imagine a super-fast storyteller who never wants to look stuck. Ask anything and it instantly gives a smooth answer — even when it doesn't actually know, it just makes up something that sounds right. That made-up part is a "hallucination." To stop it we do three things: (1) hand it the answer book first (retrieval) and say "only use this"; (2) make it show its sources so we can catch the invented bits; (3) let it say "I'm not sure" instead of guessing. We also ask it the same question a few times — the real answer stays the same, the made-up one keeps changing, so we spot the fake.


Flashcards

What is an LLM hallucination?
A fluent, confident output that is factually wrong or unsupported by the given context, produced because the model predicts likely tokens rather than true ones.
Factuality vs faithfulness hallucination?
Factuality contradicts real-world truth; faithfulness contradicts the provided source/context.
Formula for hallucination rate over N atomic claims with C supported?
(N − C)/N.
Why does self-consistency reduce hallucinations?
Correct facts are stable across samples while fabrications vary, so majority voting filters the unstable false answers.
Effect of raising abstention threshold τ?
Coverage decreases (fewer answered) and selective risk decreases (fewer errors among answered).
Why doesn't RAG fully eliminate hallucinations?
The model can ignore/misread context (faithfulness failure) or the retriever can fetch wrong passages.
Why is temperature=0 insufficient alone?
It removes sampling-based errors but not knowledge-gap errors — it confidently returns the single most likely wrong answer.
Chain-of-Verification (CoVe) core idea?
Draft → generate verification questions → answer them independently → revise, so the model doesn't just re-justify its own mistake.
Why decompose answers into atomic claims for scoring?
So one false claim doesn't hide among true ones; you get a granular faithfulness fraction (FActScore).
Selective risk definition?
Error rate computed only over the questions the model chose to answer (confidence ≥ τ).

Connections

  • RAG pipeline — the primary grounding mechanism
  • Prompt engineering — "answer only from context / say I don't know"
  • RLHF and alignment — why models become over-confident and how to train abstention
  • Model calibration — turning raw confidence into trustworthy uncertainty
  • Chain-of-thought reasoning — reasoning + verification steps
  • Evaluation metrics for LLMs — FActScore, risk–coverage curves

Concept Map

not a

always outputs

when ungrounded

type 1

type 2

fixed by

fixed by

caused by

measured by

decomposed via

reduced by

trade-off

LLM next-token predictor

Truth database

Plausible-sounding text

Hallucination

Factuality error vs world

Faithfulness error vs context

Retrieval RAG

Grounding + citations

Objective mismatch, gaps, no IDK, decoding

HallucinationRate = N-C over N

FActScore atomic claims

Abstention above threshold tau

Risk vs Coverage

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, ek LLM basically ek next-token predictor hai — woh sochta nahi ki "yeh sach hai ya nahi", woh sirf predict karta hai ki agla shabd kya aana chahiye jo natural lage. Isliye jab usko koi fact nahi pata, tab bhi woh confidently kuch bana ke bol deta hai — usko hi hallucination kehte hain. Problem yeh hai ki galat answer bhi utna hi smooth aur confident lagta hai jitna sahi answer, toh sirf sun ke pakadna mushkil hai.

Isko kam karne ka sabse bada trick hai RAG (grounding) — pehle relevant documents retrieve karo, model ko do, aur bolo "sirf isi context se answer do, warna keh do 'mujhe nahi pata'". Isse factuality problem ek faithfulness problem ban jaati hai jo check karna easy hai (citations se). Dusra, factual kaam ke liye temperature kam rakho taaki random low-probability shabd na aaye. Teesra, self-consistency — same question 5 baar poocho, majority answer lo, kyunki sach har baar same aata hai par jhoot badal jaata hai.

Ek zaroori baat: confidence ka matlab correctness nahi hai. Model miscalibrated hota hai, poori confidence se galti bol sakta hai. Isliye hum abstention threshold τ\tau use karte hain — jab confidence kam ho, model answer na de. τ\tau badhao toh galtiyan kam hoti hain par kam sawaalon ka jawab milta hai (yeh risk–coverage trade-off hai, diagram mein dekho). Aur answer ko chhote-chhote atomic claims mein todo, har claim alag se verify karo — tabhi pata chalega exactly kitna hissa hallucinate hua.

Yaad rakhne ke liye mnemonic: G-C-A-V — Ground, Cite, Abstain, Verify. Bas yeh chaar walls laga do aur hallucination kaafi kam ho jaayega.

Go deeper — visual, from zero

Test yourself — Alignment, Prompting & RAG

Connections