Code
Architecture

Generative BI over a governed semantic layer

A user asks a business question and gets a dashboard in seconds. The AI interprets and chooses; definitions, joins and SQL are deterministic and auditable.

Swipe the diagram sideways to see all of it.

Business userquestion in English / HebrewWeb · Next.jsanswer + chart + lineagedashboards as JSON specsAPI · FastAPI (Cloud Run)staged pipelineone trace per questionClaude APIchooses and combines onlynever writes SQL or numbersANSWER PIPELINENormalizelanguage · as_ofinjectionVerifiedtrusted queriesno AIRouterHaiku 5.5workspacePlannerSonnet 5.5QueryPlanValidatorcatalog1 repairCompilerplan → SQLdeclared joinsExecutorread-only5 s · 5,000 rowsChecksboundsreconciliationAnswertrust tier+ lineageSemantic layer (versioned YAML)35 metrics · dimensions · declared joinsverified queries · values · known gapsMongoDB (raw)Crop Story · GeoJSON geometriesalerts · formsELTraw → staging → martsdata-quality testsPostgres + PostGIS (marts)one wide mart per processapp_reader role (SELECT only)Evals + tracesper-stage golden set · CI/trace/{id} replaycompiled SQL
AI (Claude)DeterministicTrust / controlData

Principles

01

The AI chooses and combines; it doesn't calculate

The model returns a typed QueryPlan (metrics, dimensions, filters). It never writes SQL or numbers.

02

Logic lives in the semantic layer

Ratio of sums, hectares counted once, required standard: rules in versioned YAML, not prompts.

03

Deterministic SQL

Same plan → same SQL, byte for byte. Declared joins only. Snapshot tests in CI.

04

Better “I don't know” than a wrong number

If a metric is missing, it refuses and offers the closest. Known gaps are declared.

05

Every number is traceable

Definition, plan, SQL, source tables, sample rows, as-of date and semantic version.

06

Evals are product

Golden set scored per stage; CI blocks if accuracy drops. Never used as few-shot.

Trust tier of every answer

TierWhenWhat the user sees
VerifiedMatches a verified query; only parameters are filled.Owner and verification date. AI cost: 0.
GovernedQueryPlan over defined metrics that passed every validator.Full lineage and check warnings.
ExploratoryFree SQL behind a flag (off in the public demo).SQL expanded and a review notice.
Not answeredOut of scope, ambiguous after one clarification, or failed validation.Plain explanation and the closest metrics.

Stack

LayerDemoProduction
WebNext.js 15 · Recharts · LeafletServerless (Node)
APIFastAPI · Pydantic · sqlglotCloud Run (min 0)
Analytical dataDuckDB (read-only)Postgres + PostGIS (Neon), app_reader
Raw dataJSONL (Mongo-shaped)MongoDB Atlas
LLMClaude Haiku 5.5 (router) · Sonnet 5.5 (planner)Same; model chosen on cost via evals
CIGitHub ActionsLint, tests, semantic linter, gated evals

Patterns from production systems

PatternSourceHere
LLM decomposes into metrics + dimensions; an engine writes SQLdbt Labs (2023, 2026)QueryPlan + compiler
Accuracy depends on the semantic layer more than the modelCube (2026)Model as config; compared in evals
Workspaces + intent agent + catalog pruningUber QueryGPTWorkspace router
Trusted assets: verified parameterised queriesDatabricks GenieVerified tier
Benchmarks evaluate but never feed the contextDatabricks GenieDisjointness test in CI