BXUP Track progress & test yourself — free
QA & Testing · Module · ~12 min read
QA & TESTING · MODULE

Testing AI Systems II — Judges, Agents, MCP & Release Criteria

An uncalibrated judge gating a release is a random number generator with authority — and an agent that reaches the right answer by the wrong path is a production incident on a delay timer. This module covers judge calibration, tool-call and trajectory testing, MCP contract tests, simulated-user conversations, refusal matrices, and cost/latency as release criteria.

The stakes are documented, not hypothetical: Applause's 2026 State of Digital Quality found that while 54.5% of organizations shipped AI features, 44.1% deactivated at least one after shipping — cost, quality or risk killed features that had passed whatever gate existed. That deactivation rate is the strongest argument for this module: the release criteria for AI features were the missing discipline, and QA is the function positioned to own them. Module 6 built the foundations; this module is the advanced practice that decides whether the feature ships, stays shipped, and earns its bill.

The scenario — right answer, wrong path

  1. Q3

    Sara's support copilot grows up: it becomes an agent. Given a ticket, it can look up orders, check refund policy, and draft — with approval — an actual refund through the billing system's MCP server. The team's tests check final outputs: was the refund decision correct? Pass rate: 96%. Everyone is comfortable.

  2. THE TRACE

    Doing dataset curation, Sara reads one passing trace end to end — and goes cold. Ticket: customer overcharged ₹1,200. The agent's final answer: correct refund, correct amount, polite message. The path: it called issue_refund twice — first for the full order value, then, apparently "noticing" its error, called charge_customer to claw back the difference. Net result: correct. Actual behavior: two spurious financial transactions that the customer's bank statement will absolutely show.

  3. THE REALIZATION

    Every final-response test in the suite scores this trace as a pass. The failure lives entirely in the trajectory — the sequence of tool calls — which nothing asserts. Worse: a sampling of passing traces finds three more pattern classes: redundant lookup loops (cost), a policy check performed after the refund rather than before (compliance), and one trace where the right answer emerged from a hallucinated policy quote the tools never returned.

  4. THE REBUILD

    The test bench splits into layers: deterministic asserts on tool selection and parameters separately; trajectory specs with expected paths, forbidden orderings and loop detection; contract tests on the MCP server itself — including timeout and error paths; and an LLM judge for answer quality that is calibrated against Sara's own labels before it may block anything.

  5. THE CATCH

    Two weeks later, a model-version bump passes every final-response check — and fails the trajectory gate: step count on refund tasks up 40%, one forbidden ordering (refund before policy check) reappearing at low frequency. The bump is held back. Finance never sees the double-transaction pattern again.

Final answers are the tip of the agent. The behavior — what it called, with what arguments, in what order, at what cost — is the iceberg, and it is testable.

What You'll Learn

  • Judge calibration before gatingrubric design, bias controls, and judge-vs-human agreement measurement on a labeled gold slice, as a mandatory protocol (UC-44).
  • RAG acceptance with failure attributionthresholds on faithfulness and context precision, and routing each failure to retrieval or generation (UC-43, UC-52).
  • Agent tool-call testing in two dimensionsselection and parameter construction asserted separately, deterministically where possible (UC-45).
  • Trajectory evaluationexpected-path specs, loop detection, step efficiency, and the right-answer-wrong-path catch (UC-46).
  • MCP contract testingthe tool layer tested like the API it is: schemas, discovery, error and timeout paths, auth scoping, version drift (UC-47).
  • Multi-turn testing with simulated usersconfused, hostile, off-topic and code-switching personas against your conversation criteria (UC-48).
  • Robustness red-teaming and the refusal matrixmust-refuse and must-not-over-refuse as paired suites (UC-49, UC-50).
  • Cost, latency and resilience as release criteriaTTFT percentiles, token budgets, and chaos tests for the AI dependency (UC-51, UC-54).

Calibrating the judge — before it holds the gate

