Describe a concrete, production runnable mechanism to detect hallucinations in a RAG answer (claims unsupported by the retrieved chunks), as the answer is generated or just after.
You are running a production RAG system. Describe a concrete mechanism (not 'just have humans review them') that flags when an answer contains claims unsupported by the retrieved chunks. Cover the inputs, the check, and what happens on a positive detection.
Split the answer into atomic claims, ask a smaller judge LLM whether each claim follows from the retrieved chunks, aggregate to a faithfulness score, and refuse, retry, or log when the score is below threshold.
Imagine a student wrote a five-sentence answer and you want to check whether each sentence is actually backed by the textbook pages you handed them. You go sentence by sentence and ask 'is this in the pages or not?'. If most sentences check out, you accept the answer. If a sentence is invented, you flag it. A production RAG system does exactly this with a smaller AI playing the role of the checker. The big AI writes the answer; the small AI compares each claim against the retrieved chunks. If the small AI flags too many unsupported claims, the system either refuses, retries with stricter instructions, or saves the case for a human reviewer.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: name LLM-as-judge claim grounding, specify both inputs (answer plus chunks), describe per-claim decomposition and judge prompt, give the three gating actions, and close with the sampling versus full coverage cost tradeoff.
import re
JUDGE_PROMPT = """You are a grounding judge.
Claim: {claim}
Retrieved chunks:
{chunks}
Does the claim follow from these chunks?
Answer one of: yes / no / partial.
If yes or partial, quote the supporting span.
If no, explain briefly."""
def split_claims(answer):
return [s.strip() for s in re.split(r"(?<=[.!?])\s+", answer) if s.strip()]
def judge_claim(claim, chunks, judge_llm):
out = judge_llm.complete(JUDGE_PROMPT.format(claim=claim, chunks=chunks))
return out.split()[0].lower() # yes / no / partial
def faithfulness_score(answer, chunks, judge_llm="claude-haiku-4.7"):
claims = split_claims(answer)
verdicts = [judge_claim(c, chunks, judge_llm) for c in claims]
supported = sum(1 for v in verdicts if v in ("yes", "partial"))
return supported / max(1, len(claims))
def gated_answer(answer, chunks, threshold=0.7):
score = faithfulness_score(answer, chunks)
if score < threshold:
return {"action": "refuse", "score": score,
"answer": "I don't have enough info to answer that confidently."}
return {"action": "accept", "score": score, "answer": answer}| Approach | Cost | Strength | Weakness |
|---|---|---|---|
| LLM-as-judge per claim | Extra LLM call per answer | Flexible, handles nuance | Latency and dollar cost |
| NLI model (DeBERTa, AlignScore) | Tens of ms per claim | Cheap, fast | Less nuanced on complex claims |
| Answer-level vibe check | One LLM call | Cheapest LLM-judge variant | Misses isolated hallucinations |
| No detection (trust generator) | Zero | No latency | Hallucinations reach users |
| Sampled detection (1-5% traffic) | Bounded extra cost | Catches trends, monitors drift | Misses per-user hallucinations |
| Full-coverage detection | Doubles per-answer cost | Catches every case | Expensive at scale |
Real products, models, and research that use this idea.
- RAGAS is the leading open source RAG evaluation framework; its faithfulness metric implements exactly this pattern (claim decomposition plus per-claim grounding check by a judge LLM).
- TruLens by TruEra offers online and offline hallucination detection on RAG pipelines with hooks for popular LLM judges.
- Patronus AI provides a hosted hallucination detection service (Lynx) that runs as a post-generation check on production RAG traffic.
- Anthropic Claude Haiku 4.7 and OpenAI GPT-5.5-mini are the 2026 references for small judge LLMs cheap enough to run on a meaningful fraction of production traffic.
- NLI models like microsoft/deberta-v3-large-mnli and AlignScore are the lightweight alternative to LLM judges; they run in tens of milliseconds and handle simple entailment well.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you detect that your judge model is itself unreliable?
QWalk me through how RAGAS faithfulness differs from a runtime hallucination detector.
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Trying to detect hallucinations by looking at the answer alone or by measuring answer confidence. Hallucinations are answer versus source mismatches; both inputs are required.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.