By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
You could build all of this yourself — claim extraction, rubric prompting, score aggregation. DeepEval packages the common metrics so you can start in minutes and read the source when you want to know exactly what a score means. It plugs into pytest, which means your AI tests live next to your normal tests.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install deepeval pytest
# Point the judge at your provider (example: OpenAI)
export OPENAI_API_KEY=sk-... # Windows: setx OPENAI_API_KEY sk-...Everything in DeepEval revolves around one object with five fields. Learn them once:
from deepeval.test_case import LLMTestCase
case = LLMTestCase(
input="Can I return a sale item?",
actual_output="Sale items can be returned within 14 days for store credit.",
expected_output="Sale items may be returned within 14 days for store credit.",
retrieval_context=[
"Sale items may be returned within 14 days of delivery for store credit."
],
context=[
"Sale items may be returned within 14 days of delivery for store credit."
],
)| Field | What goes in it | Needed by |
|---|---|---|
| input | The user's question | Relevancy metrics |
| actual_output | What your system answered | Every metric |
| expected_output | The known-good answer (if you have one) | Completeness, similarity |
| retrieval_context | The chunks your retriever returned | Faithfulness, context precision/recall |
| context | The full set of documents that were available | Grounding checks |
# test_nova.py
import pytest
from deepeval import assert_test
from deepeval.metrics import FaithfulnessMetric, AnswerRelevancyMetric
from deepeval.test_case import LLMTestCase
def test_returns_answer_is_grounded():
case = LLMTestCase(
input="Can I return a sale item?",
actual_output="Sale items can be returned within 14 days for store credit.",
retrieval_context=[
"Sale items may be returned within 14 days of delivery for store credit."
],
)
faithfulness = FaithfulnessMetric(threshold=0.85)
relevancy = AnswerRelevancyMetric(threshold=0.80)
assert_test(case, [faithfulness, relevancy])
# pytest test_nova.py -v -> one ordinary pytest resultThat is genuinely it. What you get on failure is a score, the reason the judge gave, and the claim it could not support — which is exactly the failure message you wanted back in Module 3's first lesson.
One test is a demo. A suite is a loop over data:
import json, pytest
from deepeval import assert_test
from deepeval.metrics import FaithfulnessMetric
from deepeval.test_case import LLMTestCase
CASES = json.load(open("datasets/golden_nova.json"))
@pytest.mark.parametrize("case", CASES, ids=[c["id"] for c in CASES])
def test_faithfulness(case):
metric = FaithfulnessMetric(threshold=0.85, verbose_mode=False)
assert_test(
LLMTestCase(
input=case["question"],
actual_output=case["actual"], # captured from a real run
retrieval_context=case["retrieved"],
),
[metric],
)Key takeaways
DeepEval wraps the judge machinery and plugs into pytest.
The LLMTestCase has five fields: input, actual_output, expected_output, retrieval_context, context.
Start with faithfulness, answer relevancy and your own rule checks.
Capture real outputs to JSON, then judge the file — reproducible and cheaper.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.