AI Data Governance & Cleanup Platform
Self-hosted data governance platform for checksum PII tokenization, Jaro-Winkler undoable dedup merges, E.164/USPS normalization, and PostgreSQL schema hygiene audits.
01. Problem & Context
Data and backend engineering teams inherit production databases burdened with untagged PII columns, duplicate customer records, inconsistent phone/address formats, unindexed foreign keys, and high-risk cleanup scripts that lack rollback guarantees.
02. Engineering Solution
Built a Phase 2 self-hosted data governance and cleanup console pairing a FastAPI + async SQLAlchemy 2.0 backend with a 7-tab React 18 TypeScript UI. Unifies checksum-validated PII scanning and reversible HKDF/Fernet vault tokenization, Jaro-Winkler/Soundex duplicate clustering with undoable HITL merges, non-destructive E.164/USPS/ISO normalization previews, PostgreSQL DDL + live catalog audits, and Fernet-encrypted live SQLite/PostgreSQL connectors under four-eyes RBAC.
03. System Architecture
FastAPI domain APIs (`/api/v1/pii/*`, `/dedup/*`, `/normalizers/*`, `/schema-audit/*`, `/connectors/*`, `/auth/*`, `/jobs/*`, `/reports/*`, `/governance/*`) run on async SQLAlchemy 2.0 (`asyncpg` / `aiosqlite`) with Alembic migrations, HKDF + Fernet encryption, PyJWT + API-key four-eyes RBAC (`viewer`, `analyst`, `steward`, `admin`), pure ASGI security-header + rate-limit middleware, and `structlog` JSON logging.
Core Architectural Components
Checksum PII Detection & HKDF/Fernet Vault (`/api/v1/pii/*`)
Combines regex + checksum validators (Luhn cards, Mod-97 IBANs, SSN, email, phone, API keys, IPv4) and offline heuristic NER with `redact`, `mask`, `hash`, and reversible HKDF/Fernet vault `tokenize` + audited `detokenize`.
Undoable Duplicate Record Clustering & Merges (`/api/v1/dedup/*`)
Clusters duplicate records using blocking keys, Jaro-Winkler, token-set similarity, and Soundex, applies survivorship rules with field-level provenance, and routes undoable merge proposals through HITL gates.
Non-Destructive Normalizers & Live DB Connectors (`/api/v1/normalizers/*`, `/connectors/*`)
Generates non-destructive previews for emails, E.164 phones, USPS addresses, taxonomies, null sentinels, whitespace, and ISO dates, backed by Fernet-encrypted SQLite/PostgreSQL connectors with live introspection and transactional rollback.
PostgreSQL Schema Hygiene Audits & Four-Eyes Governance (`/api/v1/schema-audit/*`, `/reports/*`, `/governance/*`)
Audits PostgreSQL DDL and live catalog telemetry for orphaned/unindexed FKs, sequential-scan hotspots, missing PKs, untagged PII columns, unused indexes, and retention SLAs with remediation SQL and Markdown/CSV/JSON compliance exports.
04. Notable Engineering Decisions
Reversible HKDF/Fernet Tokenization & Transactional Merge Snapshots
Irreversible batch mutations or naive merges corrupt customer records. Storing reversible HKDF/Fernet tokens and pre-merge snapshots makes every cleanup operation auditable and undoable.
Checksum Validation to Eliminate PII False Positives
Validating Luhn check digits on payment cards and Mod-97 checksums on IBANs prevents order IDs or timestamps from flooding PII triage queues.
Four-Eyes RBAC Enforcement & Outbound Cloud PII Redaction
Requiring separate analysts and stewards on approvals alongside `LLM_REDACT_PII_FOR_CLOUD=true` ensures no single actor or model prompt exposes raw regulated fields.
05. Engineering Challenges & Solutions
Challenge: Supporting live inspection and cleanup on external PostgreSQL/SQLite databases without storing plaintext DB credentials.
Engineering Solution: Encrypted connector strings with Fernet at rest and scoped live introspection, table sampling, and CSV/JSON ingestion behind transactional HITL execution.
Challenge: Prioritizing real schema performance and compliance risks inside complex PostgreSQL DDL dumps.
Engineering Solution: Built a catalog and DDL analyzer pairing structural checks (missing PKs, unindexed/orphaned FKs) with live sequential-scan hotspot and untagged-PII heuristics plus remediation SQL.
06. Implementation Highlights
- Checksum-validated PII detection (Luhn, Mod-97 IBAN, SSN, API keys) with `redact`, `mask`, `hash`, and HKDF/Fernet `tokenize`/`detokenize`
- Blocking-key, Jaro-Winkler, token-set, and Soundex duplicate clustering with field provenance and undoable HITL merges
- Non-destructive E.164 phone, USPS address, email, taxonomy, null-sentinel, and ISO date normalization previews
- PostgreSQL DDL + live catalog schema hygiene auditor flagging unindexed/orphaned FKs, seq-scan hotspots, and untagged PII with SQL fixes
- Fernet-encrypted SQLite/PostgreSQL live connectors, transactional rollback, and four-eyes JWT/API-key RBAC (`viewer`/`analyst`/`steward`/`admin`)
- 7-tab React 18 TypeScript console with Markdown/CSV/JSON exports and Ruff/Mypy/pytest/Vitest/Trivy CI