Data leakage detection library and CLI for molecular machine learning.
LeakGuard is a Python package that checks for structural and fingerprint data leakage between training and testing splits in molecular datasets. It uses a Rust backend (via PyO3 and Rayon) to accelerate pairwise Tanimoto similarity calculations, and RDKit to handle SMILES canonicalization and Bemis-Murcko scaffolds.
Randomly splitting chemical datasets can lead to unintended memorization. LeakGuard scans for three common forms of data leakage:
- Exact SMILES Overlap: Checks for identical molecules in both train and test splits.
- Bemis-Murcko Scaffold Leakage: Checks if molecules in the test set share a core scaffold with the training set.
- Fingerprint Similarity: Calculates a pairwise Tanimoto similarity matrix using Morgan Fingerprints to flag highly similar compounds.
Requires Python 3.9+ and Rust (Cargo).
git clone https://github.com/VoidEchoes42/LeakGuard.git
cd LeakGuard
# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .\.venv\Scripts\activate
# Install package (will compile the Rust extension)
pip install -e .If you prefer not to manage a virtual environment and just want the CLI tool available globally, use pipx or uv:
# Using pipx
pipx install .
# Using uv
uv tool install .The package provides a CLI for quick analysis of CSV datasets.
leakguard analyze --train data/train.csv --test data/test.csv --smiles-col smiles--train(Required): Path to the training data CSV.--test(Required): Path to the testing data CSV.--smiles-col: Column name containing the SMILES strings (Default:"smiles").--threshold: Tanimoto similarity threshold for flagging leaked pairs (Default:0.8).--output: File path to save the report (JSON or TXT).
- Python Frontend (
leakguard/): Uses RDKit for cheminformatics tasks and Typer for the CLI. Converts valid SMILES into Morgan fingerprint bit vectors. - Rust Backend (
src/lib.rs): Takes NumPy bit vectors from Python and computes the Tanimoto similarity matrix in parallel across available CPU threads.
MIT License. See the LICENSE file.