Skip to main content

xai-auditor

Quantitative Explainability Auditing and Model Risk Management for Machine Learning.

xai-auditor is an independent, production-grade Python library designed to audit the reliability, stability, fidelity, consistency, manipulation resistance, distributional drift, and operational coverage of post-hoc Explainable AI (XAI) pipelines such as SHAP and LIME.


Overview

In regulated and high-stakes machine learning applications, post-hoc explanations must be audited with the same mathematical rigor applied to model predictive accuracy. xai-auditor evaluates whether surrogate explainers produce faithful, robust, and dependable explanations across six core dimensions:

  1. Local Lipschitz Stability: Attribution invariance and rank preservation under small feature perturbations.
  2. Attribution Fidelity: Empirical causal validity measured via ROAR (Remove and Retain) and KAR (Keep and Retain) probability curves.
  3. Cross-Method Explainer Consistency: Consensus between SHAP and LIME evaluated via Top-K Jaccard overlap, Spearman rank correlation, Sign Agreement, Cosine Similarity, and Rank-Biased Overlap (RBO).
  4. Adversarial Manipulation Resistance: Robustness against explainer hyperparameter tuning (kernel widths, sampling budgets, background reference sets) measured by the Explanation Manipulation Index (EMI).
  5. Distributional Explanation Drift: Temporal and cohort attribution shift evaluated via Population Stability Index (PSI) and Wasserstein Distance.
  6. Operational Coverage & Latency: Service level agreement (SLA) verification evaluating explanation success rates and p50/p95/p99 execution latency.

Installation

pip install xai-auditor

Optional dependencies for deep integration with NumPy, Pandas, Scikit-Learn, SHAP, and LIME:

pip install xai-auditor[all]

Quickstart

from xai_auditor import Auditor
from xai_auditor.models.builtins import BuiltinLogisticRegression

# 1. Prepare data and model
# X can be a list of lists, a numpy array, or a pandas DataFrame
X = [
    [0.2, 1.1, 0.4, 0.9],
    [0.8, 0.3, 0.1, 0.2],
    [0.5, 0.9, 0.7, 0.6],
    [0.1, 0.2, 0.8, 0.4],
    [0.9, 1.4, 0.3, 0.8],
    [0.3, 0.5, 0.2, 0.1],
]
y = [1, 0, 1, 0, 1, 0]
feature_names = ["credit_utilization", "annual_income", "debt_ratio", "payment_history"]

model = BuiltinLogisticRegression(weights=[0.8, -0.6, 1.2, -0.9], bias=0.1)

# 2. Run the audit
auditor = Auditor(
    model=model,
    X=X,
    y=y,
    feature_names=feature_names,
)
result = auditor.run()

# 3. Inspect scores, risk tier, and metrics
print(f"Explainability Trust Score: {result.trust_score}/100")
print(f"Risk Classification Tier:   {result.risk_tier}")
print(f"Regulatory Approval Status: {result.approval_status}")

# 4. Access individual dimension scores
for dim, dim_result in result.dimension_results.items():
    print(f" - {dim_result.name}: {dim_result.score}/100 (Weight: {int(dim_result.weight * 100)}%)")

# 5. Export results to JSON or HTML
json_str = result.to_json(indent=2)
result.save_html_report("audit_report.html")

Auditing Individual Dimensions

Users can run individual audit dimensions independently without running the full suite:

from xai_auditor import (
    StabilityAuditor,
    FidelityAuditor,
    ConsistencyAuditor,
    ManipulationAuditor,
    DriftAuditor,
    CoverageAuditor,
)

# Example: Run only cross-method consistency (SHAP vs LIME)
consistency_auditor = ConsistencyAuditor(top_k=3, rbo_p=0.9)
res = consistency_auditor.audit(model=model, X=X, feature_names=feature_names)

print(f"Consistency Score: {res.score}/100")
print(f"Top-K Jaccard:    {res.metrics['top_k_jaccard']}")
print(f"Sign Agreement:   {res.metrics['sign_agreement']}")
print(f"Rank-Biased RBO:  {res.metrics['rank_biased_overlap']}")

Supported Models and Explainers

Models

  • Scikit-Learn classifiers implementing predict_proba
  • XGBoost, LightGBM, CatBoost binary classifiers
  • PyTorch / TensorFlow binary classification modules
  • Built-in standalone reference models (XGBoost emulation, Random Forest, Logistic Regression, Multilayer Perceptron)
  • Arbitrary Python prediction callables: f(X) -> probabilities

Explainers

  • SHAP: Permutation Shapley engine with efficiency constraint enforcement
  • LIME: Kernel-weighted local linear ridge surrogate with exponential distance weighting

Scoring and Risk Classification

The composite Explainability Trust Score (0-100) aggregates all six dimensions using established regulatory weights:

Audit Dimension Weight Primary Testing Objective
Attribution Fidelity (ROAR/KAR) 25% Causal accuracy of feature attribution under ablation
Local Lipschitz Stability 20% Invariance under input feature perturbation noise
Cross-Method Consistency 15% Multi-explainer consensus (SHAP vs LIME) including RBO
Manipulation Resistance 15% Robustness against hyperparameter cherry-picking (EMI)
Distributional Explanation Drift 15% Temporal attribution stability (PSI & Wasserstein)
Operational Coverage & Latency 10% Generation success rate and tail SLA execution latency

Risk Tiers

  • Low Risk (85 - 100): Approved for unconditional production deployment.
  • Medium Risk (75 - 84): Approved with standard governance telemetry.
  • High Risk (60 - 74): Conditional approval with mandatory secondary review.
  • Critical Risk (0 - 59): Deployment rejected; hard re-audit mandated.

Command-Line Interface (CLI)

xai-auditor provides a command-line tool xai-audit for batch auditing and continuous integration:

xai-audit --data data.csv --target is_default --model logistic_regression --output report.json --html report.html

License

Apache License 2.0.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xai_auditor-0.1.0.tar.gz (48.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xai_auditor-0.1.0-py3-none-any.whl (57.8 kB view details)

Uploaded Python 3

File details

Details for the file xai_auditor-0.1.0.tar.gz.

File metadata

  • Download URL: xai_auditor-0.1.0.tar.gz
  • Upload date:
  • Size: 48.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: xai-auditor-publisher/0.1.0

File hashes

Hashes for xai_auditor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 26e28c51ad87a72ac72face342ebc1b28f234d85582690fd519ce9bb750c9338
MD5 61245762413858c0a5215abe1e3f3a9a
BLAKE2b-256 9a162316e82c46e3621a9e897d8be759cc421bbcfd61dc349bab24ea188e5755

See more details on using hashes here.

File details

Details for the file xai_auditor-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: xai_auditor-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 57.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: xai-auditor-publisher/0.1.0

File hashes

Hashes for xai_auditor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9368db5c636bc65f7823b3d7d6cb33e640488feb211cd8f9db4310bc10242109
MD5 b5a96e2ac74425bda425fde902857d5c
BLAKE2b-256 358f5a4ce1eb94c192046f3ac24e29935c704a531d970019d014f67f77bf2dab

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page