💥 Introducing JevEval: Jev-as-a-Judge for LLM evaluation. Read the post →
RAG

Faithfulness

LLM-as-a-judge
Jev-as-a-judge
Single-turn
Referenceless
RAG
Multimodal

The faithfulness metric uses LLM-as-a-judge to measure the quality of your RAG pipeline's generator by evaluating whether the actual_output factually aligns with the contents of your retrieval_context. deepeval's faithfulness metric is a self-explaining LLM-Eval, meaning it outputs a reason for its metric score.

Required Arguments

To use the FaithfulnessMetric, you'll have to provide the following arguments when creating an LLMTestCase:

  • input
  • actual_output
  • retrieval_context

Read the How Is It Calculated section below to learn how test case parameters are used for metric calculation.

Usage

First, set the eval mode:

deepeval set-eval-mode llm         # LLM-as-a-judge (default)
deepeval set-eval-mode hybrid      # LLM extracts, Jev decides
deepeval set-eval-mode system_one  # Jev-as-a-judge, no LLM

The FaithfulnessMetric() can be used for end-to-end evaluation of text-based and multimodal test cases:

from deepeval.metrics import FaithfulnessMetric
from deepeval.test_case import LLMTestCase
from deepeval import evaluate

# Replace this with the actual output from your LLM application
actual_output = "We offer a 30-day full refund at no extra cost."

# Replace this with the actual retrieved context from your RAG pipeline
retrieval_context = ["All customers are eligible for a 30 day full refund at no extra cost."]

metric = FaithfulnessMetric(
    threshold=0.7,
    model="gpt-4.1",
    include_reason=True
)
test_case = LLMTestCase(
    input="What if these shoes don't fit?",
    actual_output=actual_output,
    retrieval_context=retrieval_context
)

# To run metric as a standalone
# metric.measure(test_case)
# print(metric.score, metric.reason)

evaluate(test_cases=[test_case], metrics=[metric])
from deepeval.test_case import LLMTestCase, MLLMImage
from deepeval.metrics import FaithfulnessMetric
from deepeval import evaluate

# Replace this with the actual retrieved context from your RAG pipeline
retrieval_context = [
    f"The Eiffel Tower {MLLMImage(...)} is a wrought-iron lattice tower built in the late 19th century.",
    f"...",
]

metric = FaithfulnessMetric(
    threshold=0.7,
    model="gpt-4.1",
    include_reason=True
)
test_case = LLMTestCase(
    input=f"Tell me about this landmark in France: {MLLMImage(...)}",
    actual_output=f"This appears to be Eiffel Tower, which is a famous landmark in France"
    retrieval_context=retrieval_context
)

# To run metric as a standalone
# metric.measure(test_case)
# print(metric.score, metric.reason)

evaluate(test_cases=[test_case], metrics=[metric])

There are TWELVE optional parameters when creating a FaithfulnessMetric:

  • [Optional] threshold: a number representing the minimum passing threshold. Can also be set to None to run the metric in score-only mode. Defaulted to 0.5.
  • [Optional] model: a string specifying which of OpenAI's GPT models to use, OR any custom LLM model of type DeepEvalBaseLLM. Defaulted to gpt-5.4.
  • [Optional] include_reason: a boolean which when set to True, will include a reason for its evaluation score. Defaulted to True.
  • [Optional] strict_mode: a boolean which when set to True, enforces a binary metric score: 1 for perfection, 0 otherwise. It also overrides the current threshold and sets it to 1. Defaulted to False.
  • [Optional] async_mode: a boolean which when set to True, enables concurrent execution within the measure() method. Defaulted to True.

  • [Optional] verbose_mode: a boolean which when set to True, prints the intermediate steps used to calculate said metric to the console, as outlined in the How Is It Calculated section. Defaulted to False.
  • [Optional] truths_extraction_limit: a number which when set, determines the maximum number of factual truths to extract from the retrieval_context. The truths extracted will be used to determine the degree of factual alignment, and will be ordered by importance, decided by your evaluation model. Defaulted to None.
  • [Optional] penalize_ambiguous_claims: a boolean which when set to True, will not count claims that are ambiguous as faithful. Defaulted to False.
  • [Optional] evaluation_template: of type FaithfulnessTemplate, which allows you to override the default prompts used to compute the FaithfulnessMetric score. Defaulted to deepeval's default prompts.
  • [Optional] flaky: a boolean which when set to True, marks the metric as flaky. Defaulted to False.
  • [Optional] system_one_model: the Jev model to use, as a string or a DeepEvalBaseSystemOneModel. Only used under hybrid or system_one eval_mode. Defaulted to jev-latest.
  • [Optional] eval_mode: llm, hybrid or system_one, choosing whether an LLM, Jev, or both judge. Defaulted to the configured eval mode (llm unless set).

