ai-powered-conversational-intelligence

42 — Data Lineage Platform

Prompt 42 of the ongoing Enterprise AI Analytics & Recommendation Platform initiative: end-to-end lineage from source database objects through columns, governed metrics, executed SQL, visualizations, insights, and recommendations. INSPECT/PLAN/IMPLEMENT/TEST/REVIEW/ FIX/DOCUMENT — one new top-level package (lineage/), a new standalone REST surface (api/lineage.py), a new multi-agent specialist, a new frontend explorer page, server-driven nav wiring, additive config surface, and a dedicated cross-cutting regression test proving the mission’s own two named acceptance checks. No existing route, node, prompt, or Settings field changed behavior for any pre-existing caller.

0. A found, disclosed branch-divergence risk (read before extending this further)

feat/knowledge-graph-36 (Prompt 36, “Enterprise Knowledge Graph”) is a sibling branch, never merged into this branch’s own history, with materially overlapping scope — found only after this prompt’s own implementation was complete and tested, while preparing to commit (a cross-branch git log --all check, not something an in-tree grep could have surfaced: git branch --all --contains <that commit> shows it reachable only from feat/knowledge-graph-36, which diverged from this branch’s own history at their shared merge-base 791521a and was never merged back into either master or this branch). Its own commit message describes a persisted, Postgres-backed (graph_nodes/graph_edges) generic node/edge graph spanning tenants/databases/schemas/tables/ columns/metrics/dimensions/business terms/policies/questions/findings/ recommendations/evidence, with derives_from/governed_by/ supported_by/joins_to edge types, a GET /graph/lineage/{id}/ GET /graph/impact/{id} bounded-BFS traversal, and a restricted-column- removed-before-traversal authorization posture — independently arriving at several of the same shapes this prompt’s own lineage/ package uses (GOVERNED_BY/SUPPORTED_BY edge names, BFS trace, pre-traversal restricted-node removal).

What is genuinely different, not just duplicated: that branch’s graph is a persisted projection synced from several source systems at once (schema, catalog, semantic-intelligence findings, recommendations, policy/document RAG, chat questions) with no SQL-statement-level column-derivation parsing at all; this prompt’s lineage/ is a stateless, deterministic, sqlglot-based engine whose own distinct contribution is column-level lineage recovered from one query’s or one governed metric’s actual SQL/expression text (never persisted, always caller-supplied/re-fetched per call), plus the query → visualization → insight → recommendation presentation tail that branch’s own commit message does not mention at all.

This was not reconciled in this pass — merging two independently- designed, partially-overlapping graph systems is a larger, separate undertaking than this prompt’s own scope, and attempting it without the project owner’s explicit direction on which to keep, merge, or layer would risk exactly the kind of silent, unreviewed architectural collision master rule 4 (preserve working behavior) warns against. Flagged here, in §6’s recommended next prompt, and in the final report handed back for this prompt — not silently worked around.

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

Exhaustive grep for “lineage”/”knowledge_graph”/”dependency_graph”/”DAG” within this branch’s own working tree confirmed exactly one prior lineage concept reachable from here: data_quality/lineage.py (Prompt 41) — a narrow, table-level-only link from a data-quality finding to a published governed concept declaring that table as a source (identity.models.SemanticCatalogEntry .source_tables), with no column-level precision, no schema/FK layer, no query/visualization/insight/recommendation layer, no trace/impact analysis, no versioning/staleness concept, and no persisted or assembled “graph” at all — confirmed by direct inspection of that module’s own docstring and identity/models.py (no source_columns field exists on SemanticCatalogEntry).

Building blocks reused, never reimplemented:

Real gap this prompt closes: nothing in this codebase before it could answer “where did this KPI’s number actually come from” or “what breaks if this table/column changes” across the full mission-named chain, with deterministic parsing preferred over LLM guesses, and no way to detect that a previously-computed lineage fact had gone stale.

2. What was built

