LeakLens
Catch data leakage before it fools you. Most "99% accuracy" models are leaking. LeakLens audits both your data and your code, then proves what survives by training three model families on a leak-free pipeline.
What it catches
| Where | Leak |
|---|---|
| Data | Target leakage (a single feature that almost perfectly predicts the label), ID-like columns, train/test row overlap, temporal leakage, entity/group overlap (--group COL) |
Code (.py, .ipynb) |
Scaler/encoder/imputer fitted before the split, SMOTE before the split, transformers fitted on test/validation data or on the full dataset after the split, chained calls like StandardScaler().fit_transform(X), preprocessing or resampling done before cross_val_score / GridSearchCV (preprocess_outside_cv) |
Every audit returns a 0-100 trust score. The CLI exits with code 1 on a high-severity leak, so it gates CI.
Demo
$ leaklens demo.csv --target is_fraud --arena LeakLens trust score: 50/100 [HIGH] target_leakage :: chargeback_flag :: alone predicts target (roc_auc=1.000) [MEDIUM] id_like :: txn_id :: 100.0% unique values; likely an identifier
Arena ranked by pr_auc (auto-dropped: chargeback_flag, txn_id) model roc_auc pr_auc best_f1 neural_net 0.8374 0.4219 0.4353 linear 0.8410 0.4215 0.4304 tree_ensemble 0.8242 0.3562 0.4103
A leaked column makes accuracy look perfect. LeakLens drops it and shows the honest numbers.
Install
pip install leaklens-ml
Quick start
pip install -e ".[dev,app]" leaklens train.csv --target label --test test.csv --time date leaklens --scan notebooks/ --explain # prints a suggested fix under each finding leaklens --scan . --sarif leaklens.sarif # for GitHub code scanning leaklens train.csv --target label --test test.csv --group patient_id leaklens train.parquet --target label --fail-under 80 # Parquet input (pip install leaklens-ml[parquet]); CI gate on trust score leaklens train.json --target label # JSON input, no extra needed leaklens train.xlsx --target label # Excel input (pip install leaklens-ml[excel]) leaklens train.feather --target label # Feather input (pip install leaklens-ml[feather]) python examples/make_demo.py leaklens demo.csv --target is_fraud --arena mlflow ui --backend-store-uri sqlite:///mlflow.db
New to data leakage? Start with the walkthrough notebook: three planted leaks, an inflated score, and how LeakLens finds and fixes them.
Optional LLM explanations
LLM explanations are disabled unless you pass --llm. LeakLens sends the selected findings' severity, kind, file name and line, and diagnostic detail; details can include short code expressions from scanned files. It does not send complete source files, notebooks, or dataset rows. The default provider is local Ollama. If you choose --llm-provider openai-compatible or configure a remote base URL, these finding details are sent to that host. Provider URLs must use HTTP or HTTPS, redirects are refused, and an API key is not sent over plain HTTP except to localhost or 127.0.0.1. Explanations are limited to the 10 highest-severity findings by default; use --llm-max-findings N to change that limit.
ollama pull qwen2.5:7b
leaklens --scan notebooks/ --llm
To use an OpenAI-compatible API, configure its endpoint and key. The request leaves your machine:
export LEAKLENS_LLM_BASE_URL=https://api.example.com/v1
export LEAKLENS_LLM_API_KEY=...
export LEAKLENS_LLM_MODEL=your-model
leaklens --scan notebooks/ --llm --llm-provider openai-compatible
You can also pass --llm-base-url and --llm-model on the command line. The API key is read only from LEAKLENS_LLM_API_KEY.
Model arena
Auto-drops leaking and ID columns, then trains linear, gradient-boosted tree and neural-net models inside leak-safe pipelines (imputation, scaling and encoding are fitted on training data only). Runs are tracked in local MLflow (SQLite) and the winner is saved to models/best.joblib. Add --time COL for a temporal split.
API and UI
uvicorn leaklens.api:app --port 8000 # docs at /docs streamlit run leaklens/ui.py
Endpoints: GET /health, POST /audit, POST /scan, POST /predict.
Docker
docker compose up --build
API on http://localhost:8000/docs, UI on http://localhost:8501.
GitHub Action
- uses: actions/checkout@v4
- uses: eyadstein/leaklens@main
with:
path: notebooks
HTML report
leaklens demo.csv --target is_fraud --arena --html report.html
A single self-contained file with the trust score, findings and arena table. Easy to attach to a PR or share with your team.
GitHub code scanning
permissions:
security-events: write
steps:
- uses: actions/checkout@v4
- run: pip install leaklens-ml
- run: leaklens --scan . --sarif leaklens.sarif || true
- uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: leaklens.sarif
Findings then appear in the repository's Security tab and as PR annotations.
Pre-commit hook
repos:
- repo: https://github.com/eyadstein/leaklens
rev: main
hooks:
- id: leaklens
Blocks a commit when a notebook or script fits a transformer before the split.
Trust score badge
leaklens --scan . --badge badge.json
Commit badge.json, then point a shields.io endpoint badge at its raw URL (as at the top of this file).
Architecture
flowchart LR
A[CSV / notebooks] --> B[Data audit + leakage detectors]
A --> C[Static code scanner]
B --> D[Trust score]
C --> D
B --> E[Model arena + MLflow]
E --> F[best.joblib]
F --> G[FastAPI /predict]
D --> H[CLI / Streamlit / GitHub Action]
How the Trust Score Is Calculated
LeakLens starts with a trust score of 100 and deducts points for each finding based on its severity.
| Severity | Penalty |
|---|---|
| High | 35 points |
| Medium | 15 points |
| Low | 5 points |
The final score is calculated by subtracting the total penalties from 100. The score cannot fall below 0.
Example: If a dataset has one high-severity finding, one medium-severity finding, and one low-severity finding, the total penalty is 35 + 15 + 5 = 55. The final trust score is 100 − 55 = 45/100.
Roadmap
Full plan with phases and exit criteria: ROADMAP.md. Open tasks are in Issues.
- Core detectors, static scanner, model arena, API, UI
- Docker, GitHub Action, badge, CI
- Group/entity leakage detector
- PyPI packaging + release workflow (PyPI name
leaklens-ml, command staysleaklens; create a GitHub release to publish)
Leakage study
In a non-random sample of 1,725 public notebooks that split their data, 38% fit a preprocessing step before the split or on test data (static heuristic, not a verdict on any notebook). Details and caveats: docs/STUDY.md. Reproduce it with python scripts/study.py (needs the gh CLI).
Validated on real notebooks
Five public notebooks were read by hand against the scanner output. Details, counts and limits are in docs/VALIDATION.md. The sample is tiny, so treat it as a sanity check.
Accuracy and security
The code scanner is checked against a labeled regression benchmark on every CI run (python -m leaklens.bench, results in docs/BENCHMARK.md). It is small and hand-written, so treat it as a regression guard, not a real-world accuracy claim. Report vulnerabilities as described in SECURITY.md.
Contributing
See CONTRIBUTING.md. Starter tasks are labeled good first issue.
Contributors
Thanks to @jay23606 (Parquet input), @slopggobblercobbler81 (--fail-under), @tyza66 (Excel, JSON and Feather input), @rahul05ranjan (random_state reproducibility check), @have-you-tried-restarting (severity summary), @Rashmi-R444 (trust score docs), @Thecoolss (benchmark snippets), @ElDShell (Arabic README), @Aaqibhafeezkhan (colored severity labels and CITATION.cff), @Cami0111 (leak walkthrough notebook) and @rahul-jain-dev (--version), @Vamsi-2581 (Add opt-in LLM explanations for findings).
MIT licensed.
Metadata
Release files for leaklens-ml 0.12.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| leaklens_ml-0.12.0.tar.gz | 44.7 kB | With provenance | Details for leaklens_ml-0.12.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| leaklens_ml-0.12.0-py3-none-any.whl | Python 3 | none | any | Details for leaklens_ml-0.12.0-py3-none-any.whl |
Total release size: 80.8 kB
Release files / leaklens_ml-0.12.0.tar.gz
| Download URL | leaklens_ml-0.12.0.tar.gz |
|---|---|
| Size | 44.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
87ffa24f0e7f5f34187b8187826a1362f02f10bc64fb4e4130d9ebca961a6f74
|
|
BLAKE2b-256 checksum How to use checksums |
124cfb07c65220546e8c9cdc22d8ea4ce76e630057dc46e3afaa0f479daeb579
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / leaklens_ml-0.12.0-py3-none-any.whl
| Download URL | leaklens_ml-0.12.0-py3-none-any.whl |
|---|---|
| Size | 36.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9b6e5fb1c472bd407f113b1552899757c2ea8c8959e27a11b74d193c991bc336
|
|
BLAKE2b-256 checksum How to use checksums |
720096f37dfacfd9552fe5ee35a8513d373296ae0a55e70dc8fedcd13a20cbca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logSecurity for leaklens-ml 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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for leaklens_ml-0.12.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logA 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.