Module 6 put the LLM judge at the top of the assertion hierarchy and attached a warning. Here is the discharge of that warning. A judge is an LLM with documented biases — position bias (favoring the first or last option compared), verbosity bias (longer answers score higher at equal quality), self-preference, and rubric drift under ambiguity. An uncalibrated judge does not merely add noise; it adds systematic error with a confident voice, and wiring it to a release gate hands your go/no-go to those biases. The calibration protocol is the antidote, and it must complete before the judge acquires any authority:

  1. Design a rubric that a careful human could apply. Concrete criteria, defined score anchors ("5 = every claim traceable to the ticket; 3 = minor unsupported detail; 1 = fabricated commitment"), one quality per rubric — a judge scoring "overall goodness" is unfalsifiable.
  2. Hand-label a gold slice. 100–200 outputs, labeled by the humans who own quality — for a QA engineer this is a few focused days, and it doubles as the deepest product education you will ever get. The labels are the standard the judge must meet.
  3. Measure agreement. Run the judge over the slice; compare against your labels with an agreement statistic (Cohen's kappa, not raw percentage — a judge that says "pass" to everything scores high raw agreement on an imbalanced slice while being useless).
  4. Debug the disagreements. Every judge-vs-human mismatch is either a rubric ambiguity (fix the rubric), a judge bias (counter it: randomize positions, cap or normalize length, require reason-before-verdict), or occasionally a wrong human label (fix the label — calibration audits both sides).
  5. Set the authority threshold and re-calibrate on schedule. Above the agreed kappa, the judge may gate; below, it may only advise. Judges drift when their underlying model updates — re-run agreement on every judge-model change and periodically regardless.
CALIBRATION · summarizer judge v3

agreement report — gold slice n=150

κ = 0.81— above the 0.75 gate threshold; judge authorized to blockwas κ = 0.52 pre-calibration · two biases fixed, one rubric rewrite
  • Position bias: eliminated by randomizing comparison order (was +9% first-position)
  • Verbosity bias: length-normalized after correlation r=0.41 between tokens and score
  • Rubric v3: "faithful" split into "no fabricated facts" and "no omitted commitments" — disagreements fell 60%
  • Residual: judge lenient on hedged fabrications — flagged class routes to human review

Below threshold, a judge advises. Only above it does a judge gate — and it re-earns the right on every model change.

Exam Tip

"The team wants an LLM judge to gate releases — what must happen first?" is answered by the protocol, and the load-bearing phrase is measured agreement against human labels on a gold slice. Any answer that wires a judge to CI without an agreement number is the planted wrong option.

The judge protocol's first consumer is RAG acceptance testing (UC-43): the DS team designs the metrics (faithfulness, context precision, answer relevancy — Ragas-class, consumed via DeepEval or Langfuse); QA owns the accept/reject decision against agreed thresholds and — the distinctly QA contribution — failure attribution. A failed case routes differently depending on where it broke: retrieval returned the wrong passages (search/indexing bug) versus retrieval was right and generation contradicted it (prompt/model bug). A bug report that says "faithfulness 0.62, retrieval verified correct for these five cases, generation contradicts context — here are the traces" gets fixed in a sprint; "the AI is wrong sometimes" gets a shrug.

Agent testing — selection, parameters, trajectory

Agent failures decompose into dimensions that fail independently, and the test design must respect the decomposition — mushing them into one "did it work?" assert is how Sara's team got a comfortable 96% while double-charging customers.

Dimension one: tool selection. Given this state, did the agent call the right tool? Deterministic: the expected tool name is known, the trace records the actual call, assert equality. No judge required.

Dimension two: parameter construction. Right tool — right arguments? An agent can correctly choose issue_refund and pass the wrong amount, the wrong currency, the wrong order ID. Assert required params exactly where ground truth exists; schema-validate everything else. Still no judge. These two dimensions, asserted separately over traced runs (DeepEval agent metrics, Langfuse/LangSmith traces, or plain pytest over trace JSON), catch a remarkable share of agent bugs at deterministic-assert prices — and when they fail, they tell you which dimension broke, which is triage gold.

Dimension three: the trajectory. Three test designs, in increasing depth — you need all three, weighted by risk:

  • Final-response (black-box)assert on the answer alone. Cheapest, catches outcome failures, and structurally blind to wrong-path successes: this is the design that scored the double-refund trace as a pass.
  • Trajectory (glass-box)assert on the tool-call sequence against an expected-path spec: required steps with exact/any-order/subset matching, forbidden orderings (policy check must precede refund), loop detection (the same call with the same args twice is a bug, not persistence), and step-efficiency budgets (baseline steps per task class; alert on regression — step inflation is silent cost inflation).
  • Single-step (white-box)freeze a mid-trajectory state, assert the next decision. This is unit testing for agent decisions: fast, precise, ideal for regression-testing the exact fork where a past incident happened.
Remember:

"Right answer, wrong path" is not pedantry — the path is behavior. Sara's double-refund produced correct arithmetic and two real financial transactions. Any agent whose tools touch money, records or messages needs trajectory asserts on its riskiest task classes, because final-response testing certifies outcomes while ignoring conduct.

The MCP layer — contract-test the tools themselves

Under every tool-using agent sits a tool server — increasingly an MCP server — and it is an API under contract, testable with entirely classical instincts without an LLM in the loop (UC-47). Separating this layer is what makes agent debugging tractable: when the bench fails, you know immediately whether the agent chose wrong or the tool lied.

  • Schema validity and discoveryevery tool definition validates; names, descriptions and parameter schemas are exactly what agents were built against. A silently renamed parameter is an outage the agent will narrate confidently.
  • Happy, error and timeout paths per toolcorrect results; structured, informative errors for bad input (an agent retrying against an unhelpful error loops — Sara's loop detector fires on exactly this); and injected timeouts (Toxiproxy-class) to verify the agent's handling, because an agent that hangs or hallucinates a result when a tool stalls is a production incident with a countdown.
  • Auth scopingthe agent's credential reaches only its allowlisted tools; scope violations are denied and logged. This is a security boundary wearing an API-test costume.
  • Version-drift regressionpin the contract in CI; any server upgrade that changes schemas fails loudly. MCP Inspector and FastMCP's test client cover interactive and automated paths.

Above the tool layer, multi-turn conversational testing (UC-48) closes the behavioral surface: scripted dialog flows for known-critical paths, then LLM-simulated user personas — confused (vague, self-contradicting), hostile (abusive, demanding), off-topic (drifting to what the bot must not do), and code-switching (mid-conversation language mixing, an everyday reality for Indian deployments) — with asserts on context retention across turns, recovery from derailment, and explicit conversation-completion criteria. Simulated users generate the volume; your persona design and completion criteria decide whether the volume means anything.

Robustness, refusals, and the budgets that keep features alive

Red-teaming, quality lens. QA owns robustness: garbage input, adversarial phrasing, prompt-format abuse, long-context stress, multilingual probes — Promptfoo's redteam plugins automate generation at scale, and your job is triage: which failures are quality bugs to fix, and which are security-class findings (injection, exfiltration) that route to the security team, who own that discipline end to end (UC-49).

The refusal matrix. Guardrails fail in two directions, and testing only one is half a test (UC-50). Applause's deactivation statistic looms here: over-refusal — the feature lecturing legitimate users into abandonment — kills shipped features as surely as scandal does.

Should refuseShould answer
RefusesCorrect block — must-refuse suite passesOver-refusal — legitimate user turned away; UX kills features this way
AnswersGuardrail miss — harmful/off-policy output; route by classCorrect behavior — the product working

Both off-diagonal cells get golden suites with tracked rates: a must-refuse set (rate ~100%, misses triaged by severity) and a must-answer set of legitimate-but-edgy requests near the boundary (refund demands with angry language, medical-adjacent questions to a general assistant). Every guardrail change runs both — tightening one cell silently moves the other, which is why the matrix is paired by construction.

Cost, latency and resilience as release criteria (UC-51, UC-54). The final QA ownership: the budgets. Time-to-first-token and total-latency percentiles under realistic load (k6 against the feature path); token and rupee/dollar cost per task tracked per release (Langfuse-class cost tracing) with budget-regression gates in CI — a prompt change that doubles token spend is a regression even when every quality gate passes, and step inflation from the trajectory section lands here as money. And resilience: chaos-test the AI dependency like the third-party service it is — provider outage (does the feature degrade gracefully or take checkout down with it?), rate-limit storms, and the silent model-version swap, which is precisely when your golden dataset re-runs and tells you within the hour what changed.

Pro Tip

Publish the budgets next to the quality thresholds in the release criteria — p95 TTFT, cost per task, refusal rates, trajectory step budget, judge kappa. A one-page criteria sheet, agreed before the release, converts every go/no-go argument into a reading of numbers — and it is the sheet Module 8's audit lab has you sign.

Where this lands in your week

  • In gate designno judge blocks anything without an agreement report; below-threshold judges advise humans, and re-calibration triggers on every judge-model change.
  • In agent QAselection and parameter asserts run deterministic and cheap on every PR; trajectory specs guard the risky task classes; one passing trace gets read end-to-end per week, because that habit is what caught the double refund.
  • In integration testingthe MCP contract suite is a standing CI job; tool-layer changes cannot reach the agent unannounced.
  • In release meetingsyou bring the criteria sheet: quality thresholds, refusal rates, budgets, and the chaos-test results. The go/no-go stops being vibes.
Key Takeaway:

Advanced AI testing is authority management: a judge earns gate authority through measured agreement with human labels, an agent earns trust through selection, parameter and trajectory asserts — not final answers alone — and the tool layer earns it through contracts. Add the refusal matrix and the cost/latency budgets, and "should this ship?" becomes a sheet of numbers you can sign — which is exactly what the 44.1% deactivation rate says most teams were missing.

Try it now

  1. Read three traces end to end. Pull three passing runs of any agent (or multi-step LLM flow) you can access and audit the full path: redundant calls, odd orderings, steps that contradict policy. Log what final-response testing was hiding.
  2. Run a micro-calibration. Hand-label 20 LLM outputs pass/fail against a two-line rubric, run an LLM judge over the same 20, and compute agreement. Diagnose your two biggest disagreements: rubric ambiguity, judge bias, or label error?
  3. Draft one refusal matrix. For an AI feature you know, write five must-refuse and five must-answer cases near the policy boundary; run them and place each result in the matrix's four cells.

Take this into Lab 13 (calibrated judge for a release gate) — agreement measured before and after fixing seeded rubric biases — and Lab 14 (agent & MCP test bench), whose seeded right-answer-wrong-path behavior your trajectory tests must catch, then Lab 15 (AI-feature release audit) for the full criteria sheet. Companion playbooks: pb-40 through pb-47.

This is the free reading view. Open BXUP to track your progress, run the hands-on labs, and prove it with original, exam-pattern assessments.
© Anvi Innovate · BXUP — Be Exponentially Upskilled · BXUP is an independent learning platform, not affiliated with or endorsed by AWS, Microsoft, Google, NVIDIA, IBM, Salesforce, Databricks, Oracle or Anthropic. All trademarks belong to their respective owners. · bxup.in