Workflow Integration
Integrate fairness checks into every stage of the development lifecycle: experiment tracking, version control, CI/CD pipelines, testing, and collaborative review.
The features below ensure fairness is not a one-time audit but a continuous, automated practice.
Experiment Tracking
Log fairness metrics to MLflow and Weights & Biases alongside model performance.
Version Control
Pre-commit hooks validate fairness configs and model cards before every commit.
CI/CD Gates
Deployment gates block unfair models. Hierarchical checking covers intersectional groups.
Testing
pytest plugin with markers, fixtures, and terminal summary. JUnit XML for CI/CD.
Report Card
Auto-generated markdown reports for PR comments with pass/fail metrics and warnings.
DevOps Templates
Ready-to-use GitHub Actions, GitLab CI, and PR template files.
Experiment Tracking
vfairness provides first-class integration with both MLflow and
Weights & Biases. Both functions accept either a FairnessAnalyzer
instance or a raw report dictionary and log metrics, confidence intervals, effect sizes,
and group statistics.
MLflow
import mlflow
from vfairness import FairnessAnalyzer, log_fairness_to_mlflow
with mlflow.start_run():
analyzer = FairnessAnalyzer(y_true, y_pred, gender)
logged = log_fairness_to_mlflow(analyzer, prefix="model_v1")
print(f"Logged {len(logged)} metrics")
Weights & Biases NEW
import wandb
from vfairness import FairnessAnalyzer, log_fairness_to_wandb
wandb.init(project="fairness-audit")
analyzer = FairnessAnalyzer(y_true, y_pred, gender)
logged = log_fairness_to_wandb(analyzer, prefix="model_v1")
wandb.finish()
Auto-Logging Decorator NEW
from vfairness import auto_log_fairness
@auto_log_fairness(backend="mlflow", prefix="eval")
def evaluate_model(X_test, y_test, sensitive_attr):
y_pred = model.predict(X_test)
return y_pred, y_test, sensitive_attr # (y_pred, y_true, sensitive_attr)
# Fairness metrics are automatically logged when called
evaluate_model(X_test, y_test, gender)
Version Control Hooks
vfairness provides pre-commit hooks that validate fairness-related files before every commit, ensuring documentation and configuration standards are met.
Pre-commit Configuration
# .pre-commit-config.yaml
repos:
- repo: https://github.com/your-org/vfairness
rev: v0.0.8
hooks:
- id: vfairness-check-config # Validates fairness config files
- id: vfairness-check-model-card # Checks model cards for fairness sections
Hooks
| Hook | Description | Files Matched |
|---|---|---|
vfairness-check-config |
Validates that fairness config files contain required keys (metrics, thresholds) |
*fairness*.json, *bias*.yml |
vfairness-check-model-card |
Verifies model cards include fairness-related sections | *model-card*.md |
CI/CD Fairness Gates
The ModelFairnessGate class acts as a deployment gate in CI/CD pipelines,
evaluating model fairness against configurable thresholds and deciding whether deployment should proceed.
from vfairness import ModelFairnessGate
gate = ModelFairnessGate(
metrics=['demographic_parity_difference', 'equalized_odds_difference'],
thresholds={
'demographic_parity_difference': 0.1,
'equalized_odds_difference': 0.1,
},
blocking_metrics=['demographic_parity_difference'],
)
decision = gate.evaluate(y_true, y_pred, protected_attr)
if decision.approved:
deploy_model()
else:
print(decision.blocking_reasons)
The gate returns a GateDecision with status
APPROVED, CONDITIONAL, or BLOCKED.
Use gate.create_github_check(decision) to generate a GitHub Checks API payload.
Hierarchical Intersectional Gate NEW
The evaluate_hierarchical() method checks fairness at three levels:
- Overall — across all groups
- Single-attribute — per individual protected attribute (gender, race, etc.)
- Intersectional — combinations of attributes (gender × race)
from vfairness import HierarchicalGateConfig
hconfig = HierarchicalGateConfig(
check_overall=True,
check_single_attributes=True,
check_intersections=True,
intersection_depth=2,
min_group_size=30,
default_intersection_threshold_multiplier=1.2, # 20% relaxed
per_intersection_thresholds={
'Female_Black': {'demographic_parity_difference': 0.15},
},
)
decision = gate.evaluate_hierarchical(
y_true, y_pred,
protected_attrs={'gender': gender, 'race': race},
hierarchical_config=hconfig,
)
for level, result in decision.level_results.items():
print(f"{level}: {result.status.value}")
for warning in decision.small_sample_warnings:
print(f"WARNING: {warning.message}")
Small-Sample Warnings
Groups with fewer samples than min_group_size emit
SmallSampleWarning objects instead of silently producing unreliable metrics.
Each warning includes the group name, sample size, and recommended minimum.
pytest Integration
vfairness provides multiple layers of pytest integration, from simple assertions to a full test suite with JUnit XML export.
assert_fairness()
# test_fairness.py
from vfairness import assert_fairness
def test_model_is_fair():
assert_fairness(
y_true, y_pred, gender,
metrics=['demographic_parity_difference'],
thresholds={'demographic_parity_difference': 0.1},
)
FairnessTestSuite
from vfairness import FairnessTestSuite
suite = FairnessTestSuite(
protected_attributes=['gender'],
metrics=['demographic_parity_difference'],
thresholds={'demographic_parity_difference': 0.1},
)
results = suite.test_predictions(y_true, y_pred, gender)
xml = suite.to_junit_xml() # For CI/CD integration
pytest Plugin NEW
The vfairness pytest plugin registers automatically via the pytest11 entry point.
It provides:
| Feature | Description |
|---|---|
@pytest.mark.fairness | Tag a test as a fairness test |
@pytest.mark.fairness_gate | Tag a test as a gate-level check |
fairness_gate fixture | Pre-configured ModelFairnessGate factory |
assert_fairness_fn fixture | The assert_fairness function as a fixture |
| Terminal summary | Prints fairness test results at end of run |
Fairness Report Card NEW
The FairnessReportCard generates structured markdown reports for automated
PR comments. It supports both simple and hierarchical gate decisions.
from vfairness import FairnessReportCard
card = FairnessReportCard(decision, model_name="loan-model-v3")
print(card.to_markdown())
# For GitHub API
payload = card.to_github_comment_payload()
# POST to /repos/{owner}/{repo}/issues/{pr_number}/comments
DevOps Templates
vfairness ships with ready-to-use templates for common DevOps platforms.
| File | Description |
|---|---|
.github/workflows/fairness-checks.yml |
GitHub Actions workflow: runs fairness tests, evaluates gate, posts PR comment |
.gitlab-ci-fairness.yml |
GitLab CI config with fairness-tests and fairness-gate jobs |
.github/PULL_REQUEST_TEMPLATE.md |
PR template with fairness checklist |
.pre-commit-hooks.yaml |
Pre-commit hook definitions for config and model card checks |
API Summary
| Function / Class | Module | Description |
|---|---|---|
log_fairness_to_mlflow() | evaluation | Log metrics to MLflow |
log_fairness_to_wandb() | evaluation | Log metrics to W&B |
@auto_log_fairness | evaluation | Auto-logging decorator |
ModelFairnessGate | operations.cicd | Deployment gate |
HierarchicalGateConfig | operations.cicd | Hierarchical gate config |
IntersectionalGateDecision | operations.cicd | Hierarchical gate result |
SmallSampleWarning | operations.cicd | Group size warning |
FairnessReportCard | operations.cicd | PR comment generator |
FairnessTestSuite | operations.cicd | Test suite with JUnit |
assert_fairness() | evaluation | pytest assertion |
check_fairness_config() | operations.cicd | Pre-commit: config check |
check_model_card() | operations.cicd | Pre-commit: model card check |
Implementation Overview
A summary of the workflow integration capabilities provided by vfairness.
| Capability | vfairness Implementation |
|---|---|
| Experiment tracking (MLflow) | log_fairness_to_mlflow() |
| Experiment tracking (W&B) | log_fairness_to_wandb() |
| Auto-logging wrappers | @auto_log_fairness |
| Pre-commit hooks | check_fairness_config(), check_model_card() |
| PR template | .github/PULL_REQUEST_TEMPLATE.md |
| CI/CD pipelines | GitHub Actions + GitLab CI YAML templates |
| Automated PR comments | FairnessReportCard |
| pytest plugin | pytest11 entry point + markers + fixtures |
| Intersectional gate checking | evaluate_hierarchical() + HierarchicalGateConfig |
| Per-intersection thresholds | HierarchicalGateConfig.per_intersection_thresholds |
| Small-sample warnings | SmallSampleWarning |