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.

Workflow Integration Demo: vfairness_8_workflow_integration.ipynb — End-to-end validation of MLflow/W&B tracking, pre-commit hooks, CI/CD gates, pytest fixtures & report cards

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

python
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

python
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

python
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

yaml
# .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

HookDescriptionFiles 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.

python
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:

  1. Overall — across all groups
  2. Single-attribute — per individual protected attribute (gender, race, etc.)
  3. Intersectional — combinations of attributes (gender × race)
python
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()

python
# 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

python
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:

FeatureDescription
@pytest.mark.fairnessTag a test as a fairness test
@pytest.mark.fairness_gateTag a test as a gate-level check
fairness_gate fixturePre-configured ModelFairnessGate factory
assert_fairness_fn fixtureThe assert_fairness function as a fixture
Terminal summaryPrints 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.

python
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.

FileDescription
.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 / ClassModuleDescription
log_fairness_to_mlflow()evaluationLog metrics to MLflow
log_fairness_to_wandb()evaluationLog metrics to W&B
@auto_log_fairnessevaluationAuto-logging decorator
ModelFairnessGateoperations.cicdDeployment gate
HierarchicalGateConfigoperations.cicdHierarchical gate config
IntersectionalGateDecisionoperations.cicdHierarchical gate result
SmallSampleWarningoperations.cicdGroup size warning
FairnessReportCardoperations.cicdPR comment generator
FairnessTestSuiteoperations.cicdTest suite with JUnit
assert_fairness()evaluationpytest assertion
check_fairness_config()operations.cicdPre-commit: config check
check_model_card()operations.cicdPre-commit: model card check

Implementation Overview

A summary of the workflow integration capabilities provided by vfairness.

Capabilityvfairness Implementation
Experiment tracking (MLflow)log_fairness_to_mlflow()
Experiment tracking (W&B)log_fairness_to_wandb()
Auto-logging wrappers@auto_log_fairness
Pre-commit hookscheck_fairness_config(), check_model_card()
PR template.github/PULL_REQUEST_TEMPLATE.md
CI/CD pipelinesGitHub Actions + GitLab CI YAML templates
Automated PR commentsFairnessReportCard
pytest pluginpytest11 entry point + markers + fixtures
Intersectional gate checkingevaluate_hierarchical() + HierarchicalGateConfig
Per-intersection thresholdsHierarchicalGateConfig.per_intersection_thresholds
Small-sample warningsSmallSampleWarning