AI glossary · Basic · Data engineering · Language models
Text-to-SQL
Text-to-SQL is a technology that converts a question asked in everyday language into SQL, the query language databases understand. It lets you ask questions of data directly without knowing SQL.
About this term
- Level
- Basic · Technical terms you often meet in AI news
- Category
- Data, ops & platforms
- Fields
- Data engineering, Language models
- Added
- 2026-10-09
How it works
When a user asks something like "Show me sales by region last month," the system first gathers the schema, information describing which tables and columns the database has. Feeding this schema together with the question into an LLM lets the model write an appropriate SQL statement. The generated SQL is run against the database, and the results are returned to the user as a table, chart or summary sentence. A common approach is that if an error occurs during execution, the error message is shown to the model again so it can fix the SQL.
Why it matters
Most company data lives in databases or data warehouses, but few people know how to write SQL. So business staff had to request and wait for an analyst even to see a single number. Text-to-SQL shortens this wait and lets more people check data themselves. As LLMs have improved, it is quickly being built into internal data analysis tools and BI services.
Good to know
SQL can be grammatically correct but wrong in meaning, so even plausible-looking results may be wrong numbers. Terms like "revenue" or "active users," whose definitions differ from company to company, are especially easy for the model to handle by guesswork, so a semantic layer that predefines such terms is often used alongside it. A basic rule is to connect with read-only permissions only, so SQL that accidentally deletes or changes data cannot run. For numbers used in important decisions, it is safer to have a step where a person checks the generated SQL.
Pre-deployment checklist
Safety
- Is it connected with read-only permissions only?
- Is SQL that changes data blocked?
Accuracy
- Are business term definitions documented?
- Is the generated SQL shown to users?
- Are important numbers reviewed by a person?
Example
When a sales representative types "Compare the number of new customers this quarter with last quarter" into a data chatbot connected to the company messenger, the chatbot internally writes SQL, runs it on the data warehouse, and replies with the two numbers and a simple bar chart. Many BI tools and cloud data platforms offer this kind of "ask in natural language" feature, and usually show the generated SQL alongside so users can review it.