Databricks DE · Topic 10.4

Databricks Genie

Business users ask data questions in plain English; Genie generates governed SQL over Unity Catalog data. A curated Genie space grounds it in your business terms — and the Conversation API makes it programmable.

NL → SQLGenie space + curationUC-governedConversation API

The one-liner

AI/BI Genie turns plain-English questions into SQL + results over governed UC data. You build a Genie space over chosen datasets and curate it (instructions, example SQL, certified metrics) so answers match your business definitions — all enforced by Unity Catalog and callable via the Conversation API.
🗣️ Analogy: a bilingual analyst on call — you speak "business," it speaks "SQL." The curation is the glossary you give it so it uses your definition of "active customer" or "revenue."

Ask in English — and see why curation matters

▸ toggle curation to compare the answer

Space curation:
ON (metrics + instructions)
🧑‍💼 "What was revenue by region last quarter?"

How it works — deep dive

1 · The Genie space — scope + datasets

Mechanism: a space is bound to a set of UC tables/views and runs on a SQL Warehouse — the unit of scope, curation & permission. Trade-off: too many/messy tables dilute accuracy; aim at a focused, well-named gold domain.

-- A space points at curated gold objects; make columns self-describing.
CREATE OR REPLACE VIEW gold.sales_fact AS
SELECT order_id, region, net_revenue, fiscal_quarter, order_date
FROM prod.sales.orders_enriched;
COMMENT ON COLUMN gold.sales_fact.net_revenue IS 'Revenue after returns/discounts (finance definition)';

2 · Natural language → SQL

Mechanism: Genie maps the question to SQL using schemas + column comments + curation, runs it, and returns the SQL and result so users verify & refine. Trade-off: ambiguity → plausible-but-wrong query; fix with curation, not luck.

-- "revenue by region last quarter" → Genie generates (and shows):
SELECT region, sum(net_revenue) AS revenue
FROM gold.sales_fact
WHERE fiscal_quarter = '2026-Q1'
GROUP BY region ORDER BY revenue DESC;

3 · Curation & trust — instructions, example SQL, metrics

Mechanism: curate with general instructions, example SQL, certified/sample questions, and defined joins & metrics so "revenue" resolves to one definition. Trade-off: ongoing upkeep — but it's what makes answers trustworthy.

-- Encode the canonical metric as a governed object everyone (incl. Genie) reuses:
CREATE OR REPLACE VIEW gold.active_customers AS
SELECT * FROM prod.sales.customers
WHERE status = 'ACTIVE' AND last_seen >= current_date() - INTERVAL 90 DAYS;
-- Space instruction: "'active customer' = rows in gold.active_customers."

4 · Governance — UC grants, row filters, column masks

Mechanism: Genie queries run as the asking user through Unity Catalog, so existing grants, row filters, and column masks apply automatically — it can't surface data the user couldn't query. Trade-off: users get different rows by grant (correct, but explain it).

-- Grant the curated domain; an existing row filter (8.3) still applies in Genie.
GRANT SELECT ON VIEW gold.sales_fact TO `sales-ops`;
-- ALTER TABLE prod.sales.orders_enriched
--   SET ROW FILTER catalog.sec.region_filter ON (region);  -- scopes rows per user

5 · Genie is programmable — the Conversation API

Mechanism: drive a space from code — start a conversation, send follow-ups, poll the message until done. Trade-off: start a new conversation per session (reuse bleeds context); poll every 1–5 s, cap ~10 min. ⚠️ verify the API version against docs.

# Start a conversation in a space (verified path, API 2.0):
curl -X POST \
  https://<host>/api/2.0/genie/spaces/<space_id>/start-conversation \
  -H "Authorization: Bearer $DATABRICKS_TOKEN" \
  -d '{"content": "What was revenue by region last quarter?"}'

# Follow-up: POST .../spaces/<space_id>/conversations/<conversation_id>/messages
# Poll the message until status = COMPLETED / FAILED / CANCELLED.

6 · Genie vs a generic LLM chatbot

Mechanism: a generic chatbot answers from training data; Genie is grounded — it answers only by generating SQL over your governed tables, shows the query, and respects UC. Trade-off: it won't answer beyond its data (by design); review SQL for key decisions.

Databricks GenieGeneric LLM chatbot
Source of truthyour UC tables (live)training data / prompt
OutputSQL + result (verifiable)prose (opaque)
GovernanceUC grants/filters/masksnone
Accuracy levercuration (metrics, instructions)prompt engineering

The Genie family — click each

AI/BI Genie (this lesson)▸
For business users — natural-language Q&A over governed data via a curated Genie space. Generates SQL + visualizations.
Genie Code▸
For developers — NL → code/pipelines/dashboards across notebooks, SQL editor, Lakeflow Pipelines (Topic 6.3).
Genie One▸
Cross-asset chat experience for broader Q&A across the platform.

Why it matters

📈 Real-world use case: a sales-ops Genie space over gold tables — a manager asks "top 5 regions by revenue last quarter," Genie writes the SQL and charts it, grounded by the space's certified "revenue" metric so it matches finance.

Uses, edge cases & limitations

Common gotchas