Evaluating Foundation Models for Fairness
This lesson covers fairness test design, metrics, A/B testing and automated evaluation that systematically measure the biases foundation models can reproduce from human-written text.
Learning outcomes
After completing this lesson, you will be able to:
- Design counterfactual fairness tests.
- Track fairness metrics across groups.
- Run systematic A/B tests and LLM-as-a-judge evaluations.
Designing fairness tests
A practical approach for generative AI is counterfactual testing: create pairs or sets of prompts that are identical except for a sensitive attribute or its proxy, such as a name associated with a gender or ethnicity, an age, a nationality or a disability, and compare the outputs. Differences in recommendations, scores, refusal rates, tone, length or the presence of stereotypes indicate bias. Tests cover the application's real tasks, such as summarising candidate profiles or drafting loan explanations, rather than generic benchmarks.
The following diagram shows a counterfactual fairness evaluation of CV summaries.

Testing for bias
Fairness metrics
Fairness tests produce outputs for different groups; metrics turn the comparison into numbers that can be tracked and acted on. Typical metrics are the difference in favourable outcome rates between groups, for example the share of candidate profiles recommended for interview; differences in average sentiment or politeness of responses; differences in refusal rates; and the rate of stereotyping detected by an LLM judge.
Each metric has a threshold that defines an acceptable difference, agreed with the business and, where relevant, legal advisers. Publishing the metrics to Amazon CloudWatch with alarms turns fairness from a one-time check before launch into a monitored property, measured on evaluation runs after each change and on sampled production traffic, so that a regression introduced by a new model or prompt is detected promptly.
Systematic A/B testing and LLM-as-a-judge
Prompt Management variants and Bedrock Flows make it easy to run the same fairness test set through different prompts or models and compare results: for example, a variant with explicit instructions to ignore irrelevant personal attributes versus the original. Results are compared on fairness metrics and on task quality, because a fairer prompt that ruins accuracy is not a solution.
LLM-as-a-judge evaluations in Amazon Bedrock score responses at scale with built-in metrics such as stereotyping and harmfulness, or custom metrics with a rubric for the organisation's fairness criteria. Human reviewers check a sample to confirm the judge's assessments. The following table summarises the methods.
| Method | Measures | Tooling |
|---|---|---|
| Counterfactual prompt sets | Output differences when only a sensitive attribute changes | Test datasets in S3 |
| Outcome rate differences | Unequal recommendations or decisions | Custom metrics in CloudWatch |
| A/B comparison of prompts or models | Which configuration is fairer at equal quality | Prompt Management variants, Flows |
| LLM-as-a-judge | Stereotyping, harmfulness, custom fairness rubric | Bedrock evaluation jobs |
| Human review of samples | Judge accuracy and nuanced issues | Bedrock human evaluation, A2I |
Comparing for fairness
Candidate summaries
A recruiting tool summarises CVs and suggests a fit score. The company must show the scores do not vary by gender.
The team builds a counterfactual set of CVs that differ only in names and pronouns, runs it through two prompt variants in Prompt Management, measures the difference in average fit scores and the stereotyping score from a Bedrock LLM-as-a-judge evaluation, chooses the variant within threshold, and publishes the gap metric to CloudWatch for monitoring on sampled production data.
How can differences in outcome rates between groups be tracked over time?
Show answer
Publish them as CloudWatch metrics and alarm when the difference exceeds a threshold.
Exam Tips
Remember for the exam
- Counterfactual prompts that change only a sensitive attribute reveal bias.
- Track outcome rate differences between groups as CloudWatch metrics.
- Compare prompts or models with Prompt Management variants or Flows.
- Score stereotyping at scale with LLM-as-a-judge; validate with human samples.