DeepEval RAG testing means using DeepEval, an open-source LLM evaluation framework from Confident AI, to write unit tests for a retrieval-augmented generation pipeline, in the same way software teams write unit tests for ordinary code. The question it answers is the one every RAG team eventually faces: how do you know a change to a prompt, a model or a retriever made things better rather than worse? DeepEval answers it with test cases, metrics and a pass or fail verdict, so a RAG change can be checked in continuous integration exactly like any other code change.
That framing is the point. Most RAG evaluation is ad hoc: someone eyeballs a few answers after a change and declares it good. DeepEval treats LLM outputs as testable behaviour, with named metrics, thresholds and repeatable runs. If you have ever shipped a prompt tweak that quietly broke answers for a whole class of questions, that is the failure DeepEval is built to catch.
Key takeaways
- DeepEval is an open-source, Apache 2.0 licensed LLM evaluation framework, similar to Pytest but specialised for unit testing LLM outputs.
- Its RAG metrics include answer relevancy, faithfulness, contextual recall, contextual precision, contextual relevancy, hallucination and RAGAS.
- G-Eval lets you define custom criteria in plain language and have a judge model score them like a human would.
- Tests are written as Python test cases, so they run in CI with Pytest and fail a build on regression.
- DeepEval works with LangChain, LlamaIndex and custom pipelines, and results can be shared through the Confident AI platform.
What DeepEval is
DeepEval is a simple-to-use, open-source LLM evaluation framework for evaluating and testing large language model systems. It is similar to Pytest but specialised for unit testing LLM outputs, and it incorporates research-backed metrics such as G-Eval, hallucination detection, answer relevancy and RAGAS, using LLMs and other models that can run locally on your machine. It is developed by Confident AI, licensed under Apache 2.0, and listed on PyPI, where it is installed with a single pip command.
The unit-test framing shapes everything about it. A test case is an input, an expected output and the retrieved context, plus the metric and threshold that decide pass or fail. You write tests in Python, run them with Pytest, and get a report of which cases passed, which failed and by how much. That makes evaluation a normal engineering artefact: versioned, reviewable and runnable on every commit.
The RAG metrics DeepEval provides
DeepEval ships a large set of ready-to-use metrics, and the RAG set covers both retrieval and generation. Each metric is a class you instantiate with a threshold, then apply to test cases.
Faithfulness and hallucination
Faithfulness measures whether the answer is grounded in the retrieved context, and the hallucination metric is its complement, flagging outputs that contradict or go beyond the context. These are the first metrics to wire up, because an unfaithful answer is wrong in the most dangerous way: it sounds right while being unsupported. Our guide to RAG answer faithfulness explains the failure mode in depth.
Answer relevancy
Answer relevancy scores whether the generated answer actually addresses the input question. A faithful answer that dodges the question still fails a user, so this metric catches the polite, well-sourced non-answer that other checks miss.
Contextual recall, precision and relevancy
These three metrics diagnose the retriever. Contextual recall asks whether everything needed to answer was retrieved. Contextual precision asks whether the retrieved chunks were ranked with the useful ones first. Contextual relevancy asks what fraction of the retrieved context was actually relevant. Together they tell you whether a bad answer is a retrieval problem before you blame the generator, which is the same diagnostic split our guide to RAG evaluation metrics recommends.
RAGAS and G-Eval
DeepEval also implements the RAGAS metric set, so teams already using Ragas can run the same measures inside DeepEval test cases, and G-Eval, a research-backed metric that scores outputs against criteria you write in plain language. G-Eval is the most flexible tool in the box: if you need to check tone, structure, completeness or compliance with a house style, you describe the criterion and the judge model scores it.

