What Is Text-to-SQL? Natural Language to SQL, Explained Plainly
Text-to-SQL (NL2SQL) is the AI technique that turns a natural-language question into a runnable SQL query. How it works, where it fails, and what safe usage requires. A guide without the marketing.
Searches for "text to sql" have climbed sharply over the past year, because large language models finally made this old research problem usable. This article explains the term without slipping into marketing: what it does, how it does it, and where it stumbles.
What exactly is text-to-SQL?
Text-to-SQL (also written NL2SQL in the literature) is the technique of translating a question written in natural language, such as "who are our top 10 customers by orders last month?", into a SQL query that can run against the relevant database. The input is a human sentence, the output is SQL, and an AI model does the translation in between.
The family of terms can be confusing: text-to-SQL names the translation technique, while NLQ (natural language query) names the user-facing experience built on top of it. A product that offers NLQ almost always runs text-to-SQL under the hood.
How does it work?
- The model sees the database schema: table names, column names, and types. The map of the data, not the data itself.
- The user's question and that schema go to the model together; the model produces the SQL that matches the question.
- The generated query runs on the database, and the result comes back as a table or a chart.
The critical detail is schema quality. With meaningful names like "customers" and "orders" the model performs well; with cryptic names like "T001" and "F17" accuracy drops. That is why serious text-to-SQL tools let you annotate columns with descriptions.
How accurate is it? The honest answer
Even the best systems on academic benchmarks (Spider, BIRD) do not reach one hundred percent, and real-world schemas are messier than benchmarks, so you should not expect one hundred percent in production either. Ambiguous questions ("best customers" by what measure?) and complex multi-table queries are where systems stumble most.
That makes how accuracy is measured more important than the number itself. A query that "looks right" and a query that returns the right data when executed are different things; measurement should be based on the latter. At PerSight we benchmark against hundreds of real questions across four database engines and publish the result with an open method.
Three requirements for safe use
- Read-only execution: generated queries must be SELECT-only, with writes and deletes technically blocked.
- Visible SQL: the generated query must not stay in a black box; you should see and edit it before it runs.
- Data locality: only the schema and the question should reach the model; row data should never leave your machine.
Frequently asked questions
- Are text-to-SQL and NL2SQL the same thing?
- Yes, two names for the same technique. Academic papers tend to write NL2SQL; product pages tend to write text-to-SQL.
- How is a text-to-SQL tool different from asking ChatGPT to write SQL?
- ChatGPT does not know your schema; you paste table structures by hand and copy queries back yourself. A text-to-SQL tool is connected to the schema, runs the query through a safety layer (read-only), and shows the result directly. Pasting company schemas or data into a chatbot is also a policy violation at many companies.
- Does it work in languages other than English?
- Modern models are multilingual; a Turkish or German question matches even English schema names. PerSight treats Turkish as a first-class language and also speaks English and German.
- Does text-to-SQL replace someone who knows SQL?
- For routine question-and-answer queries, largely yes; for data modeling, performance tuning, and complex analysis, no. The healthiest setup keeps the generated query visible so someone who knows SQL can review it when needed.
If you want to try text-to-SQL on your own database, PerSight is built on exactly those three requirements: read-only, visible SQL, and your data staying on your machine. The beta queue is at persight.ai/beta.
References
Related articles
- What Is a Natural Language Query (NLQ)? Reaching Data in Your Own WordsNLQ, or natural language query, is the experience of reaching data with your own sentence instead of SQL or filter panels. How it relates to text-to-SQL, its place in self-service BI, and its limits.
- Is AI-Generated SQL Safe? The Real Risks and How to Contain ThemAI SQL generators and ChatGPT-written SQL are everywhere; is that safe on company data? Four real risks and a concrete control for each: read-only users, visible SQL, data locality, and measurement.
- Natural Language to SQL: How It Works and Why the Visible Query MattersA plain-English guide to natural-language-to-SQL: how a question becomes a query, why a read-only, always-visible query is safer, and how PerSight keeps your row data on your machine.