lineage/ (new top-level package, a peer of analytics//

optimization//data_quality/)

api/lineage.py + api/lineage_schemas.py

Three routes, all gated by Settings.enable_lineage_platform (404 when off) and rate limiting:

A database_id outside Settings.databases_for_tenant(tenant_id) is a 404 — the identical anti-enumeration convention GET /schema/tables already establishes. Request models forbid unknown fields (caller_roles/ tenant_id can never be client-supplied).

Multi-agent wiring (agent/multiagent/)

New AgentName.LINEAGE, TOOL_LINEAGE (registered at Permission.ASK, the identical two-tier pattern TOOL_DATA_QUALITY/TOOL_OPTIMIZATION already establish and this prompt reused from the start rather than rediscovering the Prompt-39 bug), lineage_handler, and a new, self- contained LineageRequest dataclass (sql + optional dialect, no data_task — DataSlot does not carry the SQL text that produced its rows, confirmed by direct inspection, so there is no governed-rows slot a data_task could point at here; the identical shape OptimizationRequest already establishes for the same reason). Its AgentSpec.max_truth_level is DataTruthLevel.DATABASE_FACT — the identical reasoning DATA_QUALITY’s own spec gives: a deterministic parse of SQL text is an observed fact about that text’s structure. Gated on an explicit caller-supplied request; the planner never creates one.

Frontend (frontend/src/pages/DataLineage.tsx)

A lean, read-only explorer — database selector, “Build graph” (calls /lineage/graph), nodes grouped by type with TruthLevelBadge (reused, not duplicated), and a trace panel (select a node, pick upstream/ downstream, calls /lineage/trace). Deliberately a plain grouped-list view, not a graph-visualization library — consistent with this app’s own stated conservatism against adding a new rendering library for a chart/graph type. Wired through security/navigation.py (new data_lineage NavItem, agent_any={ASK} — hiding a tab is UX only, the real enforcement is the route’s own require_local_user), App.tsx, AppShell.tsx’s screen-presentation map, and all 5 locale files’ nav label (the same “translate the minimum bar” precedent MediaSearch.tsx established).

Config (config/settings.py)

enable_lineage_platform (default True), lineage_max_trace_depth, lineage_max_queries_per_request, lineage_max_trace_graph_nodes — the identical “cap regardless of what a caller sends” philosophy data_quality_max_tables/predictive_max_features already establish.

3. Authorization, tenant isolation, and provenance

Authorization is node suppression, not value redaction. A COLUMN node naming a column config.sensitive_columns classifies “restricted” is removed from the graph entirely (never kept with a placeholder value) for a caller lacking Permission.VIEW_RESTRICTED_COLUMNS — a lineage graph can disclose a restricted column’s existence/name even without ever disclosing a value, so this platform treats that the same way optimization.validator/analytics.predictive treat a restricted column reference: withheld outright. LineageGraph .suppressed_restricted_nodes discloses what was removed, never a silent omission.

Tenant isolation mirrors data_quality’s own /lineage route exactly — security.tenancy.resolve_actor_tenant_id (never a client- supplied value), Settings.databases_for_tenant filtering which database names a tenant may even name, and identity.repositories.semantic_catalog.list_entries(session, tenant_id, ...) scoping every catalog read. Proven directly, against a real identity database with real tenants/users/published rows (not a mock), in tests/security/test_lineage_kpi_end_to_end_and_tenant_isolation.py.

Provenance: every node/edge carries its own DataTruthLevel — DATABASE_FACT for a declared FK, a deterministic SQL/expression parse, or a computed chart spec; CONFIRMED_BUSINESS_TRUTH only for a published catalog entry’s own edges; AI_INFERENCE for an inferred candidate relationship, a draft/reviewed catalog entry, an LLM-narrated insight, or a recommendation — never silently promoted, even when reached transitively through a multi-hop trace (verified directly: every downstream insight/recommendation node reached by trace_lineage stays tagged ai_inference).

4. Testing

Full suites re-run clean: 4236/4236 backend tests passing (the pre-existing count, confirmed unchanged before this prompt’s own new test files were added) + 51 new backend tests; 561/561 frontend tests passing, zero regressions; npx tsc --noEmit clean.

5. Known, disclosed limitations

First, and most urgently: reconcile feat/knowledge-graph-36 with this work (see §0) — decide, with the project owner, whether the two graph systems merge into one, or lineage/’s own SQL-statement-level column parsing and presentation-tail layering become an additive extension synced into that branch’s persisted graph_nodes/ graph_edges store instead of staying a separate, stateless package. Doing this before either system gets its own further frontend/API investment avoids compounding the divergence.

Separately: a persisted lineage history (auto-capturing each /ask/ /execute call’s own query/visualization/insight/recommendation lineage into a queryable store, closing the “self-contained per call” limitation above — likely the same store feat/knowledge-graph-36 already built, once reconciled) and/or a real graph-visualization frontend, once a design-system decision is made about which (if any) graph-layout library this app is willing to adopt.