What it does
You ask a question in plain English and get a sentence with the names and numbers that matter, a chart or a table you can copy or download as CSV, and the SQL behind it. It handles follow-ups in the same conversation (“now only the top 5”), keeps past conversations, lets you browse the tables, and connects to your own PostgreSQL database through a read-only user.
It is built for people who know their business but don’t read SQL. They can’t check the query, so the app has to decide when to answer at all.
Answer, clarify or decline
A triage call sees the question, the conversation and the candidate tables, and returns one of three decisions. It answers by default and states small choices as assumptions. It asks only when two readings would give materially different answers, and declines only when no column could hold the fact.
How a question is answered
- Schema. At startup the backend reads tables, columns, types, keys and comments. Partitioned tables appear as one table, so the model can’t sum two monthly partitions and call it the total.
- Triage. One model call decides to answer, clarify or decline.
- Retrieval. Tables and columns are scored by the words in the question through a small business vocabulary (“spent” → amount, payment), plus the shortest foreign-key path between matched tables, so the model sees the joins it needs.
- SQL. One call writes a single SELECT and up to three assumptions in plain words; a second call reviews it against the question and can ask for one rewrite.
- Checks and run. sqlglot parses the query and allows one read-only SELECT. It runs in a read-only transaction with a 10-second timeout and a 200-row cap; errors go back to the model for a bounded repair.
- Answer. A small model writes the sentence from the result rows. Every number in it is checked against the rows, and a plain template replaces it if one doesn’t match.
Four of these steps call a model, each with one narrow job and a structured (Pydantic) output; the rest is plain Python. There is no agent loop, so the number of model calls per question, and with it the cost and the latency, has a fixed upper bound.
Results
I tested it on 52 questions about two demo databases, including questions that are vague on purpose and questions the data can’t answer. Each answer was checked against the result of a hand-written SQL query.
| Questions | Answered correctly | Vague: asked first | Unanswerable: declined | Wrong answers | Median time | Cost per question |
|---|---|---|---|---|---|---|
| All 52 | 35 of 38 | 6 of 8 | 6 of 6 | 3 of 52 (6%) | 8.3 s / 8.7 s | $0.0072 / $0.0051 |
| 32 held-out | 19 of 20 | 4 of 6 | 6 of 6 | 1 of 32 (3%) | 7.8 s / 8.3 s | $0.0064 / $0.0044 |
“Wrong answers” are the ones that matter most: a confident answer that is wrong, or an answer to a question the data can’t support. Asking or declining is visible to the user and doesn’t count. The 32 held-out questions were written before any test run and never used to change prompts or rules, so that row is the fair one. Both runs gave the same outcome on every question; time and cost show run 1 / run 2.
Safety
AskData is meant to be pointed at databases it doesn’t own, so it doesn’t rely on a single check.
- Before connecting, it inspects the database user and refuses it, with the reasons, if it is a superuser, can create objects, can change any table, or can read or write server files.
- The SQL must be one SELECT;
COPYand risky functions such aspg_read_file,pg_sleepanddblinkare denied anywhere in the query. - Every query runs in a read-only transaction with a 10-second timeout and at most 200 rows.
- Connections added in the interface live in memory only, and passwords are masked in logs.
Limits
- Tested on two small demo databases and 52 questions; a difference of one or two questions is within run-to-run noise.
- One model family (OpenAI). Answers vary a little between runs.
- An answer takes about 8–9 seconds (median), because it needs four model calls.
- The number check catches invented numbers, not a correct number attached to the wrong name.