Skip to main content

fairpipe

Fairness measurement, mitigation, monitoring, and pipeline tooling for ML workflows.
PyPI package: fairpipe · License: Apache-2.0 · Python 3.10+

Upgrading from 0.11: this release includes breaking behaviour changes (default backend, optional MLflow, equalized-odds undefined strata, CI overhaul, LLM metric rename). Read Upgrade notes in the CHANGELOG before upgrading.

Fairlearn AIF360 fairpipe
Metrics library ✅ ✅ ✅
Mitigation algorithms ✅ ✅ ✅
DataFrame I/O ✅ ✅ ✅
Parquet I/O ❌ ❌ ✅
Orchestrated end-to-end pipeline ⚠️ Partial ⚠️ Partial ✅
CI/CD integration ❌ ❌ ✅
GitHub Action ❌ ❌ ✅
Production monitoring ❌ ❌ ✅
REST API ❌ ❌ ✅
LLM / GenAI fairness evals ❌ ❌ ✅

Fairlearn and AIF360 provide individual pre/in/post-processing components; fairpipe provides a YAML-configured baseline→transform→validate workflow with CI/CD exit codes.

PyPI version Python versions Coverage Launch in Binder


Install

pip install fairpipe

Optional extras: pip install 'fairpipe[api]' · 'fairpipe[training]' · 'fairpipe[monitoring]' · 'fairpipe[adapters]' · 'fairpipe[llm]' · 'fairpipe[tracking]'
(REST API, PyTorch training helpers, dashboards/drift, Fairlearn/Aequitas backends, LLM provider SDKs, MLflow tracking.) Full detail is in the documentation below—not duplicated here.


Setting LLM provider credentials

LLM fairness evaluation (see fairpipe.llm_evals) uses provider SDKs installed via the optional extra:

pip install 'fairpipe[llm]'

Credentials are read from environment variables only — never from YAML config files or CLI flags:

Provider Environment variable Notes
OpenAI (and OpenAI-compatible APIs) OPENAI_API_KEY Required for provider: openai
Anthropic ANTHROPIC_API_KEY Required for provider: anthropic
Local / self-hosted (none) provider: local needs no API key

Toxicity/sentiment disparity uses a lexical scorer by default (no moderation API key). Plug in an external scorer via ToxicitySentimentEvaluator.run_async(scorer=...).

Example:

export OPENAI_API_KEY="sk-..."
# or
export ANTHROPIC_API_KEY="..."

When using the CLI, run fairpipe llm-eval --dry-run to estimate request volume and approximate cost before making live provider calls. Live HTTP is forbidden by default; set FAIRPIPE_LLM_ALLOW_LIVE=1 on CLI, REST, Jupyter, or CI jobs that should call a provider (same flag — see Environment Variables). Replay-from-cache_dir does not need it.

fairpipe llm-eval --config llm_eval.yml --dry-run
fairpipe llm-eval --config llm_eval.yml --report-md artifacts/llm_report.md --with-ci
fairpipe llm-eval --config llm_eval.yml --metric demographic_swap_divergence --threshold 0.25

See docs/llm_evals_intro.md for configuration, REST POST /llm-eval, and sampling production logs into the existing tracker.


Documentation

Start here (hosted): Documentation — SvrusIO.github.io/fAIr
Built from this repo’s Sphinx sources; includes getting started, user guide, API reference, integration, performance, and security links.

In-repo references (absolute links so they resolve on PyPI as well as GitHub):

Topic Location
LLM fairness evals docs/llm_evals_intro.md
Getting started docs/getting_started.md
User guide (long-form) DOCS.md
API reference docs/api.md
Playbook · fairpipe (as implemented) docs/playbook-part-five-fairpipe.md
Integration guide docs/integration_guide.md
Architecture / ADR docs/ADR-001-architecture.md
Versioning docs/VERSIONING.md
Package / import identity docs/identity.md
Changelog CHANGELOG.md

Quick start

Python (self-contained — each group clears the default min_group_size=30)

import numpy as np
from fairpipe.metrics import FairnessAnalyzer

rng = np.random.default_rng(0)
n = 40
y_pred = np.concatenate([rng.integers(0, 2, n), rng.integers(0, 2, n)])
sensitive = np.array(["F"] * n + ["M"] * n)

