White Test Lab

LLM Testing: How to Evaluate RAG Systems and AI Agents

Published December 2, 2026 · Reviewed by Vladimir Sokurenko, CEO & CTO, White Test Lab

LLM Testing: How to Evaluate RAG Systems and AI Agents

Most QA teams will know what a failed test looks like (red build, assertion didn't hold, stack trace, etc.). An LLM product is very unlikely to fail in that way. The answer can be perfectly fluent and well-formed and yet be completely wrong, and every one of the normal checks will still pass, as the request itself has succeeded.

Two types of products make this issue worse. RAG systems are answering from the company's own documents, so correctness is a function of both what was retrieved and the model. AI agents go one step further: they can call tools, change records, and take multi-step actions. A perfectly plausible final answer can be the result of a completely wrong tool having been called, a dangerous intermediate step having been taken, or simply a massive number of calls to tools having been made.

The risk is quantifiable. The OWASP GenAI Top 10 for LLM Applications 2026 (published 4 August 2026) had prompt injection in first place and promoted excessive agency from 6th to 3rd. Gartner forecasts that over 40% of agentic AI projects will be shelved by the end of 2027 due to cost overruns, lack of clear business value or insufficient risk controls.

This article looks at what LLM testing is, the differences between evaluating RAG systems and agents and traditional QA, which metrics to use at each layer, how an evaluation run works, what tools are available, and where teams typically go wrong.

What Is LLM Testing?

LLM testing is the practice of determining whether an application built on a large language model produces correct, grounded, safe, and consistent results. It's not just testing the model itself; it's testing the model, the prompts, the data the model is given, and, for agents, the actions it takes. The unit under test is no longer a function with one right answer. It's a probabilistic system whose outputs vary. The question is no longer "did it return X?" but rather "how often is it right and how badly does it go wrong when it is wrong?"

Think of a classic unit test as a vending machine test: press B4, and you expect a certain snack. Testing a RAG system or an agent is more akin to assessing a new member of staff at a helpdesk. You don't just test one pre-defined phrase. You're testing whether they found the right policy, whether they told the customer what the policy actually says, and whether they did the right thing in the system afterwards.

Two terms are very easy to confuse. LLM testing (the subject of this article) is about testing products that contain an LLM (e.g., a chatbot, a document assistant, or a support agent). Agentic testing is the other way around: it's about using AI agents to test normal software. ISTQB has split them too, with CT-GenAI being the use of generative AI in testing and CT-AI being the testing of AI systems. They frequently come together in practice, as an agent that's testing an AI product will still need its own results to be validated.

Image 1Title: "Two systems, two ways to fail." Diagram: a RAG pipeline (query, retriever, context, generator, answer) and an agent loop

Why Evaluating RAG Systems and Agents Is Getting Attention

  • A demo is not a test. A handful of carefully selected questions tells you nothing about how the system will perform on the real thing. You can't possibly tell whether a new prompt, a new model version, or a new chunking approach has made things better or worse without a fixed set of test cases.
  • Failures are quiet. A hallucinated answer won't throw an exception. It'll just look right, which is precisely why it gets to the user. Output that looks correct is the most unreliable signal that an LLM system is actually producing.
  • RAG has two places it can go wrong. The retriever can fail to retrieve the right document, or the generator can fail to use the document it has retrieved and simply make something up. A single 'is the answer good?' score won't tell you which of those two things to fix.
  • Agents act, not just answer. The OWASP Top 10 for LLM Applications 2026 saw the most substantial move of any item in the list, with excessive agency moving from #6 to #3. That's the extent of the agency being granted to LLM applications.
  • Consistency is a separate issue. The τ-bench authors came up with the pass^k metric, which is the probability that an agent will succeed on all k repeated runs of the same task. It was explicitly designed to measure reliability and consistency, something that a single-run success rate will not do.
  • Governance is way behind. In the World Quality Report 2025-26, data privacy risk (67%) and concerns around hallucinations and reliability (60%) were the two biggest impediments to scaling Gen AI in quality engineering. Evaluation is the mechanism by which a team turns those concerns into something it can actually measure.

Image 2

Three Layers of LLM Evaluation

The most useful habit is to assess each layer in isolation. If you're only scoring the final answer, then you're going to end up with a bad answer coming from the retriever, the prompt, the model, or a tool call, and you're just going to have to guess.

Evaluating retrieval

What it is: scoring the passages that the retriever hands to the model prior to any answer being produced.

When to use it? In every RAG system, and most importantly when the answers are incomplete or incorrect.

Trade-off. You need labelled relevant documents or reference answers, and good retrieval scores don't necessarily lead to good answers.

Retrieval determines what the model sees. Two questions are key: has the retriever found the information it needs to answer (context recall)? And has it ranked the relevant passages above the irrelevant ones (context precision)? The classic ranking metrics of MRR and nDCG still apply in the case of labeled relevant documents.

Evaluating generation

What it is: scoring what the model does given the context it's provided, typically with a second model acting as the judge.

When to use it? On every RAG release and on every prompt or model change as it scales to large regression runs.

Trade-off. Judge scores are inherently systematically skewed estimates, so they need to be adjusted against human labels.

Generation is about what the model does with the context. Faithfulness is about whether every claim in the answer is actually supported by the retrieved text. Answer relevancy is about whether the answer in fact answers the question. Text overlap evaluation measures such as BLEU and ROUGE are not really appropriate in this case, as two answers can have very little in common and still say the same thing or have a lot in common and still contradict each other.

Faithfulness is generally calculated as the number of claims that are actually supported by the retrieved context divided by the total number of claims in the answer. Every claim that is not supported by the context will reduce the faithfulness score and will therefore be a marker of where a potential hallucination may be.

Image 3

Evaluating agents

What it is: scoring the full trace of a task (the end state, the tool calls, the number of steps, and the safety behavior).

When to use it? For any agent that calls tools, modifies records, or acts on behalf of the user.

Trade-off. It needs an environment that can be reset and checked, is more expensive per run, and gives results that vary from run to run.

An agent produces a sequence of decisions, and the final sentence in that sequence is the least informative. The unit of evaluation is the trace (what the agent observed, which tools it invoked with what arguments, what came back, and what state the system was left in). Five checks cover pretty much all of the things that go wrong.

  • Task completion. Compare the end state of the environment with the expected state (e.g., the final state of the database) rather than rely on the agent's final message. An agent that says "your order has been cancelled" after invoking a refund tool has produced a perfectly good sentence and a very bad outcome.
  • Tool call accuracy. Score tool selection (did it pick the correct tool?) and argument construction (did it pass the correct inputs?) separately, as they have different root causes and require different fixes.
  • Step efficiency. Set a step budget per task. An agent can get to the right answer via many, many more calls than the task actually required, and that doesn't show up in the final text at all.
  • Safety and permissions. Test for refusals (test refusals), prompt injection via retrieved documents or tool output, and attempts to act outside the permitted scope. This is the point at which the OWASP 'excessive agency' risk becomes a very tangible test case.
  • Consistency. Run each important task several times and report pass^k, the proportion of tasks where all k runs succeed. NVIDIA's guidance on agent evaluation is to that effect: a success rate without a consistency metric is just a point estimate on a stochastic system.

Image 4. Anatomy of an agent trace: what to score at each step

When an agent uses retrieval as one of its tools, the two approaches come together. You keep the RAG metrics on the retrieval step and then add in trace-level metrics around it. The retrieval score tells you whether the tool worked, and the trace score tells you whether the agent actually used it correctly.

The same discipline applies in reverse. In our earlier piece on agentic testing, we looked at how an AI agent could be used to run tests on standard software and why you'd need a fixed check outside of the agent and a human to approve the changes. An agent that tests your product and an agent inside your product are two very different problems, but both boil down to the same principle: you never let the system assess its own work.

How an LLM Evaluation Run Works

The process is the same for a RAG assistant as it is for an agent. The only difference is in the checks.

  1. Define what 'good' means. Work with the product owner to establish the quality criteria: what answers are acceptable, what actions are off-limits, and what a failure would cost. A rubric such as 'must cite the policy page and must not promise a refund outside of the window' is testable. 'Should be helpful' is not.
  2. Build a golden dataset. Pull real questions/tasks from logs, tickets, and support chats and add in the reference answers or expected end states. Include the hard cases (ambiguous questions, questions the docs can't answer, out-of-date docs, and people trying to game the system). The dataset should grow as we have production incidents.
  3. Instrument the system. Capture the query, the retrieved chunks, the prompt, the answer, and for agents, every tool call with its arguments and results. Without traces, you can't diagnose a failed case.
  4. Score each layer. Run the retrieval metrics on the retrieved context, the generation metrics on the answer, and the trace metrics on the agent's steps. Use code assertions wherever possible (e.g., where you can check the answer exactly against an order ID, a total, or a status).
  5. Repeat and compare. Run each case several times, record the model/prompt/index versions, and compare against the previous baseline. A change that improves one metric and degrades another is a finding.
  6. Review the failures with a person. Have a look at a sample of both passes and failures. Work out which of the failures are genuine defects, which are just poor test cases, and which are judge errors. Then feed the confirmed failures back into the dataset.
  7. Gate releases and keep watching. Run the suite in CI on every prompt/model/index change, set thresholds on the metrics that actually matter, and score a sample of production traffic to pick up any drift.

Image 5 How an LLM evaluation run works

Where Automated Evaluation Works Best, and Where Other Checks Are Better

Good fits for judge-scored evaluation

  • Open-ended answers (summaries, explanations, support replies) have no single correct answer, so a mark scheme-based approach is the only viable option.
  • Grounding checks. Checking that each claim is actually grounded in the retrieved text is something that's very slow to do by hand and is absolutely the sort of thing that lends itself to automation.
  • Regression after any change. A new prompt, model, or index can be compared against the previous baseline in minutes.
  • Triage at volume. A judge can flag the weakest conversations for a person to read.
  • Sampling production traffic. Scoring a slice of live conversations will show you the drift that a fixed test set simply cannot.

Code assertions are the better choice

  • Money, access rights, and data. Totals, permissions, and stored records must match every time, so check them against the system of record.
  • Structured output. The schema, field types, and required values are trivial to verify exactly.
  • Audit-style checks. Regulated flows need a clear pass-or-fail record that does not depend on a model's opinion.

People should decide

  • High-stakes answers. Medical, legal, and financial answers all require human sign-off.
  • Ambiguous policy and attitude. Whether an answer is acceptable to the brand or to the policy owner is a business judgment.
  • Judge calibration. Someone has to provide the sample that the judge is being measured against.

Image 6 Who checks what: code, judge model, or person

LLM-as-a-Judge: Where Automated Scoring Works and Where It Does Not

The vast majority of RAG metrics are computed by a second LLM, which takes the question, the context, and the answer as input and returns a score. This is the LLM-as-a-judge approach, and it's what makes large-scale evaluation runs so affordable. In the MT-Bench study that first used it, a GPT-4 judge was in agreement with human preferences over 80% of the time, pretty much the same as two human raters would be.

The same research documented systematic distortions, and any team relying on judge scores should plan for them:

  • Position bias. In side-by-side comparisons, the judge favors an answer because of where it appears. Run each comparison twice, swapping the order, and average the results across both orders.
  • Verbosity bias. Longer answers get the points regardless of quality.
  • Self-preference. A judge will tend to give its own output a better rating.
  • Poor reasoning on the hard cases. A judge can easily miss a subtle numerical or logical error. Make exact assertions for anything that can be verified in code.

The rule of thumb is to calibrate the judge first. Get some people to label a sample of cases, compare the judge's output to their labels, and track the agreement over time. Judges are very good at high-volume regression checks and initial triage. The final call on the sensitive flows (medical, legal, financial) will still need a human.

Tools for LLM Evaluation

The tool market changes quickly, so check each option against its current documentation. This list is a selection, not a ranking, and several online comparison guides are written by vendors who include their own products.

  • Ragas. An open-source library for RAG. Scores faithfulness, answer relevance, context exactness, and context recall with a judge model and includes a test set generator.
  • DeepEval. An open-source, pytest-style framework. Your evaluations are written as unit tests and run in CI, with metrics for RAG, tool use, and safety. It's the sort of thing that would fit with a team that already has a Python test suite in place.
  • Arize Phoenix. Open-source tracing and evaluation that you can self-host. Ideal for teams who want to run it in their own environment.
  • LangSmith. Tracing, datasets, and evaluators from the LangChain team. Ideal for teams who are primarily building with LangChain and LangGraph.
  • Langfuse and Braintrust. Evaluation platforms that bring together traces, datasets, experiments, evaluators, and human review in a single system. Definitely worth a look if you've got multiple people who need a shared view of the results.
  • τ-bench and BFCL (both public benchmarks for tool-using agents). τ-bench compares the end state of a simulated customer service conversation with the desired goal state. BFCL looks at individual function calls. NVIDIA's recommendation is that for enterprise use you'd be far better off with domain-specific evaluations built from real tickets and real APIs.
  • Pytest, Playwright, and Postman. The standard QA tooling is still being used to check the app around the model (the UI, the API contracts, and the exact values that the agent writes to your systems).

A fairly typical setup is to have a lightweight framework for CI gating (DeepEval or Ragas would be the usual examples) paired with a platform for human annotation, regression tracking, and dashboards.

Best Practices for Testing RAG Systems and AI Agents

  • Score retrieval and generation separately. A single quality score hides the cause. Split the pipeline so that every unsuccessful case points to one layer.
  • Build the dataset from real traffic. Questions written by developers are tidier than questions written by users. Sample logs, tickets, and chat transcripts, and remove personal data before they enter the test set.
  • Check exact facts with code. Verify totals, IDs, dates, and statuses with assertions or by querying the system of record. Keep the LLM judge for qualities that code cannot measure.
  • Calibrate the judge against people. Manually label a sample, measure agreement, and recheck after changing the judge model or prompt.
  • Repeat runs and report spread. Run important cases several times and report the pass rate with its range, plus pass^k for agent tasks. A single green run on a stochastic system proves little.
  • Record a version of everything. Record the model, prompt, retriever settings, index build, and tool versions with each run. A model update can affect the results even if your code hasn't changed at all.
  • Test the data as well as the model. Add cases with outdated documents, conflicting sources, and questions that the knowledge base cannot answer. The correct behavior in the last case is to say so.
  • Give agents the least access they need. Run evaluations against test accounts and resettable data, never against production, and include prompt-injection cases hidden in documents and tool output.
  • Gate in CI and watch production. Fail the build when key metrics drop below the agreed threshold, and score a sample of live conversations to catch drift between releases.

A short pilot is the safest way to start. Pick one assistant or one agent workflow, write down its current failure rate, review time, and known incidents, and build a first golden dataset. Run the evaluation in shadow mode so that it reports results without blocking any release, then compare what it finds with what your current process finds.

You can also plant a few known defects (e.g., an old policy document, a question the knowledge base can't answer) to check that the evaluation picks them up. Once you've done that, you can then decide whether to go further, tweak it, or call it a day.

Risks and Limits of LLM Evaluation

  • Judge errors are very much a thing. The judge model can misread a long context and will often reward a confident (but wrong) answer. Treat its scores as just that, as estimates. Always do a spot check and only state anything as fact if you can verify it.
  • A dataset that's too small or too clean. A small dataset of very easy questions will give you a high score and a false sense of comfort. Add in the hard, ambiguous, adversarial examples and keep adding them after each incident.
  • Over-adapting to the test set. If you're tuning the prompts until the golden set passes, then the score stops being a predictor of real behavior. You need to hold back a chunk of cases that the team has never tuned against.
  • Good retrieval scores, bad answers. The standard ranking metrics measure relevance to the query rather than usefulness to the generator. You need to look at the final answers as well as the retrieval numbers.
  • Silent changes upstream. A new model version, a re-indexed knowledge base, or an edited prompt can change things overnight. Version everything and re-run the suite after every change.
  • Data privacy. Test sets derived from real conversations will contain personal data. Anonymize them, restrict access, and ensure you know where the judge model is processing the text.
  • Cost and runtime. Judge calls, repeated runs, and multi-step agent traces all add up. Run a small suite on every commit, the full suite nightly, and the expensive consistency runs prior to releases.
  • Treating benchmarks as acceptance tests. Public benchmarks describe general capability only. They have no knowledge of your policies, your documents, or your tools.

How a QA Partner Can Help

Building an evaluation practice takes time product teams often don't have, and the people who built the assistant aren't the most neutral judges of it. An independent QA provider can help in four areas: designing the golden dataset and quality criteria with the business, setting up automated evaluation in CI, reviewing the system from the outside with adversarial and edge-case testing, and checking that the application around the model, including its APIs, permissions, and data flows, behaves correctly.

If your team is likewise experimenting with agents on the testing side, then our guide to agentic testing will cover how you can run that pilot and still have control over release quality. The two topics go hand in hand with the evaluation practices outlined in this article, which makes an agentic test setup credible.

White Test Lab team is combining this kind of review with hands-on automation in Playwright and Cypress, API testing, and AI-based product testing. It's integrated into the working QA process rather than being a separate experiment, so the results get to the people who make the release decisions.

Conclusion

RAG systems and AI agents fail in a completely different way from normal software. They fail silently; they can fail in a completely different way on a second run, and with agents, the damage can be done in a tool call that the user is completely unaware of. That's why the final answer on its own is simply not sufficient. You need separate metrics for retrieval, for generation, and for agent behavior. You need a golden dataset built from real cases, and you need a very clear rule about when a human has to step in.

For most teams, the next step is tiny: pick one assistant or one agent workflow, collect a first batch of real cases, score retrieval and answers separately, and then run the suite on every change. If you want help planning that evaluation or reviewing the first results, White Test Lab can help.

FAQ

What is LLM testing in simple terms?

LLM testing is about checking that an app built on a large language model produces correct, well-grounded, safe, and consistent results. As the output varies from run to run, the results are reported as rates and scores against a rubric rather than a simple pass/fail.

How do you assess a RAG system?

Evaluate retrieval and generation in isolation. For retrieval, look at context recall and context precision. For generation, look at faithfulness and answer relevancy. Run it on a golden dataset of real questions and reference answers, and then go through the failures manually to work out which of the two is the problem.

How do you test an AI agent?

Score the full trace, not just the final message. Look at the end state of the system, the accuracy of tool selection and arguments, the number of steps, and safety behaviors (e.g., refusals, resistance to prompt injection). Repeat each task several times and track pass^k to assess consistency.

Can an LLM be used to grade the answers of another LLM?

Yes, and most of the RAG metrics work that way. In the MT-Bench study, the GPT-4 judge was in agreement with human preferences over 80% of the time. The judges still have position, verbosity, and self-preference bias, so you need to calibrate them against the human labels and check the actual facts via code.

Is LLM testing the same as agentic testing?

  1. LLM testing checks products that contain a language model, such as chatbots, RAG assistants, and agents. Agentic testing uses AI agents to test any software. ISTQB covers them with different certifications: CT-AI for testing AI-based systems and CT-GenAI for using generative AI in testing.

Need help with QA for your product?