Within components

You can also run the FaithfulnessMetric within nested components for component-level evaluation.

from deepeval.dataset import EvaluationDataset, Golden
from deepeval.tracing import observe, update_current_span
...

@observe(metrics=[metric])
def inner_component():
    # Set test case at runtime
    test_case = LLMTestCase(input="...", actual_output="...")
    update_current_span(test_case=test_case)
    return

@observe
def llm_app(input: str):
    # Component can be anything from an LLM call, retrieval, agent, tool use, etc.
    inner_component()
    return

dataset = EvaluationDataset(goldens=[Golden(input="Hi!")])
for golden in dataset.evals_iterator():
    llm_app(golden.input)

As a standalone

You can also run the FaithfulnessMetric on a single test case as a standalone, one-off execution.

...

metric.measure(test_case)
print(metric.score, metric.reason)

How Is It Calculated?

You can change how the FaithfulnessMetric is calculated by setting the eval mode.

LLM-as-a-judge

The FaithfulnessMetric score is calculated according to the following equation:

Faithfulness=Number of Truthful ClaimsTotal Number of Claims\text{Faithfulness} = \frac{\text{Number of Truthful Claims}}{\text{Total Number of Claims}}

The FaithfulnessMetric first uses an LLM to extract all claims made in the actual_output, before using the same LLM to classify whether each claim is truthful based on the facts presented in the retrieval_context.

A claim is considered truthful if it does not contradict any facts presented in the retrieval_context.

Hybrid

Under the hybrid eval mode, the classification step is answered by Jev, a System One model, instead: one yes/no question per claim, with P(yes) > 0.65 counted as truthful, < 0.35 as contradictory, and anything in between as borderline. The extraction, the equation and the reason are unchanged. If a Jev call fails, the LLM makes that decision instead.

Jev-as-a-judge

Under the system_one eval mode, Jev judges the whole metric in one request. It is sent the raw actual_output and retrieval_context and asked three questions:

QuestionTypeWeight
Every factual claim in actual_output is supported by the facts in retrieval_context.Noul2
No claim in actual_output contradicts the facts in retrieval_context.Noul1
How much of actual_output is grounded in the facts in retrieval_context? (Fabricated → Fully grounded)Score1

Each answer becomes a value in [0,1][0, 1] and the score is their weighted mean. No LLM is called: the reason lists each answer with its probability, and metric.confidence reports how decisive Jev was.

Customize Your Template

Since deepeval's FaithfulnessMetric is evaluated by LLM-as-a-judge, you can likely improve your metric accuracy by overriding deepeval's default prompt templates. This is especially helpful if:

  • You're using a custom evaluation LLM, especially for smaller models that have weaker instruction following capabilities.
  • You want to customize the examples used in the default FaithfulnessTemplate to better align with your expectations.

Here's a quick example of how you can override the process of extracting claims in the FaithfulnessMetric algorithm:

from deepeval.metrics.faithfulness import FaithfulnessTemplate
from deepeval.metrics import FaithfulnessMetric

# Define custom template
class CustomTemplate(FaithfulnessTemplate):
    @staticmethod
    def generate_claims(actual_output: str):
        return f"""Based on the given text, please extract a comprehensive list of facts that can inferred from the provided text.

Example:
Example Text:
"CNN claims that the sun is 3 times smaller than earth."

Example JSON:
{{
    "claims": []
}}
===== END OF EXAMPLE ======

Text:
{actual_output}

JSON:
"""

# Inject custom template to metric
metric = FaithfulnessMetric(evaluation_template=CustomTemplate)
metric.measure(...)

FAQs

Is a low faithfulness score a retrieval or a generation problem?
Generation. It grades actual_output against the already-retrieved retrieval_context, so a low score means unsupported claims (a prompt or model issue). Retrieval quality is covered by Contextual Recall and Contextual Precision.
How is Faithfulness different from the Hallucination metric?
Faithfulness checks the actual_output against the retrieved retrieval_context ("is this grounded in what I retrieved?"), while HallucinationMetric compares it against a ground-truth context. Use faithfulness for RAG, hallucination when you have known-correct reference context.
My answer relevancy is high but faithfulness is low — what's going on?
The classic confidently-wrong case: an on-topic answer (high answer relevancy) backed by claims your retrieval_context doesn't support. The model is leaning on parametric knowledge instead of retrieved evidence — tighten your prompt to force grounding.
Why is a claim I know is true being marked unfaithful?
Faithfulness only rewards claims supported by the retrieval_context — a real-world truth absent from the retrieved text still counts as unfaithful. Use truths_extraction_limit to focus on key truths and penalize_ambiguous_claims to control borderline scoring.

On this page