Happy Dussehra! May good always win. Merry Christmas! Warm wishes from Vizag. Happy New Year! Here’s to a great year ahead.

DevOps · CNCF daily

DeepEval: Unit Tests and Quality Gates for Language Model Answers

NON CNCF, listed in the CNCF Landscape. A pytest-style Python framework that scores LLM and RAG outputs with metrics such as faithfulness and answer relevancy, so a bad prompt or model change fails CI before it reaches users.

14 min read

NON CNCF

  • DeepEval
  • Python
  • pytest
  • LLM-as-a-judge
  • CI
CNCF Landscape page

You change a prompt, swap the model, or update the retrieval index. Did the copilot get better or worse? Without a test, the honest answer is “it looked fine when I tried three questions”. Normal unit tests do not help, because the output is free text and two correct answers rarely match character by character. DeepEval fills that gap. It lets you write tests that look like pytest, but instead of assert a == b they score an answer on things like “does it stay faithful to the retrieved documents” or “is it relevant to the question”, using a judge model, and they pass or fail against a threshold. The CNCF Landscape lists it under AI Agent › Evaluation, with a second placement under Training › Evaluation, described as “The LLM Evaluation Framework”. It is a NON CNCF tool, built by the Confident AI team.

CNCF daily · Sprint 6, post 17 of 26 · AI Agent (Evaluation) · NON CNCF

At a glance

Category AI Agent › Evaluation; also Training › Evaluation (Landscape second path)
CNCF status NON CNCF, listed in the CNCF Landscape
Maintained by Confident AI; repository github.com/confident-ai/deepeval
Licence Apache 2.0, per a third-party guide; confirm on the repository
Language Python; a mirror of the package page gave Python 3.9 or newer, so check the current requirement
Versions seen PyPI pages for 3.9.5 and 4.1.5; the test-case API differs between them (see Troubleshooting)
Core idea LLMTestCase plus metrics, run with deepeval test run or evaluate()
Metrics G-Eval, DAG, RAG metrics, agent metrics, conversation metrics, hallucination, bias, toxicity and more
Judge A model you choose; the older docs set OpenAI’s gpt-4o as the default, and a custom model can be used instead
Cloud Optional Confident AI platform for shared reports; local use needs no account

The problem DeepEval solves

Question Hand-checking answers DeepEval
Did the last change make answers worse? Try a few questions and hope Run the same set every time, compare scores
What does “good” mean? A feeling A named metric with a threshold
Free-text answers No exact match possible A judge model scores meaning, with a reason
RAG quality Mixed up with model quality Separate metrics for retrieval and for generation
CI No gate A failing test fails the pipeline
Agents Hard to observe Metrics for task completion and tool use

Key concepts

Term Meaning
LLMTestCase One case: input, actual output, and optionally expected output and retrieved context
Golden A reviewed example (question, expected answer) that you keep in a dataset
Metric A scorer with a threshold; the test passes if the score is at or above it
G-Eval A custom metric you define in plain language (“is the account code correct?”)
Faithfulness Does the answer agree with the retrieved context
Answer relevancy Is the answer relevant to the question
Contextual precision, recall, relevancy How good the retrieval step is
Hallucination Does the output contradict the given context
LLM-as-a-judge A model scores another model’s output; it is useful, and also imperfect
assert_test and evaluate One test in pytest style, or a batch over a dataset

Architecture

DeepEval architecture: a set of reviewed golden questions with expected answers is loaded by DeepEval, which creates test cases and sends the questions to the ERP copilot under test. The model version under test is served from MatrixHub. A judge model grades the answers against the chosen metrics. Scores and reasons are produced per metric and per case, and a CI quality gate compares them with thresholds to pass or block the release.

Blue is inputs and the gate, grey is the app and the judge and teal is DeepEval and its results. Open the zoomable diagram, or download it as SVG or PNG.

Component Responsibility
Golden questions Reviewed questions with expected answers, kept in version control.
DeepEval Builds test cases, runs the metrics and collects the scores.
ERP copilot The system under test, called as a black box (an end-to-end test) or traced inside (component tests).
Judge model Scores each answer; it should be at least as capable as the model under test.
MatrixHub Serves the exact model version being tested. See the MatrixHub brief.
Scores and reasons A number and a written reason per metric, per case.
CI quality gate Compares scores with thresholds and blocks the release on failure.

From a golden question to a release gate

DeepEval flow in five steps: a golden question with an expected answer and context is sent to the copilot; the actual output is collected; DeepEval builds a test case from input, output and retrieved text; a judge model scores it on metrics such as faithfulness, answer relevancy or a custom criterion; each score is compared with a threshold to pass or fail with a reason; and the CI pipeline blocks the release if any test fails.

  1. Ask. A golden question goes to the copilot.
  2. Output. The answer, and the text it retrieved, are collected.
  3. Score. DeepEval builds a test case and the judge scores it.
  4. Result. Each score is compared with its threshold, with a reason.
  5. Report. CI blocks the release if any test fails.

