Use Case · Data Analysis

AI Data Analysis: Query Your Database in Natural Language

NL2SQL, narrative report generation, anomaly detection, BI dashboard copilots and a data-security posture — so any teammate can ask a warehouse question and get a chart and explanation.

Updated Aug 16, 2026 · Start building free →

Scenario overview

"How did retention change for users acquired via podcast ads last quarter?" — a great growth question that took three Slack replies, one dbt run and a Looker export to answer. NL2SQL pipelines collapse that into one prompt and one chart. The challenge is doing it without letting the model invent or leak data: schema-grounded generation + read-only credentials + result verification is what separates a demo from a production copilot.

NL2SQLReport synthesisAnomaly detectionBI copilotData securityCited charts

Architecture (text version)

1
Schema captureCatalog tables, columns, descriptions, foreign keys + a small set of "golden" sample rows per table. Cached and re-embedded on schema drift.
2
NL2SQL (grounded)Model (gpt-5 or deepseek-v3) translates the question to SQL using schema + RAG over past Q&A pairs. Forced structured output + scope tags (read-only).
3
Execute (read-only)SQL is EXPLAIN-ed first, then executed via a read-only credential with a row cap. Big results are aggregated, never streamed wholesale to the model.
4
Report synthesisModel writes a narrative paragraph per returned result, cites column names and values, suggests one chart type and the x/y axes.
5
Anomaly detectionScheduled runs compare current metrics to historical distributions; the model writes an incident note when deviation exceeds threshold.
6
BI integrationEmbeds in Metabase / Superset / Grafana as a side panel. Query history forms a per-user context for follow-ups in the same thread.

Code & configuration

NL2SQL with grounded schema

curl https://api.dr-ai.top/v1/chat/completions \
  -H "Authorization: Bearer sk-***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5",
    "temperature": 0,
    "response_format": {"type": "json_object"},
    "messages": [
      {"role": "system", "content": "Translate the user question to SELECT-only SQL using the schema provided. Reply JSON: {sql, chart_type, columns}."},
      {"role": "user", "content": "Question: \"Weekly revenue by region, last 8 weeks, excluding returns\"\n\nSchema:\nCREATE TABLE orders(id, region, gross_revenue, refunded_at, created_at);"}
    ]
  }'

Sample dialogue

user > Top 5 declining SKUs by unit sales, last 30 days vs prior 30 days

assistant >
  sql
  WITH cur AS (SELECT sku, SUM(units) AS u FROM sales WHERE day >= now() - interval '30' day GROUP BY sku),
       prev AS (SELECT sku, SUM(units) AS u FROM sales WHERE day BETWEEN now() - interval '60' day AND now() - interval '30' day GROUP BY sku)
  SELECT cur.sku, cur.u AS cur_units, prev.u AS prev_units, prev.u - cur.u AS drop_units
  FROM cur JOIN prev USING(sku) ORDER BY drop_units DESC LIMIT 5;

  narrative
  SKU 78520 fell from 12,400 → 3,100 units (-75%). Confirm inventory status before reordering — this may be a stockout rather than demand drop.

Data security

Production hardening — couple NL2SQL with row-level security on your warehouse role so a marketing analyst simply cannot ask for raw payment rows, no matter how the model phrases the SQL.

ROI data

MetricBI ticket queueSelf-serve copilot
Time to answer (median)> 2 days~6 sec
Analyst hours / week / team6014
Questions answered / week~40~220
Stakeholder satisfactionavg 3.4/5avg 4.6/5
Wrong-data events (90-day)30

A medium-sized product org typically spends $480k/year on BI analyst headcount to answer self-serve questions. The same team, augmented with an NL2SQL copilot, supports 5× the question volume at ~$2k/month DrAI subscription cost — and analysts pivot to higher-value strategic work.

Let your whole team interrogate the warehouse

Stop queueing questions for analysts. Open an NL2SQL copilot behind your warehouse and ship answers in seconds.

Get Started — freeRead the Quickstart
🌐 English