ai-powered-conversational-intelligence

08 — Data Profiling, PII & Client Onboarding Engine

Prompt 08 of the 32-prompt Enterprise AI Analytics & Recommendation Platform initiative (00_MASTER_IMPLEMENTATION_CONTRACT.md), following 07_RELATIONSHIP_INTELLIGENCE_CONTRACT.md. INSPECT/PLAN/IMPLEMENT/ TEST/REVIEW/FIX/DOCUMENT — a new onboarding/ package (pure-logic pipeline stages, each independently testable with plain objects/a real SQLite database), a new identity/ persistence slice (3 ORM tables + an Alembic migration + a repository module, following identity/ repositories/shares.py’s own split exactly), a new RBAC permission pair, and a new REST surface (api/onboarding.py). Scope, per the user’s own explicit choice when asked to calibrate: “Full pipeline, real depth on the new parts” — discovery/relationship stages reuse Prompts 06/07 unchanged; every other stage (profiling, PII detection, semantic inference/ambiguity detection, SME review, semantic contract, golden questions, evaluation) is genuinely new, tested logic, not a stub.

1. Inspection: what already existed vs. the real gaps

db/schema_introspection.py (Prompt 06) already discovered tables/ columns/types/FKs/views/row-count estimates. db/relationship_inference.py (Prompt 07) already inferred undeclared FK candidates with confidence/ evidence. agent.provenance.DataTruthLevel (Prompt 02) already defined the DATABASE_FACT/AI_INFERENCE/CONFIRMED_BUSINESS_TRUTH vocabulary this prompt needed. config/sensitive_columns.py/config/table_descriptions.py already enforced a hand-authored PII/semantic classification once one exists — but nothing in the codebase ever produced one; both files assume a human already wrote the YAML. identity/repositories/shares.py

Real gaps, found by reading the actual code (not assumed):

  1. No profiling at all — no null%/distinct/min/max/avg/percentile/ distribution/duplicate-key/orphan-row computation existed anywhere.
  2. No PII detection — config/sensitive_columns.py only consumes a classification; nothing produced one.
  3. No semantic-role inference — config/table_descriptions.py only consumes column notes; nothing inferred a column’s likely business role (identifier/measure/category/free_text/…) or flagged ambiguity.
  4. No SME review workflow, no job/state-machine persistence, no onboarding API — this entire engine (the prompt’s actual acceptance criterion) didn’t exist.
  5. No golden-question generation or pre-publish smoke-test — the only existing few-shot mechanism (embeddings/golden_examples.py, Prompt before this series) requires a human to already know good (question, SQL) pairs; nothing proposed candidates for a brand-new database.

2. What was built

onboarding/ (new package — pure logic, zero identity/ dependency except jobs.py)

identity/ additions

api/onboarding.py / api/onboarding_schemas.py (new)

10 routes under /onboarding: create/list/get job, discover, list/decide review items, publish, cancel, retry, list artifacts. db_password appears on exactly 3 request bodies, never a response model. Discover/ publish build a throwaway Engine directly (create_engine(...), disposed in finally) — deliberately bypassing db.connection’s process-wide cached-engine pool, whose own docstring assumes “a handful” of configured connections, an assumption this dynamic, many-distinct- candidate-databases-over-time engine would violate.

config/settings.py

enable_pii_data_verification (default False) + pii_data_verification _sample_size — kept separate from Prompt 07’s enable_relationship _data_verification flag, per the prompt’s own “minimize sensitive sampling” requirement: an operator can opt into relationship value- overlap sampling (never PII-shaped) without also opting into sampling columns already name-flagged as likely PII.

3. Explicitly out of scope

4. Testing

9 new test files, 116 tests, all passing:

Full suite: 2635 tests pass (2519 pre-existing + 116 new), zero regressions (pytest -q, ~98-125s across runs). ruff check / black --check / mypy on every touched/new production file: clean (two pre-existing, unrelated findings in api/main.py confirmed via git stash to predate this prompt’s changes — left alone, not claimed as fixed, per CLAUDE.md’s own documented CI-hygiene-gap tracking).

5. Security / tenant-isolation / performance review

6. Known limitations / remaining risks

Per 02_TARGET_ARCHITECTURE.md §5’s own table: wire analytics/ (ResultSummaryAnalyticsProvider) into generate_insight_node and surface AnalyticsResult in AskResponse — unchanged recommendation carried forward from Prompts 04-07, still pending explicit sign-off since it changes a live response shape.