Sub topic 15
Documenting results and governing change
A fairness audit has value only if someone can read it later, repeat it, and act on it. This chapter covers what to record after an audit, how to tie that record to a model version, and how to control changes so a model that passed once does not drift into harm unnoticed.
It assumes you have the earlier chapters' material: per-group rates, the main group fairness criteria, uncertainty in small subgroups, the audit workflow, and mitigation. Prerequisites are Python with NumPy, pandas, and scikit-learn.
Why documentation is part of the assessment
A set of gap numbers without context is easy to misread. Consider a report that says "equal opportunity gap: 0.04". A reader cannot tell which groups were compared, how many people were in each group, which threshold was used, or whether 0.04 was acceptable. They also cannot tell whether it was measured on the data the model will see in production.
Documentation fixes this in three ways:
- It makes the audit reproducible. Another person can rerun it and get the same numbers.
- It makes the decisions reviewable. The choice of criterion, the tolerance, and the accepted trade-offs are written down where others can challenge them.
- It makes later change comparable. When the model is retrained, you can compare the new audit with the old one, line by line.
What to record
A useful audit record has five parts.
Scope and context
State what the model decides, who is affected, and what harm a wrong decision causes. Name the deployment setting, the decision threshold, and any human review step. This ties back to the harms discussion at the start of the tutorial. A false negative in a loan decision and a false negative in a medical screen call for different criteria.
Data and groups
Record where the evaluation data came from and its date range. Record how each sensitive attribute was defined, who supplied it (self-reported, inferred, or collected by a third party), and how missing values were handled. List the group sizes. Note any group you could not evaluate, and say why.
Criteria, tolerances, and rationale
State which fairness criteria you chose and which you set aside. Give the tolerance for each, for example "TPR gap at most 0.05 with the 95% interval below 0.10". Explain why. Because the criteria cannot all hold at once, the rationale for the choice is as important as the numbers.
Results with uncertainty
Report each metric per group, the gap, and an interval. Include the counts behind each rate. A gap of 0.08 from groups of 40 people means something different from the same gap from groups of 40,000.
Limitations and decisions
List what the audit did not cover: intersections you lacked data for, shifts in population you expect, proxies you did not test. Then record the decision (ship, ship with conditions, mitigate, do not ship), who made it, and the date.
Producing the record from code
Write the record as a machine-readable file next to the model, generated by the same code that computes the metrics. That avoids copying numbers by hand. The sketch below bootstraps an interval for the TPR gap and writes a JSON report.
import json
from datetime import date
import numpy as np
def tpr(y_true, y_pred):
pos = y_true == 1
return y_pred[pos].mean() if pos.any() else np.nan
def tpr_gap(y_true, y_pred, group, g1, g2):
m1, m2 = group == g1, group == g2
return abs(tpr(y_true[m1], y_pred[m1]) - tpr(y_true[m2], y_pred[m2]))
def bootstrap_interval(y_true, y_pred, group, g1, g2, n_boot=1000, seed=0):
rng = np.random.default_rng(seed)
n = len(y_true)
gaps = []
for _ in range(n_boot):
idx = rng.integers(0, n, n)
gap = tpr_gap(y_true[idx], y_pred[idx], group[idx], g1, g2)
if not np.isnan(gap):
gaps.append(gap)
return tuple(np.percentile(gaps, [2.5, 97.5]))
# Small synthetic example so the script runs as shown.
rng = np.random.default_rng(1)
n = 2000
group = rng.choice(["A", "B"], size=n)
y_true = rng.integers(0, 2, n)
flip = rng.random(n) < np.where(group == "A", 0.15, 0.25)
y_pred = np.where(flip, 1 - y_true, y_true)
low, high = bootstrap_interval(y_true, y_pred, group, "A", "B")
report = {
"model_version": "credit-model-1.4.0",
"audit_date": date.today().isoformat(),
"eval_data": "synthetic example",
"criterion": "equal_opportunity",
"tolerance": {"tpr_gap_max": 0.05, "interval_upper_max": 0.10},
"group_sizes": {g: int((group == g).sum()) for g in ["A", "B"]},
"tpr_gap": round(float(tpr_gap(y_true, y_pred, group, "A", "B")), 4),
"tpr_gap_ci95": [round(float(low), 4), round(float(high), 4)],
"decision": "pending review",
"limitations": ["No intersectional analysis", "Group labels self-reported"],
}
print(json.dumps(report, indent=2))Storing the report in version control alongside the code means a reviewer can see exactly which code and data produced each number.
Standard documentation formats
You do not have to invent the layout. Two widely used formats cover most of what is above.
| Format | Documents | Fairness content |
|---|---|---|
| Model card | A trained model | Intended use, evaluation data, metrics broken down by group, known limitations |
| Datasheet for datasets | A dataset | How data was collected, who is represented, known gaps and biases |
A model card holds the audit summary and links to the full report. A datasheet explains where bias may have entered. Use both: the datasheet covers the "where bias enters" part of the audit, and the model card covers the "what we measured" part.
Governing change
A passing audit describes one model, on one dataset, at one moment. Several things can invalidate it:
- Retraining on new data changes the model and may change group rates.
- Threshold changes shift selection rate, TPR, and FPR for each group, usually by different amounts.
- Mitigation such as group-specific thresholds changes behavior on purpose, so it needs its own audit.
- Population drift changes the mix of people or the relationship between features and outcomes. Base rates per group can move, which changes what each criterion demands.
- Feature changes can introduce proxies for a sensitive attribute.
Governance means deciding in advance what happens when any of these occurs.
Treat the audit as a release gate
Make the fairness check a required step before a model version is promoted. The gate compares the new audit report with the stored tolerances and the previous version's results.
def release_gate(report, previous=None, max_regression=0.02):
"""Return (passed, reasons) for an audit report dictionary."""
reasons = []
tol = report["tolerance"]
if report["tpr_gap"] > tol["tpr_gap_max"]:
reasons.append("TPR gap above tolerance")
if report["tpr_gap_ci95"][1] > tol["interval_upper_max"]:
reasons.append("Upper bound of the interval above tolerance")
if previous is not None:
if report["tpr_gap"] > previous["tpr_gap"] + max_regression:
reasons.append("Gap regressed against previous version")
return (len(reasons) == 0, reasons)
current = {
"tpr_gap": 0.07,
"tpr_gap_ci95": [0.03, 0.11],
"tolerance": {"tpr_gap_max": 0.05, "interval_upper_max": 0.10},
}
passed, reasons = release_gate(current, previous={"tpr_gap": 0.04})
print(passed, reasons)Run on the example above, the gate fails for three reasons: the gap is above 0.05, the interval's upper bound is above 0.10, and the gap rose by more than 0.02 compared with the previous version. A failing gate does not decide the outcome. It sends the change to a person who can accept the risk, require mitigation, or reject the release.
Monitor after release
Offline audits use labeled data. In production, labels often arrive late or not at all. Plan for this:
- Track selection rate per group continuously. It needs no labels.
- Track TPR, FPR, and precision per group once labels arrive, and report the delay.
- Alert on group size changes, since a shrinking group widens the intervals.
- Schedule a re-audit at a fixed interval, and also after any trigger listed above.
Roles and ownership
Assign names to these responsibilities before they are needed:
- Audit owner. Runs the audit and writes the report.
- Reviewer. Someone independent of the model's authors, who checks the choice of criteria and the interpretation.
- Decision owner. Has the authority to accept residual gaps or stop a release.
- Escalation path. Who is told if monitoring finds a problem in production.
The decision owner should be able to explain the accepted trade-off in plain words, for example "We accept a small precision gap to keep TPR equal across groups, because missing a qualified applicant is the costlier error here."
Common mistakes
- Reporting only the point estimate. Without the interval and group sizes, a reader cannot tell signal from noise.
- Documenting the winner only. Record the criteria you rejected and why. Otherwise a later reviewer cannot tell whether the choice was deliberate.
- Auditing once. A model that passed last year may not pass after a retrain on new data.
- Changing the threshold quietly. A threshold edit is a model change. Route it through the gate.
- Treating the gate as the goal. A model can pass a numeric tolerance and still cause harm in a group you did not measure. The limitations section exists to say so.
- Storing the report apart from the model. Link the report to the model version identifier so neither can be found without the other.
Exercises
Exercise
A team retrains its model monthly. Name two checks they should add to the process so that fairness is governed, not just measured once, and say what each one catches.
Show answer
First, a release gate that compares each new audit report with stored tolerances and the previous version's results. It catches a retrained model whose per-group gaps have grown, even if the overall accuracy improved. Second, per-group monitoring in production, such as selection rate by group, with alerts on drift and on shrinking group sizes. It catches changes in the population or in label behavior that an offline audit on old data cannot see.
Exercise
An audit report states "demographic parity gap: 0.03" and nothing else. List four items missing that a reviewer would need before trusting it.
Show answer
Any four of: the groups compared and how they were defined; the group sizes; an interval or other measure of uncertainty; the decision threshold; the evaluation data source and date; the tolerance and the reason for choosing demographic parity over other criteria; the limitations; the model version; the decision and who made it.