Text-to-SQL is the use of a language model to translate a natural-language question — “how many orders did we ship to Canada last month?” — into a SQL query that runs against a database.
The problem it solves
In most organizations, the set of people with questions is much larger than the set of people who can write SQL. The traditional fixes are training (slow), visual query builders (good, but they still ask you to think in tables and joins), and a queue of requests to the data team (the bottleneck everyone complains about). Text-to-SQL attacks the problem at the language level: describe what you want, and the system writes the query.
How it works
The model is given the question plus context about the database — table and column names, types, relationships, sample values, and any descriptions attached to the schema — and generates a query, which the system executes and returns as a result or a chart. Better implementations add a loop: run the query, inspect the result or the error, and revise. That iteration is the seam where text-to-SQL shades into agentic analytics.
The context is doing most of the work. A model prompted with nothing but raw table names is guessing; one prompted with a well-described schema is translating.
Why schema quality decides accuracy
Text-to-SQL fails in a specific, predictable way: the model produces a query that runs and looks plausible but answers a subtly different question. It joins on the wrong key, forgets to exclude test accounts, or picks amount when it needed amount_net. A human analyst catches these because they know the warehouse’s folklore; the model only knows what the schema tells it.
So the accuracy lever isn’t mostly the model — it’s the data model and its metadata. Clear names, column descriptions, and curated tables raise accuracy; a warehouse full of tbl_ord_v3_final lowers it. A semantic layer helps most of all, because the dangerous ambiguities — what counts as revenue, which accounts are excluded — are resolved once in a definition the model can reference, instead of being re-derived in every generated query.
Text-to-SQL in Metabase
Metabot, Metabase’s AI feature, is an implementation of this idea: ask a question in natural language, and it generates the query and shows the result. It benefits from the same groundwork — the curated models and metrics you define in Metabase are exactly the context that makes generated queries trustworthy, and someone who reads SQL can always open the generated query the way they’d inspect any native query.
Keeping it honest
Treat text-to-SQL like a junior analyst: fast, useful, and in need of review on anything that matters. Teams deploying it seriously build evaluation sets — questions with known-correct answers — and track pass rates as the schema and prompts evolve, because “it usually gets it right” is not a property you want to discover the exceptions to in a board meeting.
Related terms
Put it to work
- LLM analytics — Overview
- Eval pass rate — Metric
- P95 LLM latency — Metric