Two AI versions can finish the same evaluation with similar pass rates while disagreeing on which cases pass. Keep the case IDs and compare the outcomes as pairs. An exact McNemar test asks whether candidate-only passes and baseline-only passes are balanced. It gives a different view from a release threshold, which may still forbid even a single regression on a critical case.

Prerequisites

Use Python 3.12 and only the standard library. Save the example as paired.py. Each mapping contains one boolean verdict per case ID, scored using the same rubric. This implementation is intended for small offline evaluations.

from fractions import Fraction
from math import comb

def compare(baseline, candidate):
    if not baseline or baseline.keys() != candidate.keys():
        raise ValueError("need the same nonempty set of case IDs")
    if any(type(x) is not bool for x in (*baseline.values(), *candidate.values())):
        raise ValueError("use boolean pass/fail values")
    wins = sum(candidate[q] and not baseline[q] for q in baseline)
    losses = sum(baseline[q] and not candidate[q] for q in baseline)
    n = wins + losses
    tail = sum(comb(n, i) for i in range(min(wins, losses) + 1))
    return wins, losses, min(Fraction(1), Fraction(2 * tail, 2 ** n))

old = {i: i >= 8 for i in range(12)}
new = {i: i != 8 for i in range(12)}
wins, losses, p = compare(old, new)
assert (wins, losses, p) == (8, 1, Fraction(5, 128))
assert compare(old, old) == (0, 0, 1)
assert compare(new, old) == (1, 8, p)
print(f"wins={wins} losses={losses} p={float(p):.5f}")

Run python3 paired.py. Expected output:

wins=8 losses=1 p=0.03906

Interpret the discordant pairs

Nine of the twelve pairs disagree. Under the null hypothesis, conditional on those nine disagreements, either version is equally likely to win each independent pair. The lower tail includes zero and one win, with 1 + 9 equally weighted sequences out of 512. The symmetric two-sided tail doubles that probability. For identical verdicts the function returns 1, meaning there are no discordant pairs to provide evidence of an imbalance.

Report wins and losses alongside the p-value. The difference in the two observed pass rates is seven cases out of twelve here. The p-value is neither the probability that the candidate is better nor a measure of how important the lost case is. Do not make a launch decision from it alone. In particular, a large p-value on a small suite does not establish equivalence.

If the function reports mismatched IDs, investigate missing runs or duplicate rows before constructing dictionaries. A duplicate ID can be overwritten when the dictionary is built, which the function cannot detect afterward. Near-duplicate cases from the same conversation may not be independent, and rerunning the same prompt many times does not turn it into many independent cases. Pick your evaluation and comparison rule before inspecting results, and avoid treating repeated comparisons across many slices as one test. For large evaluations use a reviewed statistical routine rather than summing many exact binomial coefficients in application code.

Reference: statsmodels documentation on McNemar's exact test. More AI tutorials.