Assure your AI deployment - across enterprise and real world
We assure that your AI works as intended. Safely and securely.
Evaluating LLM Relevancy with DeepEval [Testμ 2026]
Monika Sharma of Salesforce on DeepEval as pytest for LLMs, the RAG and safety metric taxonomy, choosing thresholds, and where eval tests fit in the pyramid.
A support chatbot answers a question with text, images, emoticons and a row of stars for feedback. A person reading it can see it worked. The evaluation framework scoring it can only read the text, so it disagrees.
In this session from Testμ Conf 2026, Monika Sharma, Software Engineer at Salesforce, works through evaluating LLM output with DeepEval.
If you couldn’t catch all the sessions live, you can access the recordings at your convenience by visiting the TestMu AI YouTube Channel.
TL;DR
DeepEval is an open-source Python framework that evaluates LLM output with a judge model rather than a string comparison, scoring semantically between zero and one against a threshold you set and returning a written reason with every score. It exists because the same input produces different text on every run.
- Can a string assertion test LLM output? - No. LLM responses are non-deterministic, so the same input produces different text on different runs and an equality check fails a correct answer.
- Is DeepEval free? - Yes. DeepEval is open source under the Apache 2.0 license, so the cost of a run is the judge model's API calls, which Monika Sharma kept low by staying inside a free key's per-minute and per-day request limits.
- Which RAG metrics does DeepEval provide? - DeepEval provides five RAG metrics. Faithfulness checks that the output is grounded in retrieved context, answer relevancy that it addresses the query, contextual relevancy that the retrieved context fits the query, contextual precision that the context is free of noise, and contextual recall that it covers everything needed.
- What threshold should a DeepEval metric start with? - Start at 0.5, which is also DeepEval's default threshold, while establishing response quality, then raise it as the agent proves stable. Monika Sharma's demo used 0.8, because a correct answer is still worded differently on each run.
- Why would a DeepEval test show none instead of a score? - A score of none means an output format mismatch rather than a failure. The agent returned something DeepEval could not parse the way it parsed the other tests, often because the response was too large or carried extra fields.
- Are DeepEval tests unit tests or integration tests? - Both, depending on the layer. Calling the agent directly through an API makes a DeepEval test a unit test, while checking a chatbot through the UI involves two components and makes it an integration test.
- Can DeepEval judge a chatbot reply with images and star ratings? - No. In Monika Sharma's example, DeepEval could not properly recognise the images, emoticons and star ratings in a chatbot reply, so human judgment won, and she treats output with several component types beyond text as a poor fit.
- Is one passing DeepEval test enough for production autonomy? - No. Monika Sharma's teams ran around 40 different utterances against the same agent, and the deciding factor was how many runs the results stayed stable for.
- Does a DeepEval score show what an agent changed? - No. DeepEval's judge scores the output and the tool calls recorded in the test case. TestMu AI's Agent Assurance grades agents that act against the evidence of a run: files changed on disk, records checked with read-only queries, and the tool calls made.
Sounds Right, Is Right
Ask a model a question and you get an answer that is fluent, confident and well written. Sounding right and being right are separate properties, and the session calls relevancy the most deceptive failure mode because an off-target answer reads as polished as a correct one.
The host set the brief as measuring the gap between correct and useful, and spotting hallucination dressed up as helpfulness, with a check that runs in a pipeline.
The Assertion Problem
Traditional testing rests on deterministic assertions. You call a method, or hit an API, or read a value from the UI, and you assert equality against a string or a JSON structure.
LLMs break that model. The same input produces different output between runs, so a string match fails a response that was perfectly correct.
If equality cannot be the check, something has to judge meaning instead. Another Testμ session, on techniques for testing LLM responses, answers the same problem with a funnel of progressively finer checks.
Pytest for LLMs
DeepEval is an open-source evaluation framework she describes as pytest for LLMs. It is a Python library you import into an existing repository, with Python as the only real prerequisite.
Instead of comparing strings, JSON or images, it hands the output to a judge model that scores it semantically, using techniques such as G-Eval. Everything lands on a scale from zero to one against a threshold you configure.
The flow she described runs in four stages, whether the application under test is a RAG pipeline, an agent or a chatbot.
- Output capture - responses become test case objects holding the input and the output.
- Metrics engine - those objects flow into the engine, which calls a judge model to score them.
- Scores with reasons - the engine returns a number, a written reason, and a pass or fail verdict.
- Reports - results are presented like any other automation report, showing what passed and failed per metric.
The Metrics Taxonomy
The metrics are organised into five categories, and she spent most time on the first because it carries the most weight when judging an agent’s response.
- RAG evaluation - faithfulness, answer relevancy, contextual relevancy, contextual precision and contextual recall, assessing the retriever and generator components.
- Agent evaluation - task completion and tool correctness, including the arguments passed, validating whether the agent finished what it was asked to do.
- Safety and compliance - toxicity, bias, PII leakage, misuse and role violation.
- Custom - your own measures, built with G-Eval.
- Conversational - for multi-turn exchanges rather than single responses.
Her framing of the RAG metrics as questions is the useful part, because each one asks something different of the same answer.
- Faithfulness - is the output grounded in the retrieved context?
- Answer relevancy - does the output address the user’s query?
- Contextual relevancy - is the retrieved context relevant to the query?
- Contextual precision - is the retrieved context focused, without noise or out-of-scope material?
- Contextual recall - does the context cover all the necessary information?
For a tracing-first library that scores the RAG triad, see the TruLens tutorial.
Setting Up the Project
The demo starts from an empty folder. She initialises the project with uv, which she compares to running an init command for a Node project, then adds DeepEval alongside pandas, numpy and pytest.
The judge model needs credentials. She installs Google’s generative AI package and points DeepEval at a Google AI Studio key, noting that the provider is interchangeable and the requirement is not.
Whichever model you judge with, you need an API key for it, and that key is what the cost and the speed of every run depend on.
The rest is ordinary Python hygiene: a project metadata file, a pinned Python version, then a virtual environment created, activated, and dependencies installed from the requirements file.
Note: The demo scores single answers, and a customer-facing agent also has to hold up across a whole conversation. TestMu AI's Agent Testing plays each scenario out as a full multi-turn conversation with your chat or voice agent, scores it on 9 quality dimensions including hallucination and context awareness, and returns failing transcripts annotated with the turn that caused the failure. To try it on your own agent, start free.
Writing the First Test
Her subject is an order sub-agent responsible for checking a customer’s order, tested from a Python file in a test folder.
The imports are pytest plus DeepEval’s test case type and whichever metrics you intend to use, and she picks answer relevancy. The test itself is three moves: construct a test case with an input and an expected output, evaluate it against the metric, and assert on the resulting score.
Alongside relevancy she showed the wider set available by name, covering correctness, completeness, consistency, accuracy, precision, recall and F1 score.
Her threshold in the demo is 0.8, and her reasoning is the same non-determinism that broke assertions in the first place. The agent will answer correctly using different words and terminology each time, so the bar has to allow for that.
A minimal version of that test for DeepEval 4.3.4 looks like this, with a Gemini judge as in the demo. Here answer() is the order sub-agent’s entry point, and the second case feeds in a reply padded with promotions to show what a failing score looks like.
import os
from deepeval import assert_test
from deepeval.metrics import AnswerRelevancyMetric
from deepeval.models import GeminiModel
from deepeval.test_case import LLMTestCase
from order_agent import answer
judge = GeminiModel(model="gemini-3.8-flash", api_key=os.environ["GOOGLE_API_KEY"])
def test_order_status_answer_is_relevant():
question = "Where is my order 1042?"
test_case = LLMTestCase(
input=question,
actual_output=answer(question),
expected_output="Order 1042 has shipped with UPS and should arrive on Friday.",
)
assert_test(test_case, [AnswerRelevancyMetric(threshold=0.8, model=judge)])
def test_padded_reply_loses_relevancy():
test_case = LLMTestCase(
input="Where is my order 1042?",
actual_output=(
"Thanks for shopping with us! Our winter sale ends Sunday, with 20% off "
"all jackets. Order 1042 has shipped with UPS. You can also join our "
"loyalty program for free shipping."
),
)
assert_test(test_case, [AnswerRelevancyMetric(threshold=0.8, model=judge)])Running it is a single command against the test file. Cases execute in parallel, and how long that takes depends on the model and on the billing tier behind your key, with free keys being noticeably slow.
deepeval test run test_order_agent.pyMonika Sharma walking through how to actually write tests for LLM subagents LLMTestCase, AnswerRelevancyMetric, threshold-based assertions is exactly the practical depth this space needs.
— TestMu AI (@testmuai) August 19, 2026
Great session so far! pic.twitter.com/nVHaGqaW1s
Reading the Results
The output is sectioned per metric, with a score, the threshold it was measured against, and a written reason. Her passing example scored 1.0 against a 0.7 threshold on answer relevancy, because the output addressed the prompt without including irrelevant statements.
Correctness gave its own reason on the same run: the output accurately stated that Tokyo is the capital of Japan, matched the expected output, and contained no contradictions or missing details. Faithfulness reported alignment with the retrieval context and no contradictions.
The two-case file from the previous section prints the same kind of table, condensed here to the score, status and reason.
Test case Metric Score Status
test_order_status_answer_is_relevant Answer Relevancy 1.0 PASSED
reason: The score is 1.00 because the response directly addresses the inquiry
about order 1042 without any irrelevant statements. Great job providing a
focused and accurate answer!
test_padded_reply_loses_relevancy Answer Relevancy 0.2 FAILED
reason: The score is 0.20 because the output is heavily diluted with irrelevant
marketing promotions, sales discounts, and loyalty program details instead of
answering where order 1042 is located, only retaining minimal relevancy
through a polite interaction.
Pass Rate: 50.0% | Passed: 1 | Failed: 1The score is a ratio. DeepEval’s answer relevancy documentation defines it as the number of relevant statements divided by the total: the judge first extracts every statement in the actual output, then classifies each one against the input. The same page sets the default threshold at 0.5 and notes that a high relevancy score does not mean the answer is factually correct, so it pairs the metric with faithfulness.
The padded reply splits into five statements, and only "Order 1042 has shipped with UPS." answers the question, so it scores 0.2 against the 0.8 bar. The live answer changes from run to run; a typical one, "Your order 1042 has shipped with UPS. It is scheduled to arrive this Friday.", splits into two relevant statements and scores 1.0. The reason is generated by the judge as well, so its wording shifts between runs even when the score holds.
She had deliberately broken some tests, and the interesting failure is not a low score. Some rows show none where a number should be.
A score of none means the agent’s output was not in the format DeepEval had parsed for the other tests. It is a format mismatch rather than a quality failure, often because the response was too large to interpret or carried extra fields, and it is fixed by correcting the output rather than by tuning a threshold.
G-Eval and Custom Metrics
The built-in metrics cover the standard RAG measures. G-Eval is the mechanism inside DeepEval for defining your own, in the same shape as relevancy but measuring whatever your application actually cares about.
Safety and compliance testing runs the same way as part of an end-to-end execution, covering toxicity, bias, PII leakage, misuse and non-advice violation.
She also named the alternatives. Ragas and Promptfoo are the two she is aware of, while her own teams have used DeepEval for most of their sub-agent testing. The Ragas metrics guide sorts the scoring classes of that library by category, from RAG to agents and tool calls.
For teams leaving OpenAI's hosted evals, the guide to OpenAI Evals covers rebuilding them in promptfoo.
Wiring It Into CI/CD
Her position on pipelines is that nothing special is required. Eval tests are added and their results uploaded exactly like the UI and API tests already running, on GitHub Actions, GitLab CI, Jenkins, CircleCI, Azure Pipelines, Buildkite or an in-house system.
That is the argument for treating eval as a quality gate rather than an experiment someone runs locally before a demo. Eval-driven development moves that gate to the start of the work: the eval is written before the change and must fail on the current system first.
Evals in the Test Pyramid
The question she gets most often is where eval tests belong in the pyramid, and her answer refuses to pick a single layer.
If the goal is only to see the agent’s response, and developers have given you an API or a direct call to reach it, the eval sits comfortably as a unit test.
If the goal is end to end, meaning how the agent is integrated into the UI or how the chatbot responds in place, it becomes an integration test because two components are involved.
Which layer you put them in is a decision about what you are trying to learn, and she is explicit that they can live at more than one.
Checking What an LLM Sub-Agent Changed With Agent Assurance
DeepEval scores what the order sub-agent returns: a judge model reads the test case and rates the reply, and even the tool correctness metric scores only the tool calls recorded in that test case. Once a sub-agent like it can change or cancel an order through a real API, the state of the order afterwards is what counts, so the test has to check the effect. TestMu AI's Agent Assurance is built for agents that act: it reads your codebase to work out what the agent does, invokes it for real, and grades each criterion against observed evidence.
- Evidence the judge never sees - Criteria are graded on files changed on disk, artifacts produced, and tool calls checked against the agent's declared tool surface, not the agent's own account.
- No provider key on your machine - The setup above needs a key for the judge model; Agent Assurance runs its models in the TestMu AI controller, so no model provider keys sit on your machine.
- A named gap instead of none - In DeepEval a score of none means a format mismatch; here Unable to Verify marks a criterion the run could not check, kept out of the pass rate and reported beside it as the assurance gap.
- Gate on the report - In headless CI, rook report --json gives the verdict totals a gate reads, each scenario’s verdict.yaml holds the per-criterion verdicts and evidence, and a finished run exits 2 when a scenario failed, never for Unable to Verify, so gate on the report, not the exit code alone.
In the terminal, Agent Assurance runs as rook, and Claude Code can drive it from the repository your DeepEval tests live in. Install the skill, type /rook in a Claude Code session there and describe the check; Claude Code's own approvals still apply to anything it proposes.
npx @testmuai/rook-skill@latest install --agent claude-codeFor an order sub-agent that can act on what it checks, a bounded first request could be:
/rook Test the order sub-agent in this repository, which can look up, change and cancel customer orders. Use the staging profile, propose up to three scenarios where a change or cancellation must not go through, and show me the possible writes before invoking the target.The skill is not the CLI, so install rook as well; the Claude Code setup guide covers both steps.
Q & A Session
- Where has DeepEval disagreed with your human judgment, and who won?
Monika Sharma: Human judgment won. Her example is a website chatbot asked how a product works, which replied with text, images, emoticons and a row of stars inviting feedback. A person can see that response worked. DeepEval could not properly recognise the components that were not text, and her conclusion is that where an answer involves several component types beyond text, it may not be a good fit.
- What does running these evals at scale cost, since the metrics call an LLM?
Monika Sharma: It comes down to billing, and her own rounds ran on a free API key without much cost. Free keys cap requests per minute and per day, so staying inside those limits keeps it cheap and exceeding them does not. Scheduling four or five runs a day across a suite covering many sub-agents rather than one is where it starts to demand attention.
- How can human review scale without recreating the bottleneck evaluation frameworks are meant to remove?
Monika Sharma: The same way it does for any automation. Ten scenarios you can check with your own eyes; a hundred, or a regression suite, you cannot, and nobody is present for every push and pull request. That is the argument for a safety net that catches changes automatically, which is what DeepEval exists to be, and she was clear it is one library among several worth exploring rather than the only option.
- For an agent that plans, uses tools and recovers from failures, should evaluation focus on each decision or on the final outcome?
Monika Sharma: Not the final outcome alone. Her unit is the utterance, meaning what a user actually sends to an agent, and one utterance against one sub-agent proves very little. Separate sub-agents handle onboarding, billing and orders, and each needs many utterances covering multiple languages, unusual symbols and the local language a site is hosted in. The steps in between are where the evaluation has to reach.
- Should agents be allowed to modify the knowledge base they use for future decisions?
Monika Sharma: A flat no, on security grounds. In her experience organisations constrain knowledge base updates as a matter of policy, and an agent is given read access to use with retrieval rather than permission to write.
- How do you decide the right threshold for each metric?
Monika Sharma: There is no single number. She starts at 0.5 while establishing what the agent’s response quality actually is, then raises the bar as the agents prove stable, stop hallucinating much, and are running on current models with the context they need. How high the bar goes depends on model stability.
- How easy is it to adjust the safety and compliance parameters?
Monika Sharma: Straightforward, and like every other metric they hinge on the threshold. For anything beyond the built-in set she recommends G-Eval, which she finds considerably easier to customise than the packaged metrics.
- How should enterprises establish a minimum evidence threshold before giving an agent production autonomy?
Monika Sharma: By volume and by stability rather than by a single passing test. On past projects they tested with roughly 40 different utterances hitting the same agent, checking relevancy, precision and completeness across all of them, and with several agents in play that breadth matters more again.
This session was part of Testμ Conf 2026, which ran across three days of sessions on agentic engineering and quality. Registrations for the next edition are already open on the Testμ Conference 2027 page.
Testing an AI agent? TestMu AI's Agent Testing validates chat, voice and IVR agents before your customers talk to them.
Was this helpful?
Author

TestMu AI
Author · 291 posts
TestMu AI is World's First Full Stack AI Agentic Quality Engineering platform that empowers teams to test intelligently, smarter, and ship faster. Built for scale, it offers a full-stack testing cloud with 50,000+ real devices and 3,000+ browsers. With AI-native test management, MCP servers, and agent-based automation, TestMu AI supports Selenium, Appium, Playwright, and all major frameworks. AI Agents like HyperExecute and KaneAI bring the power of AI and cloud into your software testing workflow, enabling seamless automation testing with 120+ integrations. TestMu AI Agents accelerate your testing throughout the entire SDLC, from test planning and authoring to automation, infrastructure, execution, RCA, and reporting.
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance
- Advanced access controls
- Advanced data retention rules
- Advanced Local Testing
- Premium Support options
- Early access to beta features
- Private Slack Channel
- Unlimited Manual Accessibility DevTools Tests



