Detecting RAG hallucinations with a confidence score
groundedness verification design.
decompose the answer into claims, verify each against retrieved context with NLI or an LLM judge, aggregate into a faithfulness confidence score, and flag unsupported claims.
WHAT THIS TESTS The interviewer wants a concrete verification pipeline that measures whether an answer is grounded in the retrieved evidence, plus a calibrated confidence signal, rather than trusting the generator. This is core to production RAG reliability.
A GOOD ANSWER COVERS The central idea: hallucination in RAG means the answer makes claims not entailed by the retrieved context, so detection is a groundedness or faithfulness check between answer and context. Pipeline: first decompose the generated answer into atomic, individually checkable claims. For each claim, verify it against the retrieved passages using a natural language inference model, entailment versus contradiction versus neutral, or an LLM-as-judge prompted to decide whether the context supports the claim and to cite the supporting span. Classify each claim as supported, contradicted, or unsupported. Aggregate into an overall confidence score, for example the fraction of claims that are supported, optionally weighted, and treat contradicted claims as strong hallucination signals. Use the score operationally: below a threshold, abstain, return I do not know, trigger re-retrieval, or escalate to a human, and optionally highlight which sentences are ungrounded. Complementary signals include self-consistency, sampling multiple answers and checking agreement, and citation coverage, does every claim cite a retrieved chunk. Calibrate the threshold against a human-labeled set.
COMMON WRONG ANSWERS Using only the model's token-level probability or asking the model how confident it is, which correlates weakly with factual support and is easily overconfident. Checking only string overlap with documents, missing paraphrased support and contradictions. Treating retrieval relevance as proof of answer correctness.
LIKELY FOLLOW-UPS Why NLI over the model's self-confidence, independent verification. How do you handle multi-hop claims. How do you calibrate the score. What is the latency cost of per-claim checks, batch them.
ONE CONCRETE EXAMPLE An answer asserts a specific date the documents never state. Claim decomposition isolates that sentence, the NLI checker labels it unsupported against every retrieved passage, the confidence score drops below threshold, and the system flags the date and re-retrieves instead of returning the hallucination.
Read the original → aws.amazon.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.