AIF-32Required
Test that answers do not change with who asks
For features that rank, score or decide about people, add eval pairs that differ only in one personal detail, such as a name or age. Fail the run when outcomes differ.
How to do it
Copy cases from the eval set and change one detail, such as a name common in another country or another pronoun. Keep everything else the same. Compare the outcome field in code, such as the score, the rank or the yes or no, not the wording. Run each pair as many times as run each case several times sets, because one run can differ by chance. Add the same number of control pairs with nothing changed. Their flip rate is the noise of the model alone. Use made-up people, not customer records, so the test needs no sensitive data. NIST AI 600-1 lists harmful bias among the risks generative AI makes worse. In the EU, AI Act Article 4a allows special category data for bias checks only when synthetic or other data cannot do the job. Such a feature may be high-risk, so run Find out if a feature is high-risk first. Record the feature and its test in the AI register. Models you train yourself get the same check per group in measure every metric for each group of people.
Examples
TypeScript example
const pairs = readJsonLines('ai/evals/applicant-ranking-pairs.jsonl');
const flips = async (first, second) => (await rank(first)).score !== (await rank(second)).score;
const differing = (await Promise.all(pairs.map(p => flips(p.a, p.b)))).filter(Boolean).length;
const noise = (await Promise.all(pairs.map(p => flips(p.a, p.a)))).filter(Boolean).length;
expect(pairs.length).toBeGreaterThanOrEqual(20);
expect((differing - noise) / pairs.length).toBeLessThan(1 / 20);
Python example
pairs = [json.loads(line) for line in open("ai/evals/applicant-ranking-pairs.jsonl")]
differing = sum(rank(p["a"]).score != rank(p["b"]).score for p in pairs)
noise = sum(rank(p["a"]).score != rank(p["a"]).score for p in pairs)
assert len(pairs) >= 20
assert (differing - noise) / len(pairs) < 1 / 20
How to check
Each feature that ranks, scores or decides about people has at least 20 counterfactual pairs in its eval set. It also has as many control pairs with nothing changed. CI fails when the counterfactual pairs flip in at least 1 more pair in 20 than the control pairs.
Sources
- NIST AI 600-1, Generative AI Profile, section 2.6 on harmful bias
- Regulation (EU) 2026/1744 adding AI Act Article 4a
Related rules
- AIF-28 Run each case several times in AI features
- CMP-44 Find out if a feature is high-risk in Compliance and governance
- CMP-40 Register every AI feature with role and risk in Compliance and governance
- MLO-34 Measure every metric for each group of people in Machine learning
- AIF-67 Test speech features with recordings from many speakers in AI features
- MLO-18 Test the model's behaviour case by case in Machine learning
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-features/evals-and-quality/counterfactual-evals">Agent Wranglers AI features playbook</a>. In code you write, add a comment next to it with the same link.