QA Interview Hub · Knowledge base · Quizzes · Українська

AI › How to test an LLM agent

Evals in CI and production monitoring

In CI, fast tests with a mocked model run on every commit, while an eval with the real model runs less often. A subset runs on PRs that touch the prompt or model, and the full set overnight. A quality gate compares per-category pass rate with a baseline within a tolerance. In production you need traces, online scoring, canary releases and alerts, and incidents go back into the golden dataset.

AI for QA · Testing AI

The model was updated on Friday, complaints piled up on Monday and CI was green. What did it not see?

The vendor quietly updated the model behind an alias, while CI ran only unit tests with a mocked model and stayed green. Real users saw a change of tone and more refusals on Monday. Testing an LLM system does not end at release: behaviour drifts with model updates, data changes and new kinds of requests. The lesson covers what to run in CI and what to watch in production.

How it works and why. Different checks have different cost and speed, so they are laid out in layers, like a test pyramid. Fast deterministic ones stay on every commit. Expensive eval runs with a real model run less often and selectively. What the set does not see is caught by monitoring in production.

Layers of checking from commit to production

Every commitunit with a mocked modelPR touching prompt, model, tools, RAGeval subset + quality gateNightly runfull set, repeats, costProductiontraces, judge sampling, alertsIncident → new casethe golden dataset grows
Figure 1. Every real incident flows back into the golden dataset, so the set grows with the system.

In CI.

  • Every commit. A fast layer with no network: unit tests of parsing, routing, schemas, error handling and context building with a mocked model;
  • A PR touching the prompt, model, tools or RAG. An eval set with a real model. It is expensive and slow, so a subset (smaller and representative) goes on a PR, and the full set with repeats runs at night;
  • Quality gate. The pass rate not below a floor, not worse than the baseline by more than an allowed margin, plus cost and latency limits;
  • Pinned versions. The model and prompts in configuration, so a difference can be explained. For non-determinism, each case is run several times with a tolerance (not retry until the first green).

Example: a quality gate. The baseline is stored in the repository next to the set and is updated deliberately, not automatically. A script on a PR compares the current run with it:

const base = JSON.parse(readFileSync('eval/baseline.json', 'utf8'));
const cur = await runEval({ subset: 'pr' });
const problems: string[] = [];

// an absolute floor and an allowed drop from the baseline
if (cur.passRate < 0.9) problems.push('pass rate below 0.9');
if (cur.passRate < base.passRate - 0.03) problems.push('pass rate regressed');

for (const [cat, rate] of Object.entries(cur.byCategory)) {
  if (rate < base.byCategory[cat] - 0.1) problems.push('category dropped: ' + cat);
}
// cost and speed limits
if (cur.p95Tokens > base.p95Tokens * 1.3) problems.push('p95 tokens grew');

if (problems.length) {
  console.error(problems.join('\n'));
  process.exit(1);
}

The numbers in the example (0.9, 0.03, 0.1, 1.3) are illustrative: tolerances are chosen from real spread. For that, the baseline is run several times to see how much the result fluctuates with no changes at all. A tolerance below this noise gives false red builds, one that is too wide lets a regression through. A separate check per category is needed because an average hides the failure of one of them, and for safety rules the tolerance is zero.

In production. An eval sees only known cases, so production needs other tools as well.

Offline eval and online monitoring

Offline

Eval in CI

Catches regressions on known cases before release. Controlled and reproducible, but sees only what is already in the set.

Online

Production monitoring

Sees real requests, drift and new scenarios. Less controlled, since there is no reference, so it relies on a judge, feedback and alerts.

Figure 2. They complement, not replace each other: offline gives control, online gives reality.
  • Observability. Log (carefully with personal data) the prompt, model version, tool calls, tokens, latency, cost; a trace for every request;
  • Online scoring. A sample of real dialogues goes through a judge with the same rubric as in the eval. User feedback (answer ratings) and escalations to a person are added;
  • Canary release and A/B. A new model or prompt first gets a small share of traffic, and results are compared with the baseline version;
  • Alerts. A jump in cost, in the refusal rate, in tool errors, in answer length, a change in the distribution of request topics;
  • A closed loop. Every real incident becomes a new case in the golden dataset so that it does not repeat.

Limits and alternatives. Monitoring with no reference is weaker than an eval: the judge can be wrong, and user feedback gives a partial and delayed picture. So online scoring is calibrated and samples for manual review are taken regularly. Logs with personal data need a retention and masking policy, especially if requests reach third-party services. If a vendor announces a model version retirement, it is a planned event: the eval on the new version runs before switching, not after.

Common mistakes.

  • An eval with a real model on every commit. Consequence: slow, expensive, the build is noisy from non-determinism.
  • A gate with only an absolute floor. Consequence: gradual degradation above the floor is invisible until it crosses the line.
  • Updating the baseline automatically. Consequence: a regression becomes the new normal.
  • No traces in production. Consequence: an incident cannot be reproduced.
  • Not returning incidents to the set. Consequence: the same defects repeat.

Check yourself

The vendor updated the model behind an alias on Friday. Which mechanisms should have prevented this or caught the change before the users?

Answer

A pinned model identifier, so the update does not happen without a decision, and a nightly eval on the current configuration together with production monitoring that notices a change in the refusal rate or tone. The difference between runs can be explained because versions are recorded in the report.

The quality gate often turns red with no code changes. What is the likely cause and what do you do?

Answer

The tolerance is smaller than the natural noise of non-determinism. Run the baseline several times, measure the spread and set the tolerance with that in mind, and add repeats for critical cases.

Why does a PR run a subset of the eval and the full set runs at night?

Answer

A full run with a real model is expensive and slow, and its delay would block development. A subset catches most obvious regressions, while the nightly run checks everything with repeats.

In an interview. Junior: In CI fast tests with a mocked model run on every commit, while evals with a real model run less often. In production we log and watch metrics. Middle/Senior: The quality gate compares the pass rate by category with a baseline within a tolerance measured on the noise of repeats, plus cost and latency limits. In production there are traces, judge sampling, canary releases and alerts, and every incident goes back into the golden dataset. Model and prompt versions are pinned so a difference can be explained.

More articles in this chapter