Skip to main content

AI Bias Detection and Ethics Compliance Agent

Project description

Veritas - AI Bias Detection and Ethics Compliance

A Python package for detecting bias in ML models and checking compliance with AI ethics laws using RAG-powered recommendations.

PyPI Python

Features

  • Automatic bias detection using IBM AIF360 toolkit
  • AI ethics compliance checking via LangGraph ReAct agent
  • RAG-powered law lookup from bundled AI ethics knowledge base
  • sklearn-compatible wrappers for drop-in integration
  • Auto-initialization - knowledge base ingests automatically on first import

Installation

# From PyPI
pip install veritas-ml

# From source
pip install -e .

# Set API key for LLM provider
export OPENROUTER_API_KEY="your-key-here"
# OR
export GROQ_API_KEY="your-key-here"

Quick Start

Create bias_params.json beside your main Python file, or in the directory where you run Python:

{
  "protected_attributes": ["gender"]
}

Veritas will read this automatically, so your application code does not need to repeat sensitive/protected attribute names.

Pattern 1: Drop-in sklearn Replacement

from veritas import VeritasClassifier
from sklearn.linear_model import LogisticRegression

# Wrap any sklearn classifier
clf = VeritasClassifier(
    base_estimator=LogisticRegression(),
    run_audit=True,
    generate_report=True
)

# Fit with sensitive features
clf.fit(X_train, y_train, sensitive_features=sensitive_train)

# Get reports
print(clf.get_bias_report())         # AIF360 metrics
print(clf.get_compliance_report())   # Mitigation recommendations

Pattern 2: Manual Audit After Training

from veritas import BiasDetector, ComplianceChecker

# Train your model normally
model.fit(X_train, y_train)

# Audit separately
detector = BiasDetector()
bias_report = detector.audit(model, X_test, y_test, sensitive_test)

# Check compliance
checker = ComplianceChecker()
compliance_report = checker.check(bias_report)

Pattern 3: Full End-to-End Audit

from veritas import ComplianceChecker

checker = ComplianceChecker()
result = checker.full_audit(
    X_train=X_train, y_train=y_train,
    X_test=X_test, y_test=y_test,
    sensitive_train=sensitive_train,
    sensitive_test=sensitive_test,
)

print(result["compliance_report"])

Publishing to PyPI

This section documents how to release new versions of veritas-ml to the Python Package Index.

Prerequisites

  1. PyPI Account: Create an account at https://pypi.org/
  2. API Token: Generate at https://pypi.org/manage/account/#api-tokens
  3. Token Access: Ensure token has scope for veritas-ml project

Set Up Your Token

Add to veritas/.env:

PYPI_API_TOKEN=pypi-AgEIcHlwaS5vcmcC...

Or set environment variable:

export PYPI_API_TOKEN="your-token-here"

Using the Upload Script (Recommended)

# Navigate to veritas directory
cd veritas

# Option 1: Test first, then live (recommended)
python scripts/upload_pypi.py --test

# Option 2: Direct live upload
python scripts/upload_pypi.py

# Option 3: Build only (for verification)
python scripts/upload_pypi.py --build

Manual Upload (Alternative)

# Install build tools
pip install build twine

# Clean previous builds
rm -rf dist/ build/ src/*egg-info/

# Build
python -m build

# Upload to TestPyPI first (recommended)
twine upload --repository testppi dist/*
# Verify: https://test.pypi.org/project/veritas-ml/
# Install: pip install --index-url https://test.pypi.org/simple veritas-ml

# Upload to live PyPI
twine upload --repository pypi dist/*

Version Bumping

Before uploading, increment version in pyproject.toml:

[project]
version = "0.1.1"  # Increment as needed

Troubleshooting

Error Solution
name too similar Change package name in pyproject.toml
403 Forbidden Check API token permissions
[mutex.cc : 452] TensorFlow and PyArrow are included by default (see Dependencies)

Dependencies

LLM Providers

Veritas loads settings in this order:

  1. Explicit constructor overrides (e.g. ComplianceChecker(llm_provider="groq"))
  2. Environment variables (auto-loaded from veritas/.env)
  3. defaults.json (veritas/defaults.json or repository-root defaults.json)
  4. ~/.veritas/config.json

Environment variables:

# OpenRouter
export LLM_PROVIDER=openrouter
export OPENROUTER_API_KEY=your-key

# Ollama (local)
export LLM_PROVIDER=ollama
export OLLAMA_BASE_URL=http://localhost:11434

# Groq
export LLM_PROVIDER=groq
export GROQ_API_KEY=your-key

Or set defaults.json:

{
  "provider": "ollama",
  "llm": "qwen3.5:4b"
}

You can still use ~/.veritas/config.json:

{
  "provider": "openrouter",
  "llm": "openai/gpt-4o-mini"
}

Knowledge Base

The AI ethics knowledge base auto-initializes on first import at ~/.veritas/vector_store/.

API Reference

VeritasClassifier

sklearn-compatible wrapper with built-in bias auditing.

Parameters:

  • base_estimator: sklearn estimator (default: LogisticRegression)
  • protected_attribute: Name of protected attribute
  • privileged_classes: Privileged class values
  • run_audit: Run bias audit on fit()
  • generate_report: Generate compliance report

Methods:

  • fit(X, y, sensitive_features=None) - Train and audit
  • predict(X) - Predict labels
  • get_bias_report() - Get AIF360 metrics
  • get_compliance_report() - Get mitigation recommendations
  • has_bias() - Check if bias detected

BiasDetector

Low-level bias detection with AIF360.

Methods:

  • audit(model, X_test, y_test, sensitive_features) - Run audit

ComplianceChecker

High-level compliance checking with LLM agent.

Methods:

  • check(bias_report) - Analyze bias report
  • full_audit(...) - End-to-end training + audit + compliance

Dependencies

  • aif360 >= 0.6.1
  • langgraph >= 0.3.0
  • langchain-* providers
  • chromadb >= 0.5.0
  • scikit-learn >= 1.3.0

License

MIT

Project details


Download files

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

Source Distribution

veritas_ml-0.1.8.tar.gz (412.4 kB view details)

Uploaded Source

Built Distribution

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

veritas_ml-0.1.8-py3-none-any.whl (415.8 kB view details)

Uploaded Python 3

File details

Details for the file veritas_ml-0.1.8.tar.gz.

File metadata

  • Download URL: veritas_ml-0.1.8.tar.gz
  • Upload date:
  • Size: 412.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for veritas_ml-0.1.8.tar.gz
Algorithm Hash digest
SHA256 5de30266b9eaf89a2c10e949cadad4826436ee46e72d07f77e8fdb5fc313c771
MD5 b0731939e604c2aeaa64f4e122d41fdb
BLAKE2b-256 f270a8a1ba5f3cd956f590d00297b85de90f2bed504c2ce2cc04c999293b42e2

See more details on using hashes here.

File details

Details for the file veritas_ml-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: veritas_ml-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 415.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for veritas_ml-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 6441599355639dd05073a873ace88f737db0a91749d83b33f9a4c015210d0c2a
MD5 4646359434d53ba47b969a22243c52ca
BLAKE2b-256 42277cfa7bcf3a2f32ca327c9d7d4b55a631ed589e9e948b87e58fdc9a87eeb4

See more details on using hashes here.

Supported by

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