LLM Application Testing Strategies: How to Test What a Model Actually Does

LLM Application Testing Strategies: How to Test What a Model Actually Does

LLM application testing strategies are the methods teams use to check whether a language-model application gives correct, grounded and safe answers before and after it reaches users. The central question is how to test a system whose outputs are not deterministic, and the short answer is that you test it the way you would test a human employee: with a set of representative cases, a clear scoring rubric, and regular checks on live work. A single prompt that looks good in a demo proves almost nothing.

Traditional software testing asks whether the code does what it was written to do, and the answer is pass or fail. LLM testing asks a harder question, whether the output is good enough, which needs judgement rather than a simple comparison. That difference shapes every strategy in this guide: the test set matters more than the tool, and the scoring rubric matters more than the test set.

Key takeaways

  • LLM application testing strategies combine deterministic checks, LLM-as-judge scoring, retrieval evaluation and adversarial red teaming.
  • The test set matters more than the tool: 50 to 200 real cases, including past failures, beats any framework.
  • Run cheap deterministic checks first, then LLM-as-judge metrics for things only a model can assess.
  • Evaluation belongs in CI, with a baseline and a threshold that can block a release.
  • LLM judges have measurable biases, so calibrate them against human judgement and never trust a single score.

Start with the test set, not the tool

Every testing strategy in this guide depends on a test set of real cases. Build it from your own traffic: take representative user questions, add the failures your support team has seen, add the edge cases your product team worries about, and add questions your documents cannot answer, because those are the ones that cause hallucination. Fifty to two hundred cases is a good starting size for most applications.

Each case needs an expected outcome, which is not always a single correct answer. For a factual question, the expected answer is a fact or a refusal. For a summary, it is the points that must appear. For a refusal case, it is the boundary the system must hold. Writing these expectations forces the team to agree on what good looks like, which is itself half the value of the exercise. Best for: teams that want a test set built from real traffic and real failures before choosing any tool.

Deterministic checks: the cheap first layer

Deterministic checks are tests with a pass or fail answer that needs no judgement: does the output contain a required phrase, match a JSON schema, stay within a length limit, call the right tool, or respond within a latency budget? They are fast, free and reliable, and they catch a surprising share of regressions, especially after prompt changes that accidentally break output format.

Run these checks first, on every change, in CI. They are the smoke tests of LLM development: if the output is not valid JSON, there is no point asking a judge model whether the content is good. They also give you a stable baseline, because unlike judge scores, deterministic results do not vary from run to run. For the CI pipeline these checks live in, see our guide to AI CI/CD pipelines.

LLM-as-judge: scoring what only a model can assess

LLM-as-judge means using a second model to score outputs against a rubric: is the answer correct, is it grounded in the retrieved documents, is the tone right, does it refuse when it should? This is the workhorse of LLM evaluation, because most of what matters about an answer cannot be checked with a regular expression. The judge needs a clear rubric with examples of good and bad answers, or its scores will drift.

Judges have measurable biases, and the research on this is consistent: a judge tends to favour longer answers, answers in its own style, and the answer presented first when comparing two. Design around that by calibrating the judge against human scores on a sample, by using a different model family for judging than for generation, and by treating small score changes as noise. A judge is a measuring instrument, and like any instrument it needs calibration. Best for: teams that need scored quality metrics for correctness, grounding and tone.

Testing retrieval: when the answer is wrong, find which half failed

In a retrieval-augmented application, a bad answer can come from two places: the retriever found the wrong documents, or the generator used good documents badly. Testing the two halves separately is what makes RAG problems fixable. Retrieval metrics check whether the right passages were found; generation metrics check whether the answer stayed faithful to them.

RAGAS is the most widely used open-source library for this, with metrics for faithfulness, context precision and context recall that are designed to separate retrieval failures from generation failures. Its API has changed across releases, so check the documentation for the version you install. The practical payoff is simple: when you know which half failed, you know what to fix, instead of rewriting prompts and hoping. For the hallucination failures this testing catches, see our hallucination incident response playbook.

DeepEval: pytest-native metric gates

DeepEval brings LLM evaluation into pytest, which is where Python teams already run their tests. Test cases and metrics are Python objects, evaluations run like the rest of the test suite, and a failing threshold fails the build. Its metric library covers hallucination, bias, toxicity and RAG-specific checks, with more than fourteen metrics in total, and it is released under the Apache 2.0 licence.