Open the zoomable flow diagram, or download it as SVG or PNG.

Real world: the prompt change that made answers worse

Someone shortens the copilot’s system prompt to save tokens. Three manual questions look fine. A week later the finance team reports that the copilot now invents approval limits that are not in the policy documents. With DeepEval in CI, the pull request would have run 80 golden questions. The faithfulness metric would have dropped on the policy questions, the build would have failed, and the failing test would have shown a reason such as “the answer states a limit of 50,000 that does not appear in the context”. The prompt change would have been fixed or rejected before merging.

Install DeepEval

These steps follow the DeepEval README and PyPI page. I did not run them for this post.

python3 -m venv .venv && source .venv/bin/activate
pip install -U deepeval
export OPENAI_API_KEY="..."        # for the default judge; see below for other judges
# optional: deepeval login          # sends results to the Confident AI cloud platform

You can run tests without logging in. Logging in shares test reports with the cloud platform, so do not do that with confidential test data unless you have decided to.

For a judge that is not OpenAI, the README says you can evaluate using your own custom model; the docs describe a base class for wrapping a model, and a locally hosted model works that way. Check the model documentation for the version you install.

In CI, install it like any Python dependency and pin the version, then run deepeval test run:

# GitHub Actions example (illustrative)
- run: pip install -r requirements-eval.txt     # includes deepeval==<pinned version>
- run: deepeval test run tests/eval/ -n 4
  env:
    OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

Try it

This follows the README quickstart, with a custom G-Eval metric. Names changed between major versions; the 3.x pages import LLMTestCaseParams, and the 4.x page imports SingleTurnParams, so use the one that matches your version.

# tests/eval/test_copilot.py
from deepeval import assert_test
from deepeval.metrics import GEval, FaithfulnessMetric
from deepeval.test_case import LLMTestCase, SingleTurnParams   # 3.x: LLMTestCaseParams

def ask_copilot(question):
    ...  # call your service; return (answer, retrieved_chunks)

def test_approval_limit():
    answer, chunks = ask_copilot("What is the approval limit for a purchase manager?")
    case = LLMTestCase(
        input="What is the approval limit for a purchase manager?",
        actual_output=answer,
        expected_output="Purchase managers can approve up to the limit in the policy.",
        retrieval_context=chunks,
    )
    correct = GEval(
        name="Correctness",
        criteria="Is the actual output consistent with the expected output?",
        evaluation_params=[SingleTurnParams.ACTUAL_OUTPUT, SingleTurnParams.EXPECTED_OUTPUT],
        threshold=0.7,
    )
    faithful = FaithfulnessMetric(threshold=0.8)
    assert_test(case, [correct, faithful])
deepeval test run tests/eval/test_copilot.py
deepeval test run tests/eval/ -n 4        # parallel

The GEval argument names are from the PyPI quickstart for 3.9.x and 4.1.x; the expected text above is only an example. In a notebook, evaluate(test_cases, metrics) does the same without pytest.

Production reference design

  1. Golden set in Git. Keep 50 to 200 reviewed questions with expected answers, grouped by area (policy, accounts, purchasing), and review additions like code.
  2. Separate retrieval from generation. Use contextual precision and recall for the retriever, and faithfulness and relevancy for the generator, so you know which part broke.
  3. Pin the judge. A new judge model changes the scores; pin its name and version, and record them with each run.
  4. Use a strong, independent judge. A judge that is weaker than, or the same as, the model under test can miss mistakes; keep human review for a sample.
  5. Set thresholds from data. Run the current system, look at the score distribution, then set thresholds that catch real drops without flaking.
  6. Run in CI. A small fast set on every pull request, and a full set nightly and before release.
  7. Test the model version, not “latest”. Pull the model under test from MatrixHub by version.
  8. Track scores over time. Store results so you can see drift, either in the Confident AI platform or in your own database.
  9. Add real failures. When a user reports a bad answer, add it to the golden set.
  10. Watch judge cost. Every metric is at least one judge call; count tokens per run.

Security

  • Test data is real data. Golden questions often contain real policy text or real customer examples; use anonymised or synthetic data where possible.
  • Cloud reporting. Logging in sends results to a hosted platform; decide deliberately whether that is allowed for your data.
  • Judge model access. Sending answers and context to an external judge sends your content to that provider; use a self-hosted judge for confidential material.
  • Secrets in CI. Keep API keys in the CI secret store, and limit who can edit the workflow.
  • Prompt injection into the judge. An answer can contain text that tries to influence the judge; treat the score as a signal, not proof.
  • Red teaming. The project lists red-teaming for dozens of vulnerability types; use it on a non-production copy of the app.

