A privacy & ML safety toolkit for production ML pipelines
Project description
🛡️ Valencity
The ML Safety Fortress
Privacy Engineering · Data Validation · Leakage Prevention
Why Valencity • Features • Install • Quick Start • Full API • CLI • Roadmap
"Stop shipping ML models that leak PII or data. Valencity catches it before you do."
🚀 Why Valencity?
Most ML teams discover data privacy problems in production — when it's already too late.
Valencity is the safety net that catches issues in your pipeline before they hit your users.
One line of code. Six layers of protection.
pip install valencity
| Capability | Valencity 🛡️ | Great Expectations | Pandera | Custom Scripts |
|---|---|---|---|---|
| PII Detection (50+ patterns) | ✅ | ❌ | ❌ | ⚠️ Manual |
| Masking & Anonymization | ✅ | ❌ | ❌ | ❌ |
| K-Anonymity & Differential Privacy | ✅ | ❌ | ❌ | ❌ |
| ML Leakage Prevention | ✅ Full Suite | ❌ | ❌ | ❌ |
| Data Drift Detection (4 methods) | ✅ | ✅ | ❌ | ⚠️ Manual |
| Schema + Quality Checks | ✅ | ✅ | ✅ | ⚠️ Manual |
| Synthetic Data Generation | ✅ | ❌ | ❌ | ❌ |
| GDPR / CCPA Compliance | ✅ | ❌ | ❌ | ❌ |
| HTML Reports | ✅ Beautiful | ✅ | ❌ | ❌ |
| CLI Tool | ✅ | ❌ | ❌ | ❌ |
✨ Features
🕵️ PII Detection & Anonymization
- Detect 50+ PII types — emails, phones, IBANs, passports, API keys, SSNs, IPs, and more
- Smart Masking: redact, hash (SHA-256), partial mask, or replace with realistic fake data
- NLP support for names and addresses via spaCy (optional)
- Async detector for non-blocking scans in production services
- Plugin-friendly: register your own custom PII patterns
✅ Data Validation & Quality
- Data Profiling: automatic statistical summary of any DataFrame
- Schema Validation: enforce strict data contracts — types, nullability, ranges
- Quality Checks: nulls, duplicates, outliers, cardinality, and more
- Fluent Expectations API: expressive, chainable validation rules
- Drift Detection: KS test, chi-squared, Jensen–Shannon divergence, and PSI
🚫 Leakage Prevention
- SafeCrossValidator: preprocessing only sees training fold — no more optimistic CV scores
- LeakageDetector: catches target leakage, train/test overlap, and temporal leakage
- SafeSplitters: time-series and group-aware train/test splits
🔐 Privacy Engineering
- Differential Privacy: add calibrated Laplace / Gaussian noise to statistics
- Compliance Checker: automated GDPR & CCPA violation detection with fix suggestions
🧬 Synthetic Data
- SyntheticGenerator: generate realistic fake datasets that mirror real data distributions
📊 Reporting
- Beautiful HTML reports for PII scans, quality audits, drift analysis, and compliance checks
📦 Installation
# Core (PII, validation, leakage, reports)
pip install valencity
# With NLP support (names, free-text addresses)
pip install valencity[nlp]
python -m spacy download en_core_web_sm
# Full developer install
pip install valencity[all]
Requirements: Python ≥ 3.9, pandas ≥ 1.5, scikit-learn ≥ 1.0
⚡ Quick Start
1 · Detect & Mask PII
import pandas as pd
from valencity.pii import PIIDetector, PIIMasker
df = pd.read_csv("users.csv")
# Scan
detector = PIIDetector()
report = detector.scan_dataframe(df)
if report.has_pii:
print(f"⚠️ PII detected in columns: {list(report.columns_with_pii.keys())}")
for col, col_report in report.columns_with_pii.items():
for pii_type in col_report.pii_types_found:
print(f" [{pii_type.name}]")
# Mask
masker = PIIMasker(strategy="partial") # john@example.com → j***@example.com
safe_df = masker.mask_dataframe(df)
2 · Validate Schema & Quality
from valencity.validation import DataSchema, DataQualityChecker, DataProfiler
# Auto-infer schema from training data
schema = DataSchema.from_dataframe(train_df)
validation_result = schema.validate(production_df)
# Quality report
checker = DataQualityChecker()
quality = checker.full_report(df)
print(quality.summary())
# Statistical profile
profiler = DataProfiler()
profile = profiler.profile(df)
print(profile.summary())
3 · Detect Data Drift
from valencity.validation import DriftDetector
detector = DriftDetector(method="ks_test") # ks_test | chi2 | js | psi
detector.fit(reference_df=train_df)
drift = detector.detect(current_df=production_df)
if drift.has_drift:
print(f"🚨 Drift detected in: {drift.drifted_columns}")
4 · Prevent Model Leakage
from valencity.leakage import SafeCrossValidator, LeakageDetector, temporal_train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
# Detect leakage before training
ld = LeakageDetector()
issues = ld.full_check(X_train, X_test, y_train, y_test)
if issues:
print(f"🚨 Leakage found: {issues}")
# Safe CV — preprocessing never sees test fold
cv = SafeCrossValidator(n_splits=5, preprocessor=StandardScaler())
scores = cv.cross_val_score(LogisticRegression(), X, y)
print(f"✅ Realistic accuracy: {scores.mean():.4f} ± {scores.std():.4f}")
# Safe time-series split
X_train, X_test, y_train, y_test = temporal_train_test_split(X, y, time_column="date")
5 · Privacy Engineering
from valencity.privacy import DifferentialPrivacy, ComplianceChecker
# Add calibrated noise to protect aggregates
dp = DifferentialPrivacy()
noisy_mean = dp.laplace_mechanism(value=df["salary"].mean(), sensitivity=1000, epsilon=1.0)
# Check GDPR / CCPA compliance
checker = ComplianceChecker()
compliance = checker.check_gdpr(df)
if not compliance.satisfied:
for violation in compliance.violations:
print(f"❌ {violation.rule}: {violation.description}")
6 · Generate Synthetic Data
from valencity.synthetic import SyntheticGenerator
gen = SyntheticGenerator().from_dataframe(real_df)
synthetic_df = gen.generate(num_rows=1000)
7 · Generate HTML Reports
from pathlib import Path
from valencity.reports import HTMLGenerator
from valencity.pii import PIIDetector
detector = PIIDetector()
pii_report = detector.scan_dataframe(df)
gen = HTMLGenerator()
gen.render_pii_report(pii_report, output_path=Path("pii_report.html"))
print("📊 Report saved → pii_report.html")
🖥️ Full API
import valencity
valencity.show_api()
| Module | Class / Function | Purpose |
|---|---|---|
valencity.pii |
PIIDetector |
Scan DataFrames & text for PII |
valencity.pii |
PIIMasker |
Mask / anonymize PII |
valencity.pii |
PIIType |
Enum of 50+ supported PII types |
valencity.pii |
PIIPatterns |
Pattern registry (plugin-friendly) |
valencity.pii |
AsyncPIIDetector |
Async, non-blocking PII scanning |
valencity.validation |
DataSchema |
Schema validation & contracts |
valencity.validation |
DataQualityChecker |
Null / duplicate / outlier checks |
valencity.validation |
DataProfiler |
Statistical profiling |
valencity.validation |
DriftDetector |
KS, chi2, JS, PSI drift detection |
valencity.validation |
expect() |
Fluent expectations API |
valencity.leakage |
SafeCrossValidator |
Leakage-safe cross-validation |
valencity.leakage |
SafeSplitter |
Time-series & group-aware splits |
valencity.leakage |
LeakageDetector |
Target, overlap & temporal leakage |
valencity.privacy |
DifferentialPrivacy |
Laplace / Gaussian DP noise |
valencity.privacy |
ComplianceChecker |
GDPR / CCPA violation detection |
valencity.synthetic |
SyntheticGenerator |
Realistic synthetic data |
valencity.reports |
HTMLGenerator |
Beautiful HTML audit reports |
🖥️ CLI
# Show package info
valencity info
# Scan a CSV for PII
valencity pii scan users.csv
# Mask PII in a CSV
valencity pii mask users.csv --output safe_users.csv
# Generate a data profile
valencity profile dataset.csv
# Check GDPR/CCPA compliance
valencity compliance dataset.csv
# Run quality checks
valencity validate quality dataset.csv
🗺️ Roadmap
- PII Detection — 50+ patterns, masking, async support
- Data Validation — schema, quality, drift, profiling
- Leakage Prevention — CV, splitters, detectors
- Privacy Engineering — differential privacy, compliance
- Synthetic Data Generation
- CLI Tool
- MLflow Integration — auto-log safety checks to experiments
- Airflow Operator — drop-in pipeline safety checks
- dbt Integration — run Valencity checks in dbt tests
- Dashboard UI — real-time data safety monitoring
🤝 Contributing
Contributions are welcome! Check the open issues.
git clone https://github.com/ihakawati/valencity
cd valencity
pip install -e ".[dev]"
pytest
- Fork the repo
- Create a feature branch:
git checkout -b feature/my-feature - Commit:
git commit -m "feat: add my feature" - Push:
git push origin feature/my-feature - Open a Pull Request
Built with ❤️ for the ML Community
PyPI · GitHub · Report a Bug
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
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 valencity-0.1.4.tar.gz.
File metadata
- Download URL: valencity-0.1.4.tar.gz
- Upload date:
- Size: 52.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06e056fe8ebc4f35f5fa299a0232cb063ad2c97ef14463b2167e919b09904864
|
|
| MD5 |
194298fdaf7d28f532ab33fd4f8d1f67
|
|
| BLAKE2b-256 |
b36771e5b0dbe0a27d83b13517dd8475307844ca7e0661c5dd715476fa382c6f
|
File details
Details for the file valencity-0.1.4-py3-none-any.whl.
File metadata
- Download URL: valencity-0.1.4-py3-none-any.whl
- Upload date:
- Size: 57.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac5d585807a5ca23a2d4bf8dd90a5392dd3f4dab3171061ea43f0e7d7b07e3df
|
|
| MD5 |
27913b5e08c93c410865fd1b7d7cac2d
|
|
| BLAKE2b-256 |
d1a97be2e5b170d66ddf636a81a511e9a9e74d2495dce3bee4b7173cf53e341c
|