DeepEval Explained: Testing LLM and RAG Apps With Metrics in CI
DeepEval explained: the open-source framework for unit-testing LLM and RAG apps with metrics like faithfulness and answer relevancy, wired into CI with pytest.
By Galactic News Editorial · Published 2026-11-26T10:39:38+00:00 · Updated 2026-11-26T10:39:38+00:00
DeepEval is an open-source framework for testing LLM applications. It works like pytest, but for language model outputs. You write test cases. You pick metrics. You set a pass threshold. DeepEval runs the checks and reports which ones pass. This guide explains how DeepEval works, which metrics matter for RAG apps, and how to wire it into CI.
What DeepEval is
DeepEval is a Python framework for evaluating large language model systems. It is open source under the Apache 2.0 licence. It is built for RAG pipelines, chatbots, agents and fine-tuned models. It works with LangChain, LlamaIndex and plain OpenAI calls. The core idea is simple. Treat LLM behaviour as something you can unit test. A prompt change is a code change. It should pass tests before it ships.
DeepEval runs metrics locally on your machine. The metrics use an LLM as a judge, statistical methods, or small NLP models. You choose the judge model. Any LLM can power the evaluation. The results can also sync to Confident AI, the cloud platform built by the same team. That gives you a dashboard, dataset management and regression tracking across runs.
How a DeepEval test works
A test has three parts. A test case, a metric and a threshold. The test case holds the input, the actual output, the expected output and the retrieval context. The metric scores the output. The threshold decides pass or fail. A score at or above the threshold passes.
Install it with pip:
pip install -U deepeval
A first test looks like this:
import pytest
from deepeval import assert_test
from deepeval.metrics import GEval
from deepeval.test_case import LLMTestCase, LLMTestCaseParams
def test_chatbot_answer():
metric = GEval(
name="Correctness",
criteria="Check if the output is correct and complete.",
evaluation_params=[
LLMTestCaseParams.ACTUAL_OUTPUT,
LLMTestCaseParams.EXPECTED_OUTPUT,
],
threshold=0.5,
)
test_case = LLMTestCase(
input="How do I reset my password?",
actual_output="Go to Settings, then Security, then Reset Password.",
expected_output="Go to Settings, then Security, then Reset Password.",
)
assert_test(test_case, [metric])
Run it with the DeepEval CLI:
deepeval test run test_chatbot.py
Set your judge model's API key as an environment variable first. For OpenAI models, that is OPENAI_API_KEY. Check the docs for your installed version before copying code. The API has changed across releases. Older versions use assert_test and LLMTestCaseParams. Newer versions use assert and SingleTurnParams. The concepts are the same. The names moved.
DeepEval LLM evaluation metrics for RAG apps
RAG apps fail in two places. Retrieval brings back the wrong chunks. Generation invents facts the chunks do not support. DeepEval has a metric for each failure.
| Metric | Question it answers | Needs |
|---|---|---|
| Answer Relevancy | Does the output answer the input? | Input and actual output |
| Faithfulness | Does the output only state facts from the retrieved context? | Actual output and retrieval context |
| Contextual Recall | Does the retrieved context contain enough to produce the expected answer? | Retrieval context and expected output |
| Contextual Precision | Are the relevant chunks ranked above the irrelevant ones? | Retrieval context and expected output |
| Contextual Relevancy | Is the retrieved context relevant to the input? | Input and retrieval context |
| Hallucination | Does the output contradict the given context? | Actual output and context |
| RAGAS | Overall RAG score | Average of answer relevancy, faithfulness, contextual precision and recall |
| G-Eval | Does the output meet any custom rubric? | Your criteria, written in plain language |
Start with three metrics for a RAG app. Faithfulness catches invented facts. Answer Relevancy catches off-topic answers. Contextual Recall catches missing retrieval. Add Contextual Precision when ranking matters. Use G-Eval for anything the built-ins do not cover. It is an LLM-as-a-judge metric with chain-of-thought reasoning. You write the criteria. The judge scores against them.
Beyond RAG, DeepEval covers agents and chatbots. Task Completion checks whether an agent reached its goal. Tool Correctness checks whether it called the right tools with the right arguments. Conversational metrics cover knowledge retention, completeness and role adherence across turns. Safety metrics cover bias and toxicity. A red-teaming module tests 40-plus vulnerabilities, including prompt injection and SQL injection.
DeepEval LLM evaluation tutorial: testing in CI in 6 steps
- Build a golden dataset. Collect 20 to 50 real questions with expected answers and the chunks that should support them. Real user questions beat invented ones.
- Write one test file per feature. Keep LLM tests beside your unit tests. Use pytest fixtures to load the dataset.
- Pick metrics and thresholds. Start with faithfulness at 0.7 and answer relevancy at 0.7. Tune after the first runs. A threshold nobody can pass is as useless as one everybody passes.
- Run locally first. Use
deepeval test runto see the scores. Fix the worst failures by hand before automating. - Add a CI job. Run the test file in your pipeline on every pull request. Fail the build when a metric drops below threshold. Keep the run small and fast so it does not block the team.
- Track scores over time. Log results to Confident AI or store them as pipeline artefacts. A prompt change that drops faithfulness by 0.1 should be visible, not silent.
DeepEval integrates with any CI environment. It runs as a normal pytest suite. You can also evaluate a whole dataset in bulk with the evaluate() function. Synthetic datasets can be generated from your documents when real questions are scarce. Treat synthetic data as a starting point. Replace it with real traffic as soon as you can.
Common pitfalls
Testing with the same model that generates. A judge that shares the generator's blind spots will pass bad output. Use a strong judge model. Consider a different model family from the one you are testing.
Thresholds set by guesswork. Run the metrics on known-good and known-bad outputs first. Set thresholds between the two groups. Otherwise the numbers mean nothing.
Too few test cases. Five cases cannot catch a regression. Fifty cases can. Start small, but grow the set with every real failure you find in production.
Ignoring retrieval metrics. Teams test the final answer and forget the retrieval step. If Contextual Recall is low, no prompt fix will help. The retriever needs work.
Version drift. DeepEval's API has changed across major versions. Pin the version in your requirements file. Read the docs for that version when code breaks.
DeepEval vs manual review
Manual review is still the gold standard for a single answer. Nobody should ship a RAG app on automated scores alone. DeepEval's value is different. It watches every change, every time, without getting tired. A human reviews the new failure. DeepEval finds it. Use both. Let the framework guard the pipeline. Let people judge the hard cases.
The bottom line
DeepEval brings unit-test discipline to LLM apps. Pick the metrics that match your failure modes. Faithfulness, answer relevancy and contextual recall cover most RAG apps. G-Eval covers the rest. Set thresholds from real data. Run the tests in CI on every change. Track the scores. The goal is not a perfect score. It is knowing, the moment a change makes things worse.