Sub topic 6
Faithfulness: is the answer supported by the context?
This chapter assumes you know how a RAG pipeline works (chunking, embedding, vector search, prompting an LLM) and can read Python. It also assumes you are comfortable with averages and with precision and recall. Earlier chapters covered retrieval metrics, which score the retriever. This chapter starts scoring the generator.
What faithfulness means
Faithfulness, also called groundedness, asks one question: is every statement in the answer supported by the retrieved context?
The context here is the exact text the generator received in its prompt. It is not the whole knowledge base, and it is not what the model learned in training. An answer is faithful if a careful reader holding only those passages could confirm each of its claims.
Faithfulness checks the answer against the context. It does not check the answer against the world. Treat the context as the only evidence allowed.
This definition has three consequences:
- A claim is supported if the context states it or clearly implies it. "The warranty lasts 24 months" supports "The warranty lasts two years."
- A claim is unsupported if the context is silent on it, even when the claim is true.
- A claim is contradicted if the context says something incompatible with it. This is the worst case, because the answer is both unsupported and misleading.
Faithfulness is not correctness
Correctness compares the answer with the truth, usually a reference answer written by a person. Faithfulness compares the answer with the retrieved context. The two scores are independent, so you can have any combination.
| Row | Faithful (supported by context) | Not faithful (unsupported by context) |
|---|---|---|
| **Correct** | Ideal. The context was good and the model used it. | Lucky or memorized. The model answered from training data, not from the context. |
| **Incorrect** | The context was wrong, outdated, or irrelevant, and the model repeated it. This is a retrieval or source-data problem. | Hallucination. The model invented something and it happened to be wrong. |
The two off-diagonal cells explain why you need both scores.
The "correct but not faithful" cell is easy to miss. Suppose a user asks for a company's refund window, and retrieval returns an unrelated shipping policy. The model answers "30 days" from habit, and 30 days happens to be right. A correctness check passes. But the system is not working: the answer did not come from your documents. When the policy changes to 14 days, the model will still say 30. Low faithfulness here warns you about a failure that has not shown up yet.
The "incorrect but faithful" cell tells you the generator did its job. It faithfully summarized bad input. Fixing the prompt will not help. You need better retrieval or cleaner source documents.
Why faithfulness matters in RAG
The reason to use RAG is to make the model answer from your documents. Those documents may be private, recent, or authoritative, and the model could not know them otherwise. If the generator drifts away from the context, you lose these benefits. Users also cannot tell which sentences came from the documents and which came from the model's guesses.
An unfaithful answer is usually fluent and confident. Reading a few samples will not catch it reliably, so you need a measurement.
Measuring faithfulness: the working model
The standard approach has three steps:
- Decompose. Split the answer into short, self-contained claims. "The warranty lasts 24 months and covers defects" becomes two claims.
- Verify. For each claim, decide whether the retrieved context supports it. A verifier does this, such as a natural language inference (NLI) model or an LLM judge.
- Aggregate. Faithfulness is the fraction of claims that are supported.
If an answer has 4 claims and 3 are supported, its faithfulness is 0.75. The next chapters cover claim extraction and judges in detail. Here is the aggregation step with the verifier passed in as a function, so you can swap in a real one later.
def faithfulness_score(claims, context, is_supported):
"""Fraction of claims in an answer that the context supports.
claims: list of short, self-contained statements extracted from the answer.
context: the retrieved passages given to the generator, as one string.
is_supported: function (claim, context) -> bool, for example an NLI model
or an LLM judge prompted to answer only from the given context.
"""
if not claims:
return None # nothing to verify; do not report this as 1.0
supported = sum(1 for c in claims if is_supported(c, context))
return supported / len(claims)
# Toy judge for illustration only: exact substring match.
def toy_judge(claim, context):
return claim.lower() in context.lower()
context = "The warranty lasts 24 months. It covers manufacturing defects."
claims = ["the warranty lasts 24 months", "it covers water damage"]
print(faithfulness_score(claims, context, toy_judge)) # 0.5The second claim, "it covers water damage," is not in the context, so the score is 0.5. The toy judge only matches exact substrings. It would mark "The warranty lasts two years" as unsupported, because it cannot paraphrase. A real verifier must handle paraphrase, so the toy is useful only for seeing the shape of the computation.
Note the None return for an answer with no claims. An empty list of claims does not mean "perfectly faithful." It usually means the answer was a refusal, or the claim extractor failed. Reporting 1.0 would inflate your average. Keep None and decide separately how to treat these cases.
The context must be the real context
A common error is to check the answer against the wrong text. Faithfulness must use exactly what the generator saw, in the same form. Check these points:
- Use the post-truncation context. If your prompt builder cuts passages to fit a token limit, the model never saw the cut text. A claim supported only by the cut text counts as unsupported, and that is correct, because the model had no access to it.
- Include everything the prompt included. If the prompt also contains conversation history or a system message with facts, decide whether those count as allowed evidence. Be explicit and consistent.
- Do not evaluate against gold passages. If you score against the labeled relevant documents, you measure a different thing. You would blame the generator for retrieval misses.
Judging "supported": the edge cases
Real answers raise cases that need a written policy. Decide on each before you score, and apply the policy to every run so your numbers stay comparable.
- Inference and arithmetic. If the context lists a price of 40 and a discount of 10, is "the final price is 36" supported? Most teams accept simple, deterministic inference. Policy should say how many steps are allowed.
- Common knowledge. "Paris is in France" might not appear in the context. Strict faithfulness marks it unsupported. A lenient policy ignores claims that need no evidence. Strict is safer for high-stakes domains.
- Hedges and refusals. "The documents do not say" is faithful when the context really lacks the answer. A good generator should say this instead of guessing. Do not penalize it.
- Partial support. A claim like "the warranty covers all defects" when the context says "manufacturing defects" is stronger than the evidence. Mark it unsupported, or add a label for "partially supported."
- Contradiction. Track contradicted claims separately from merely unsupported ones. They are more harmful and may need a different fix.
Common errors
- Using correctness as a stand-in. A high correctness score does not prove the answer came from your documents. Measure both.
- Averaging claims across answers. Computing supported claims divided by all claims pools every answer together, so long answers dominate. Compute one score per answer, then average the per-answer scores. This also gives you per-question values for confidence intervals later.
- Rewarding short answers. An answer with one safe claim scores 1.0 and may say nothing useful. Faithfulness does not measure usefulness. Pair it with answer relevance, covered in the next chapter.
- Treating a low score as a generator failure. If retrieval returned irrelevant passages, a model that refuses can be faithful while a model that guesses is not. Look at the retrieved context before assigning blame.
- Trusting an unvalidated judge. A verifier that says "supported" too easily gives high scores that mean nothing. Compare it with human labels before relying on it.
Where faithfulness fits
Faithfulness scores the generator given its input. A low score points toward generation problems: the prompt does not tell the model to stay inside the context, the model prefers its own knowledge, or the context is so long that the model loses track of it. It does not tell you whether retrieval was good. Combining it with the retrieval metrics lets you separate the two failure sources, which is the subject of a later chapter on diagnosis.
Exercise
A RAG system answers "What is the refund window?" with "30 days." The retrieved context is a paragraph about shipping times that never mentions refunds. The reference answer is "30 days." Is the answer correct? Is it faithful? What does this tell you about the system?
Show answer
The answer is correct, because it matches the reference. It is not faithful, because nothing in the retrieved context supports the claim. The model answered from training data or a guess that happened to be right. This shows a retrieval failure (the refund policy was not retrieved) hidden by a lucky generator. A correctness-only check would pass, but the system would give the wrong answer as soon as the policy changed.
Exercise
An answer is split into 5 claims. The verifier marks 4 as supported. A second answer to a different question yields 0 claims because the model refused. Report the faithfulness of each answer, and explain how you would include them in a dataset average.
Show answer
The first answer scores 4/5 = 0.8. The second scores None, not 1.0, because there was nothing to verify. When averaging, exclude the None values from the faithfulness mean, and report the number of refusals separately. Check each refusal against the context: a refusal is appropriate when the context lacks the answer and is a retrieval or answer-relevance problem when the context contained it.