๐ก Abstract (Executive Summary)
The Problem: When Machine Learning models are trained on private data (like medical records, financial transactions, or customer emails), they can accidentally memorize that sensitive information. Attackers can then extract private data or determine if a specific person's record was in the training set.
The Solution:
privacylensis an open-source privacy auditing toolkit. In 3 lines of code, it runs 5 automated security checks against any ML model (scikit-learn, PyTorch, XGBoost, HuggingFace) to detect data leakage risks before deployment.Why it matters:
- ๐งโ๐ป For Developers: Catch privacy bugs automatically in CI/CD pipelines before pushing models to production.
- ๐ข For Enterprises: Generate standalone interactive HTML compliance reports for GDPR and HIPAA audits.
๐ฏ What is privacylens?
Most ML engineers don't know if their model is leaking private training data. privacylens audits it across 5 core privacy vulnerability vectors.
from privacylens import audit
report = audit(model, X_train, y_train, X_test)
report.summary()
# Export HTML Compliance Report for GDPR/HIPAA sharing
report.to_html("audit_report.html")
+-------------------------------------------------------------------+
| privacylens โ 5-Point Privacy Audit Report |
+------------------------------------+--------------+---------------+
| Check | Score | Risk |
+------------------------------------+--------------+---------------+
| Membership Inference Attack | 0.087 | LOW |
| PII Leakage Detection | 0.000 | LOW |
| Model Inversion Risk | 0.042 | LOW |
| Attribute Inference Risk | 0.015 | LOW |
| Differential Privacy (ฮต) | 0.038 | LOW |
+------------------------------------+--------------+---------------+
Model: RandomForestClassifier
Overall Risk: LOW
โข MIA advantage score: 0.087 โ model shows low Membership Inference vulnerability.
โข PII leakage score: 0.000 โ model shows low PII Leakage vulnerability.
โข Model Inversion score: 0.042 โ model shows low Model Inversion vulnerability.
โข Attribute Inference score: 0.015 โ model shows low Attribute Inference vulnerability.
โข Differential Privacy score: 0.038 โ model shows low Differential Privacy vulnerability.
โจ 5-Point Privacy Audit Suite
- ๐ต๏ธ 1. Membership Inference Attack (MIA) โ Detect if an attacker can identify training records using shadow model estimation (Shokri et al., 2017)
- ๐ 2. PII Leakage Detection โ Scan predictions and samples for memorized PII (Emails, SSNs, Credit Cards, Phones, IPs)
- ๐ 3. Model Inversion Risk Scorer โ Evaluate feature reconstructability risk from confidence probabilities (Fredrikson et al., 2015)
- ๐ฏ 4. Attribute Inference Attack โ Measure sensitive secondary attribute predictability from confidence vectors (Yeom et al., 2018)
- ๐ก๏ธ 5. Differential Privacy (ฮต) Estimator โ Estimate empirical privacy loss ($\epsilon$) under single-record modifications (Jagielski et al., 2020)
- โก Azure Machine Learning Integration โ Plug-and-play step (
AzureMLAuditStep) to enforce privacy audit gates inside Azure ML Pipelines - ๐ค Azure OpenAI Service Auditor โ Evaluate fine-tuned Azure OpenAI deployments (
gpt-4,gpt-35-turbo) for prompt injection PII leakage - ๐ Native Framework Adapters โ Out-of-the-box support for scikit-learn, PyTorch (
nn.Module), XGBoost, and HuggingFace Transformers - ๐ HTML Compliance Reports โ Export standalone, interactive HTML reports (
--report audit.html) for security & GDPR/HIPAA compliance sharing - ๐ค CLI + Python API โ Use in scripts or integrate into CI/CD pipelines (
privacylens audit) - ๐ JSON output โ Machine-readable results for dashboards and reporting (
--output json)
๐ฆ Installation
# Base install (scikit-learn models)
pip install privacyaudit
# With Azure Machine Learning & Azure OpenAI support
pip install "privacyaudit[azure]"
# With PyTorch support
pip install "privacyaudit[torch]"
# With XGBoost support
pip install "privacyaudit[xgboost]"
# Everything (Azure ML, PyTorch, XGBoost, Transformers)
pip install "privacyaudit[all]"
Note: The PyPI package is
privacyaudit. Import in Python asfrom privacylens import audit.
๐ Quick Start
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from privacylens import audit
# Train a model
X, y = make_classification(n_samples=1000, n_features=20, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
model = RandomForestClassifier(n_estimators=100)
model.fit(X_train, y_train)
# Audit it for all 5 privacy vulnerabilities
report = audit(model, X_train, y_train, X_test, y_test)
report.summary()
# Export interactive HTML audit report
report.to_html("compliance_report.html")
# Get audit results as dict (for JSON logging or API responses)
print(report.to_dict())
๐ฅ๏ธ CLI Usage
# Audit a saved model file
privacylens audit model.pkl train.csv test.csv
# Export interactive HTML report
privacylens audit model.pkl train.csv test.csv --report compliance.html
# Output JSON for CI/CD integration
privacylens audit model.pkl train.csv test.csv --output json
# Skip MIA check in fast pipelines
privacylens audit model.pkl train.csv test.csv --no-mia
๐๏ธ Architecture
privacylens/
โโโ src/privacylens/
โ โโโ __init__.py # Public API: audit(), AuditReport, Auditors, Adapters
โ โโโ auditor.py # Core 5-point orchestrator
โ โโโ adapters/
โ โ โโโ base.py # BaseModelAdapter & get_adapter() factory
โ โ โโโ sklearn_adapter.py
โ โ โโโ pytorch_adapter.py
โ โ โโโ xgboost_adapter.py
โ โ โโโ hf_adapter.py # HuggingFace Transformers Adapter
โ โโโ attacks/
โ โ โโโ membership.py # MIA engine (Shokri et al.)
โ โ โโโ inversion.py # Model Inversion Risk Auditor (Fredrikson et al.)
โ โ โโโ attribute.py # Attribute Inference Auditor (Yeom et al.)
โ โโโ leakage/
โ โ โโโ pii.py # PII Leakage Auditor (Regex + Severity Weighting)
โ โ โโโ dp.py # Empirical Differential Privacy Epsilon Estimator
โ โโโ report/
โ โ โโโ html.py # HTML Compliance Report Generator (Jinja2)
โ โโโ cli.py # Click CLI
โโโ examples/
โ โโโ benchmark_demo.py # Enterprise Privacy Audit Benchmark
โโโ tests/
โโโ test_auditor.py
โโโ test_membership.py
โโโ test_pii_leakage.py
โโโ test_inversion.py
โโโ test_adapters.py
โโโ test_html_report.py
โโโ test_hf_adapter.py
โโโ test_5point_audits.py
๐ Risk Score Interpretation
| Check Score | Risk Level | Meaning |
|---|---|---|
0.0 โ 0.10 |
๐ข LOW | Model reveals minimal membership/PII/inversion information |
0.10 โ 0.30 |
๐ก MEDIUM | Moderate risk โ review training data exposure |
0.30 โ 1.00 |
๐ด HIGH | Model likely memorising sensitive training data |
๐ค Contributing
See CONTRIBUTING.md. All contributions welcome!
๐ License
MIT โ see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file privacyaudit-1.1.0.tar.gz.
File metadata
- Download URL: privacyaudit-1.1.0.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba4ac11abc2f2ec415dff79d0ad259ef7c5e22c3abe3bcc6fbf3e40db82f0d62
|
|
| MD5 |
34bb85d09fdbc7b36315287dcf8b9bd0
|
|
| BLAKE2b-256 |
68549a772bd3aafcab57f44a260d321b27bdbf89f080145ef504463127d5d793
|
Provenance
The following attestation bundles were made for privacyaudit-1.1.0.tar.gz:
Publisher:
release.yml on nithin42/privacylens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
privacyaudit-1.1.0.tar.gz -
Subject digest:
ba4ac11abc2f2ec415dff79d0ad259ef7c5e22c3abe3bcc6fbf3e40db82f0d62 - Sigstore transparency entry: 2348295181
- Sigstore integration time:
-
Permalink:
nithin42/privacylens@8b6297162f18bcdcbd836f46e3b44050d42759cb -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/nithin42
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8b6297162f18bcdcbd836f46e3b44050d42759cb -
Trigger Event:
push
-
Statement type:
File details
Details for the file privacyaudit-1.1.0-py3-none-any.whl.
File metadata
- Download URL: privacyaudit-1.1.0-py3-none-any.whl
- Upload date:
- Size: 29.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81ee17aef2f812e7b6946e41e81d7640cdf684baa1f3e7e140400ed02197d412
|
|
| MD5 |
53eddd816e01a8c1b194d6e498585f38
|
|
| BLAKE2b-256 |
45d7d4de9621bffeee903eb6e15428c92856caee265b193300b798644407b8eb
|
Provenance
The following attestation bundles were made for privacyaudit-1.1.0-py3-none-any.whl:
Publisher:
release.yml on nithin42/privacylens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
privacyaudit-1.1.0-py3-none-any.whl -
Subject digest:
81ee17aef2f812e7b6946e41e81d7640cdf684baa1f3e7e140400ed02197d412 - Sigstore transparency entry: 2348295227
- Sigstore integration time:
-
Permalink:
nithin42/privacylens@8b6297162f18bcdcbd836f46e3b44050d42759cb -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/nithin42
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8b6297162f18bcdcbd836f46e3b44050d42759cb -
Trigger Event:
push
-
Statement type: