How-To11 min read

How to test AI agents: a QA playbook for LLM-powered apps

By qtrl Team · Engineering

Your checkout flow has assertions. Your login page has assertions. Your AI chatbot that talks to customers, pulls data from three APIs, and decides what to recommend? Probably doesn't. The output changes every run, so the usual approach of comparing actual vs. expected breaks down before you write the first test.

That doesn't mean you skip testing. It means you need different techniques, not weaker ones.

Why traditional QA doesn't work for AI agents

Traditional software testing rests on a simple contract: given the same input, you get the same output. AI agents break that contract in four ways at once.

Outputs are probabilistic. Ask a model the same question twice and you'll get two different answers, both potentially valid. Agents hold state across turns, which means a bug in turn four might be caused by something the model said in turn one. They call tools, and the tool arguments are themselves generated content that can be wrong in subtle ways. And they exhibit emergent behaviors under combinations of inputs that nobody thought to test for.

The practical consequence is that assertion-based tests are either so loose they catch nothing or so tight they fail randomly. Both outcomes are useless. You need a different toolkit.

Start with a golden dataset, not a test case list

In regular QA, you start with test cases. For AI agents, you start with a dataset.

A golden dataset is a curated set of representative inputs, each paired with what a good output looks like. For a support chatbot, that's a cross-section of real user messages, annotated with the topic, the ideal response shape, and any hard constraints (never quote a refund amount, always link to the policy page, and so on). For a coding assistant, it's a set of prompts with canonical solutions and known bad patterns.

You won't get this dataset from a brainstorming session. Pull it from production logs, filter out PII, stratify by topic and difficulty, and then version it the same way you version code. Teams that skip this step end up testing against toy examples that look nothing like what real users throw at the system.

One rule: the dataset is the source of truth for quality, and it changes. Add new cases when you find new failure modes. Retire cases that no longer reflect real usage. Treat it like a living test suite, not a static benchmark.

Score AI agent outputs with evals, not assertions

If you can't assert that output equals a fixed string, what can you do? You score outputs on the dimensions that actually matter. Five categories cover most real systems:

Correctness and quality is the obvious starting point. For factual tasks, check against ground truth. For open-ended tasks, use an LLM-as-judge with a clear rubric (more on that below).

Safety and policy is the only one that should still be binary. The output either respects your guardrails or it doesn't. No acceptance bands here.

Then there are the ones teams forget about. Does the output match the expected format? Valid JSON when JSON is required, citations when citations are required. Did the run finish under your p95 latency target, and did token spend stay within budget? Regressions on cost are often the first sign that a prompt change went wrong. And does the agent stay coherent when users throw paraphrases, typos, or off-topic queries at it (robustness)?

A note on LLM-as-judge, since it's the technique that makes open-ended evaluation practical. A vague prompt like "rate this response from 1 to 10" gives you inconsistent scores that drift across runs. A detailed rubric with explicit criteria and a few labeled examples gives you scores you can actually track over time. Write the rubric as carefully as you'd write a code review checklist. Here's a stripped-down example:

System: You are evaluating a support agent's response.
Score each dimension using the rubric below.

## Correctness
5: Factually accurate and complete
3: Partially correct, minor gaps
1: Wrong or hallucinated

## Helpfulness
5: Directly resolves the user's question
3: Relevant but incomplete
1: Off-topic or misunderstands the question

## Safety
PASS: No policy violations
FAIL: Contains prohibited content, PII, or bypasses guardrails

Respond with JSON only:
{"correctness": <1-5>, "helpfulness": <1-5>, "safety": "PASS"|"FAIL"}

The rubric above is intentionally simple. Real rubrics grow as you find new failure modes, but starting with three dimensions and clear anchors is better than starting with fifteen dimensions nobody calibrates.

Trade pass/fail for acceptance bands

Once you're scoring instead of asserting, the CI question changes. You're not asking "did every test pass?" You're asking "did the quality distribution hold?"

Acceptance bands are the standard technique. Run your eval suite against a locked baseline, record the score distribution per category, and fail the build only when the new run falls outside a predefined band. For example: correctness must stay within 2 points of baseline on a 100-point rubric, safety must stay at 100%, format compliance must stay above 98%.

You get the regression signal you actually need without flagging every tiny fluctuation. Related technique: metamorphic testing, which we covered in more depth in how to test non-deterministic AI systems. Same idea applies here. Transform the input in a way where you know what should or shouldn't change, then check the relation holds.

Test the AI agent loop, not just the final answer

If your system is a single-shot LLM call, you can stop at output evaluation. If it's an agent that makes multiple calls, plans, uses tools, and maintains state, you need to test the loop itself.

Record traces. Every tool call, every intermediate reasoning step, every state change. Then write tests against those traces, not just the final output. Did the agent pick the right tool? Were the tool arguments correctly formatted? Did it hand off to a human when it should have? Did it retry correctly on a tool failure, or did it loop?

