Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
51 small wins to finish your pathNext question →

Q21IntermediateSystem design

Design a natural-language analytics assistant (text-to-SQL) over a company data warehouse.

30-second answerSay your answer out loud first, then reveal.
Text-to-SQL flow: a business question and the semantic layer feed schema retrieval; ambiguous questions get a clarifying question, otherwise the LLM writes SQL that is validated (with a repair loop on errors), executed on a read replica, returned as an answer with table, chart and the SQL, and analyst corrections become new examples.

Key challenges

  1. Schema scale: warehouses have thousands of tables. Retrieve relevant tables via embeddings and metadata; maintain a curated "gold" subset for common questions.
  2. Business semantics: "active user", "revenue", "churn" have company-specific definitions. Encode them in a semantic layer (dbt metrics, LookML-style), or have the LLM generate metric queries instead of raw SQL.
  3. Correctness: queries can be syntactically valid but semantically wrong (wrong join, double counting). Mitigations: verified example queries (few-shot retrieval), showing the SQL and assumptions, result sanity checks.
  4. Security: read-only roles, row and column-level security per user, PII column masking, query cost limits.
  5. Evaluation: execution accuracy (does the result match the gold query's result?) on 100–300 real questions.

UX: show the interpretation ("I interpreted 'last quarter' as Jul–Sep 2026, revenue = net revenue") so users can catch mistakes.

Little by little, you're building something great.