The value of DeepEval is not the metrics themselves but where they run: inside the existing test suite, on every pull request, with a baseline that makes regressions visible. Evaluation that lives outside CI gets skipped under deadline pressure; evaluation that blocks a merge does not. Best for: Python teams that want evaluation gates inside their existing test suite.

Promptfoo: prompt regression and red teaming

Promptfoo is a CLI-first, YAML-config-driven tool that is strongest at comparing prompts and models side by side and at adversarial red teaming. You describe prompts, providers and assertions in a config file, and it runs the matrix and reports which combinations pass. Its security-testing suite includes hundreds of built-in attack vectors, which makes it the best of the three main tools for probing how a system responds to jailbreaks, prompt injection and data extraction attempts.

OpenAI announced its acquisition of Promptfoo in March 2026, while the open-source project continues. If vendor neutrality matters to your evaluation stack, that is worth noting when you choose. For most teams, the deciding factor is simpler: Promptfoo is the fastest way to answer “did this prompt change make things better or worse?” Best for: teams comparing prompts and models, and teams that need adversarial coverage.

Close-up of hands typing on a laptop keyboard with a code editor showing test scripts on a monitor in the background
Writing the test cases is the slow part of LLM testing; running them should be automatic, on every change, before anything reaches users.

Comparing LLM testing tools

Tool Shape Licence Strength Main weakness
Promptfoo CLI, YAML config MIT Prompt comparison and red teaming Less depth on scored quality metrics
DeepEval Python, pytest-native Apache 2.0 Metric gates inside CI Judge-model token cost at scale
RAGAS Python metric library Apache 2.0 Separates retrieval from generation errors RAG only, no production monitoring
LangSmith Hosted platform Commercial Tracing plus dataset evaluation Best inside the LangChain ecosystem
Braintrust Hosted platform Commercial Comparing many variants with history Paid platform, not a library

Most production teams run two of these together: RAGAS for retrieval diagnosis plus DeepEval for CI gating is the most common pairing, with Promptfoo added when adversarial coverage is required. The tools cover different failure classes rather than competing for the same job. For the security-testing side of the same problem, see our guide to AI security testing tools.

Running evaluation in CI and production

Evaluation earns its keep when it runs automatically. In CI, run deterministic checks and a fast judge-based subset on every pull request that touches prompts, retrieval or models, and run the full suite nightly. Record a baseline score for each metric, and treat a drop below the threshold like a failing unit test: the change does not ship until the drop is explained or fixed.

In production, keep testing after release. Sample real conversations, score them with the same rubric, and feed the failures back into the test set. This closes the loop that makes testing improve over time: every real failure becomes a permanent test case, so the same mistake cannot ship twice. Production sampling also catches drift, the slow change in user behaviour that no pre-release test set can predict.

LLM application testing checklist

  • A test set of 50 to 200 real cases exists, including past failures and questions the documents cannot answer.
  • Each case has a written expected outcome, not just an input.
  • Deterministic checks run on every change in CI before any judge-based scoring.
  • The judge model is calibrated against human scores and differs from the generation model where possible.
  • Retrieval and generation are scored separately, so the failing half is identified.
  • Evaluation has a baseline and a threshold that can block a release.
  • Production conversations are sampled and scored, and failures are added to the test set.

Frequently asked questions

How many test cases do I need for an LLM application?

Start with 50 to 200 representative cases, including past failures and edge cases. That is enough to catch most regressions and to compare prompt changes meaningfully. Grow the set from production failures rather than by writing cases in the abstract.

Can I trust LLM-as-judge scores?

Yes, with calibration. Judges have known biases, such as favouring longer answers, so calibrate them against human judgement on a sample, use a clear rubric with examples, and treat small score changes as noise. Never rely on a single judge score for a release decision.

What is the difference between RAGAS and DeepEval?

RAGAS specialises in evaluating retrieval-augmented generation, with metrics that separate retrieval errors from generation errors. DeepEval is a broader pytest-native framework that runs scored metrics as CI gates. Many teams run both together.

How do I test for prompt injection?

Include adversarial cases in your test set: instructions hidden in user input, in retrieved documents and in tool outputs. Run them through a red-teaming tool such as Promptfoo, and check that the system refuses or ignores the injected instruction rather than following it.

Should evaluation run on every code change?

Run deterministic checks on every change, and run the full judge-based suite on changes to prompts, retrieval, models or data. Running the full suite on every commit is usually too slow and too costly; running it nightly plus on relevant changes is the practical balance.

Latest articles

Scroll to Top