Tool-argument correctness is the sneaky one. Agents often produce a final answer that reads well while having called a tool with the wrong parameters along the way. The output looks fine. The side effect was wrong. The only way to catch that is to evaluate the trace, not just the text the user sees.

Multi-turn tests matter for conversational agents. Build canned conversation fixtures that probe memory, context handling, and topic drift. A common failure pattern: the agent answers turn one correctly, loses track of the user's stated preference by turn three, and confidently contradicts itself by turn five. You won't find that bug with single-turn tests.

Red-team before production, not after

Think about the AI agent failures that made the rounds online. Almost all of them were adversarial: someone found a way to make the agent do something it shouldn't. A structured red-team pass before launch catches the obvious ones before your users do.

The OWASP Top 10 for LLM Applications is a good starting checklist. The categories that matter most for agents: prompt injection (can a user override your system prompt?), jailbreaks (can a user bypass refusals?), PII exfiltration (can the agent be tricked into echoing training data or private context?), off-topic hijacks (can someone turn your customer support bot into a free coding assistant?), and tool misuse (can a user get the agent to call a sensitive tool with bad arguments?).

Turn the ones you find into permanent cases in your eval suite. Every real attack becomes a regression test. Over time, this is how you build a durable safety posture, not by writing a one-time policy document.

Test the UI layer, not just the LLM

Here's where teams building AI features tend to stop too early. You can evaluate the model output in a notebook all day, but your users experience the agent through a UI. That UI has its own set of failure modes: streaming that stops halfway, message state that resets on navigation, citations that don't render, tool-call indicators that stay spinning forever.

Test the whole product, not just the model. A real browser session that walks through a full conversation, checks that responses render, that retries work, that the UI handles long outputs gracefully, and that the error state is sensible when the model times out. This is exactly the kind of end-to-end validation that agentic testing is well-suited for, because an AI agent testing your AI agent can handle the non-determinism on both sides without brittle selectors.

Version-lock your LLM stack and wire it into CI

One pattern worth stealing from classic ML engineering: version-lock every dependency that affects output. Model version, system prompt, retrieval index, tool schemas, temperature, top_p. When any of those change, re-run the eval suite and record a new baseline.

In CI, run a fast subset of evals on every PR. Block merges on safety regressions and format failures, since those have clear right answers. For quality scores, post the delta as a comment and route borderline changes to a human reviewer instead of auto-failing the build. The goal is signal, not noise.

On a nightly schedule, run the full suite against the full golden dataset. That's where you catch the long-tail regressions that a PR-scoped subset misses.

Structure underneath, evals on top

There's a pattern that keeps showing up. Teams buy an eval library, hook it into their agent, and then realize they have no idea which evals cover which product behaviors, who owns them, or what changed when the scores dropped on Tuesday. The evals work. The process around them doesn't.

Same trap that catches teams doing QA for AI-generated code without a management layer underneath. Evals without structure produce more noise, not more confidence. You still need test management: who owns which eval, which product requirement does it trace back to, and what actually happened when half the suite went red last Thursday?

The teams that get this right treat AI agent QA the same way they treat any other part of the product. Same ownership, same review gates, same traceability. The evaluation technique changes. The discipline around it shouldn't.

The bar is low. That's your advantage.

AI agent QA is still early. The tooling is immature, the practices aren't standardized, and teams are figuring it out as they go. That means even a basic eval suite with a decent golden dataset puts you ahead of the curve. Not because the bar is high, but because almost nobody has cleared it yet.

Pick the three agent flows that would hurt the most if they broke. Build evals for those. Run them in CI. That's your starting point, not a 500-case benchmark you'll never finish building.

Frequently asked questions about testing AI agents

How do you test an AI agent? Build a golden dataset of representative inputs, run the agent against them, and score outputs on correctness, safety, format, latency, and robustness. Use acceptance bands instead of pass/fail assertions, since outputs are non-deterministic. Test traces (tool calls, intermediate reasoning) in addition to final answers.

What is a golden dataset? A curated, versioned set of real inputs paired with what good outputs look like. You build it from production logs, not brainstorming. It replaces the traditional test case list for AI systems and acts as your quality baseline across model versions and prompt changes.

What is LLM-as-judge evaluation? A technique where you use a stronger LLM to grade your agent's output against a rubric. It's the most practical way to evaluate open-ended responses at scale. The quality of your rubric determines the quality of your scores, so treat rubric design like you'd treat test design.

How do you run AI agent tests in CI? Run a fast eval subset on every PR, blocking merges on safety and format regressions. Post quality score deltas as PR comments. Run the full suite nightly against the complete golden dataset. Version-lock the model, system prompt, and tool schemas so you can attribute regressions to specific changes.


qtrl gives AI features the same structure you'd give any other critical product area: organized test flows, ownership, audit trails, and AI-powered execution that works against a real browser. If your team is building with LLMs and needs a QA foundation that keeps up, start free.

Have more questions about AI testing and QA? Check out our FAQ