How a DeepEval test is written
A DeepEval test starts with an LLMTestCase, which holds the input, the actual output, the expected output where relevant, and the retrieval context. You pick a metric, set a threshold, and assert the test with the framework’s assert function inside a Pytest test. Running Pytest then executes every case and reports failures like any other test suite.
The habit that makes this work is treating thresholds as decisions, not defaults. A threshold of 0.8 on faithfulness means you have decided that answers supported by less than four fifths of their claims are not shippable, and that decision should be recorded and argued about, not copied from a tutorial. Start with the framework’s suggested values, measure your baseline, then set thresholds that your current system passes and that a genuinely worse system would fail.
Best for: teams that already run CI and want RAG quality gated the same way as code quality, with failures blocking a merge rather than surfacing as user complaints.
DeepEval vs other RAG evaluation tools
| Aspect | Ragas | TruLens | DeepEval |
|---|---|---|---|
| Primary shape | Batch scoring over a dataset | Live tracing plus feedback functions | Unit tests in Pytest |
| RAG metrics | Four core metrics | RAG Triad | Wide set, plus RAGAS and G-Eval |
| Custom criteria | Limited | Feedback functions | G-Eval and DAG metrics |
| CI integration | Manual scripting | Via recorded runs | Native, it is Pytest |
| Live monitoring | No | Yes | Via Confident AI platform |
| Ground truth needed | Mostly no | No | Depends on the metric |
The three tools overlap heavily on metrics and differ on workflow. If your team lives in Pytest and CI, DeepEval is the lowest-friction choice. If you need production observability, TruLens fits better. If you want the cleanest batch scoring, Ragas is the simplest. Many teams use two of the three: DeepEval in CI and one of the others for production monitoring. Our guide to building a RAG evaluation pipeline shows how to combine them.
Running DeepEval RAG testing in CI
The natural home for DeepEval is the pull request. A change to a prompt, a chunking strategy, an embedding model or a retriever setting triggers the test suite, and a regression fails the build before it reaches users. That only works if the suite is fast and stable enough to run on every change, so keep two suites: a small, fast smoke set that runs on every commit, and a larger set that runs before releases.
Flakiness is the main enemy. LLM judges are non-deterministic, so the same test can pass on one run and fail on the next, and a flaky suite gets ignored. Reduce flakiness by pinning the judge model, using thresholds with margin rather than values your system barely passes, and re-running failures before treating them as real. A test that fails one time in ten is a signal about your threshold, not necessarily about your system.
Dataset quality matters as much as the framework. Synthetic test data generated from your documents is a good start, but it tends to reflect what the system already handles. Mix in real user questions, including the awkward ones, and refresh the set as the product changes. Our guide to RAG synthetic test data covers how to build test sets that actually catch failures.
Costs and honest limitations
DeepEval’s breadth is also its risk: with so many metrics available, teams pick too many, set thresholds they never revisit, and end up with a suite nobody trusts. Start with three or four metrics that map to real user harm, faithfulness, answer relevancy and contextual recall are a good default set, and add more only when a failure shows the gap.
Judge cost is the second limit. Every metric call is a model call, and a large suite run on every commit adds up. Use a cheap judge for routine runs, sample the larger suite, and keep the expensive judge for release gates. Finally, DeepEval scores are estimates from a judge model, so calibrate against human judgement: read failing cases by hand, check that the judge’s reasons make sense, and adjust criteria when the judge and your reviewers disagree.
Getting started checklist
- Install DeepEval and write five test cases from real user questions.
- Start with faithfulness, answer relevancy and contextual recall.
- Pin the judge model and record its version with every run.
- Measure the baseline before setting any threshold.
- Set thresholds your current system passes with margin, not barely.
- Wire the smoke suite into CI so it runs on every pull request.
- Read failing cases by hand before changing a threshold.
- Use G-Eval for custom criteria such as tone, structure or compliance.
- Refresh the test set as real user questions change.
Frequently asked questions
Is DeepEval free?
Yes. DeepEval is open source under the Apache 2.0 licence, and its metrics can run locally on your machine. Confident AI also offers a cloud platform for sharing test reports and production evaluation, which is optional.
How is DeepEval different from Pytest?
DeepEval is built on top of Pytest rather than replacing it. It adds LLM-specific test cases and metrics to the Pytest workflow, so you write tests in the same style and run them with the same tooling, but the assertions measure LLM output quality instead of code behaviour.
What is G-Eval in DeepEval?
G-Eval is a research-backed metric that lets you define evaluation criteria in plain language, such as “the answer should cite its sources”, and have a judge model score outputs against them with human-like accuracy. It is DeepEval’s tool for custom quality dimensions that no standard metric covers.
Does DeepEval work with LangChain and LlamaIndex?
Yes. DeepEval integrates with both, so you can unit test RAG applications built on either framework, as well as custom pipelines. The test case is just an input, an output and a context, so the framework does not care how those were produced.
Can DeepEval test agents as well as RAG?
Yes. Beyond RAG metrics, DeepEval provides agentic metrics for tool calling and task completion, plus conversational and multimodal metrics, so the same test harness can cover chatbots, agents and multi-turn systems.
Why do my DeepEval tests pass locally and fail in CI?
The usual causes are an unpinned judge model that changed between runs, a threshold with no margin, or different environment variables, such as a missing API key causing a fallback judge. Pin the judge, keep thresholds away from the edge, and log the judge version with every run.