analyzer = FairnessAnalyzer(min_group_size=30)
result = analyzer.demographic_parity_difference(
    y_pred=y_pred,
    sensitive=sensitive,
    with_ci=True,
)
print(result.value, result.ci, result.n_per_group)

Groups smaller than min_group_size are excluded and the metric is nan until they clear the guard — that is the intended behaviour, not a bug. See getting started.

CLI (--metric is required whenever --threshold is set)

# Write a small sample CSV, then validate
python - <<'PY'
import pandas as pd
pd.DataFrame({
    "y_true": [0, 1] * 40,
    "y_pred": [0, 1, 1, 0] * 20,
    "gender": ["F"] * 40 + ["M"] * 40,
}).to_csv("data.csv", index=False)
PY

fairpipe validate \
  --csv data.csv \
  --y-true y_true \
  --y-pred y_pred \
  --sensitive gender \
  --metric demographic_parity_difference \
  --threshold 0.05 \
  --with-ci

# Full workflow needs a pipeline YAML (see docs); not a one-liner:
# fairpipe run-pipeline --config config.yml --csv data.csv --output-dir artifacts/

CLI commands, YAML configuration, workflow orchestration, training, monitoring, and the optional REST API are documented on the docs site and in docs/api.md.


CI/CD Integration

Add fairness validation to every pull request with the companion GitHub Action:

# .github/workflows/fairness-check.yml
name: Fairness Check
on: [pull_request]

jobs:
  fairness:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: SvrusIO/fairpipe-action@v2
        with:
          csv: data/predictions.csv
          y-true: y_true
          y-pred: y_pred
          sensitive: gender
          threshold: "0.05"
          metric: "equalized_odds_difference"
          fail-on-violation: "true"

Point csv at your predictions file. If equalized odds difference exceeds 0.05, the PR is blocked. A full fairness report is written to the Actions job summary — metric values, confidence intervals, group breakdowns — permanently attached to the commit.

Gate LLM fairness evals the same way. Live provider HTTP is forbidden by default (LiveLLMCallForbidden); a job that should call a provider must set FAIRPIPE_LLM_ALLOW_LIVE=1 — that is the correct safe default, not a workaround. Replay-from-cache_dir jobs do not need the flag.

# .github/workflows/llm-fairness-check.yml
name: LLM Fairness Check
on: [pull_request]

jobs:
  llm-fairness:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: SvrusIO/fairpipe-action@v2
        env:
          FAIRPIPE_LLM_ALLOW_LIVE: "1"
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        with:
          config: llm_eval.yml
          metric: "refusal_rate_disparity"
          threshold: "0.25"
          fail-on-violation: "true"

A red check can be decoded without opening the report:

Exit gate_status Meaning
0 pass Threshold met (or no threshold) on a finite non-caveated metric
1 fail Threshold miss on a non-caveated gated metric
2 (usage) --threshold without --metric, unknown metric, cache miss / live-forbidden
3 illustrative Gated metric has a non-null caveat — even if the number would pass
4 undefined Gated metric is non-finite (insufficient evidence; typically min_group_size)

fairpipe validate uses only exits 0/1/2 — exit 4 is reserved for LLM-eval undefined and does not collide.

The example gates refusal_rate_disparity so exit 3 is reachable when the gated metric is caveated (refusal / toxicity / stereotype / divergence all call with_fixture_caveat as of 0.11.0). llm-fairness-check mode ships in SvrusIO/fairpipe-action@v2 (BL-010 closed). This package exposes the same with: keys via fairpipe llm-eval --threshold / --metric and run_llm_fairness_check().

→ SvrusIO/fairpipe-action


Development

git clone https://github.com/SvrusIO/fAIr.git
cd fAIr
pip install -e ".[dev]"
pytest -q

See CONTRIBUTING.md and SECURITY.md.


Case Studies

Real-world bias audits demonstrating fairpipe's full pipeline — from measurement and detection through mitigation and CI/CD integration.

What goes wrong when measuring LLM fairness