Troubleshooting

This table comes from the DeepEval documentation, package pages and general experience with LLM-as-a-judge. I did not run DeepEval for this post, so test each entry in your own pipeline.

Symptom Likely cause How to check Fix
ImportError for LLMTestCaseParams or SingleTurnParams The API changed between major versions pip show deepeval; compare with the PyPI page for that version Use the import that matches your installed version, and pin it
Error about a missing API key The default judge needs an OpenAI key Environment variables Set the key, or configure another judge model
Scores differ between runs Judge model randomness Run the same case several times Lower temperature, use a stronger judge, average several cases
Test passes but the answer is wrong Metric does not check that aspect Read the metric reason Add a G-Eval for the missing criterion, or an expected-output check
Everything fails after a judge change A different judge scores differently Compare old and new scores Re-baseline thresholds when you change the judge
Run is slow or expensive Many metrics times many cases Count judge calls Run a small set on pull requests, the full set nightly, use -n parallel runs
deepeval login prompts in CI Login is interactive CI log Skip login in CI, or set the platform key as a secret
Faithfulness is low for correct answers Retrieval context missed the needed text Print the retrieved chunks Fix retrieval first, then re-test
Context is empty retrieval_context not passed Inspect the test case Pass the retrieved chunks from your app
Tests not found File or function names deepeval test run -h; pytest naming rules Name files test_*.py and functions test_*

Usage cases

  • RAG regression tests. Faithfulness, relevancy and retrieval metrics on every change.
  • Prompt and model comparison. Score two versions on the same golden set before switching.
  • Agent checks. Task completion and tool-correctness metrics for tool-using agents.
  • Safety checks. Bias, toxicity and red-team style tests before a release.
  • In the Sprint 6 project. The ERP copilot’s golden set runs in CI, using a self-hosted judge model, and gates changes to prompts, retrieval and the fine-tuned model from the previous post.

Operational considerations

  • Scores are signals. A judge model can be wrong or biased; sample failures and passes by hand.
  • The golden set is the asset. Maintain it like a test suite: owners, reviews, and removal of stale cases.
  • Cost and speed. Budget judge calls, and keep the pull-request set small.
  • Version drift. The library has had breaking changes across major versions; pin it, read release notes and re-run the baseline after an upgrade.
  • Cloud vs local. The cloud platform is optional; decide your policy once and enforce it.
  • Not CNCF. It is a vendor-led open source project; follow its releases and any licence or feature changes.

Adoption

The project’s pages describe integrations with LlamaIndex, LangChain, Hugging Face and others, and the Qdrant documentation has a DeepEval page. Confident AI lists well-known companies as users on its website; I did not verify those, so none are named here.

Alternatives

Solution Model Best suited to
Ragas Open source metrics focused on RAG Teams that only need RAG metrics
TruLens Evaluation with tracing, built around a “RAG triad” Teams that want evaluation tied to traces
Promptfoo Config-driven prompt tests and red teaming, also in the Landscape Teams that prefer YAML test files and quick comparisons
Langfuse evaluations Evaluation inside an observability platform; covered later in this series Teams that want traces, datasets and evals in one place
LangSmith Hosted tracing and evaluation from LangChain Teams already on LangChain
Plain pytest with exact checks Deterministic asserts Structured outputs where exact match or schema checks are enough

Strengths and limitations

Strengths Limitations
Familiar pytest workflow and CI fit Scores depend on a judge model that can be wrong
Many ready-made metrics, plus custom G-Eval Each metric costs judge calls, so cost and time grow
Separate RAG, agent and conversation metrics API changed between major versions
Works with any judge you choose The default judge is a hosted model unless you change it
Local use needs no account Cloud features are tied to the vendor platform
Apache 2.0 licence (per a third-party guide) You still have to build and maintain the golden set

Recommendation

Adopt as a CI quality gate for any LLM feature. Start with 50 reviewed golden questions for the copilot, use faithfulness and one custom G-Eval metric, and run them on every pull request that touches a prompt, the retriever or the model. Use a judge that is independent of the model under test and, for confidential data, host it yourself. Set thresholds from a baseline run, re-baseline when the judge changes, and sample judge decisions by hand. If your outputs are structured and fully checkable, plain pytest assertions on the schema may be enough, and the Instructor validators from the earlier post already cover part of that.

References: DeepEval repository · DeepEval README · DeepEval on PyPI · DeepEval 4.1.5 package page · DeepEval 3.9.5 package page · DeepEval documentation · LlamaIndex: evaluating RAG with DeepEval · Qdrant: DeepEval integration · CNCF Landscape entry

Spotted something wrong or out of date?Suggest a correction. I review every suggestion before changing the page.

EmailRSS