Two measurement failures on committed live-recorded Anthropic responses replayed from cache (no API key required). Select kernel Python (fairpipe .venv) if imports fail.

  • §1 — A single-name-per-group counterfactual manufactured a clean 0.333 gender disparity that was a David vs Tariq name effect. Rotation (name_pools) is the default because of that.
  • §2 — demographic_swap_divergence is a lexical-divergence perturbation test (not Kusner et al. causal CF). It has a no-effect baseline of ~0.19, not 0 (token overlap ~90% of the score). A CI excluding 0 is not a group effect; hiring is 0.196 − 0.190 ≈ 0.006 (BL-012).
  • §3 — Pipeline demonstration on real output, not a fairness finding: n=1/group (third arm nonbinary) → nan at min_group_size=5; n=9/group → finite lexical divergence ≈ 0.196 (default CI undefined — no calibrated interval for this metric yet, see #63; opt in with ci_method="template_bonferroni_t").
  • §4 — One model, one temperature, two domains; BL-011 refusal ceiling; hiring's third group is the prompt token nonbinary, not name-ambiguity.
  • YAML config → run_llm_eval() → MetricResult (see docs/llm_evals_intro.md). Phase 2 toxicity demo cache is labeled via MetricResult.caveat; stereotype_association_score is always experimental (#31) — neither is part of this notebook. Humanitarian refusal is a separate fixture.

COMPAS Recidivism Bias Analysis

Reproduces ProPublica's 2016 Machine Bias investigation on the COMPAS recidivism algorithm used in US courtrooms.

  • DPD = 0.2451 — Black defendants 24.5 percentage points more likely to be flagged high-risk than white defendants
  • EOD = 0.2116 — among defendants who will not reoffend, Black defendants are 21 percentage points more likely to be incorrectly labelled high-risk
  • 53.9% reduction in EOD after a workflow that includes group-frequency InstanceReweighting plus reductions training (not Kamiran–Calders group-label reweighing — see docs)
  • 28 features with statistically significant racial disparities detected
  • 23 proxy variables identified — removing the race column alone would not fix this model

Launch in Binder Open in Colab

AI Hiring Bias — ACS Employment Analysis

Demonstrates the type of bias audit now required under NYC Local Law 144 and the EU AI Act, framed around Mobley v. Workday — the 2025 class action alleging AI hiring tools discriminated against millions of applicants by age, race, and disability.

  • DPD = 0.1046 — white candidates selected at 32.3% vs Black candidates at 21.8%, a 10.5 percentage point gap with no race feature in the model
  • EOD = 0.1022 — 76.8% of qualified Black candidates incorrectly rejected vs 66.6% of white candidates
  • All 5 prediction features show statistically significant racial disparity — removing the race column alone would not fix this model
  • 47.6% reduction in EOD after a workflow that includes group-frequency InstanceReweighting plus reductions training, closing to within 0.0036 of a 0.05 analysis threshold chosen for this notebook (not a legal cutoff)
  • Dataset: ACS 2018 1-Year California (196,604 individuals, folktables)

Launch in Binder Open in Colab


Homepage / docs SvrusIO.github.io/fAIr
Repository github.com/SvrusIO/fAIr
Issues github.com/SvrusIO/fAIr/issues

License

Apache License 2.0 — see LICENSE.

Metadata

Release files for fairpipe 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fairpipe 0.12.0
File Size Uploaded Provenance Actions
fairpipe-0.12.0.tar.gz 249.7 kB Without provenance Details for fairpipe-0.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fairpipe 0.12.0
File Interpreter ABI Platform Actions
fairpipe-0.12.0-py3-none-any.whl Python 3 none any Details for fairpipe-0.12.0-py3-none-any.whl

Total release size: 616.0 kB

Release files / fairpipe-0.12.0.tar.gz

Download URL fairpipe-0.12.0.tar.gz
Size 249.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6609a35fc4b57d9949dddfda5c893307417e40a82d0c1238550733f797b5d11e
BLAKE2b-256 checksum
How to use checksums
4e65f54a2b42a349a1656dadc51e4b1de8a8194a1c21de52085ec7b8aa5e9c66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / fairpipe-0.12.0-py3-none-any.whl

Download URL fairpipe-0.12.0-py3-none-any.whl
Size 366.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86dbe49276e95ffbd4586efa93517bac1a9bfd539c55c1f7a382804dad239ccb
BLAKE2b-256 checksum
How to use checksums
081723931ccc02808f56ae5530acb0111cca4b0af0e94b243393b8efe1021f2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for fairpipe 0.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page