What is text-to-SQL?
Text-to-SQL is the translation of a question written in plain language into a Structured Query Language (SQL) statement that a database can run. A large language model receives the question together with the database schema (table and column names and their descriptions) and sometimes a few sample rows or example queries. It writes the SQL, the database runs it, and the result goes to the user or back to the model to be explained. It is the engine behind most natural language query tools.
Why text-to-SQL matters
SQL is the common language of business data, and text-to-SQL puts it within reach of people who will never learn it. It also lets an AI agent answer questions from live systems rather than from stale document copies. Syntax is rarely the hard part. The difficulty is knowing which of three “customer” tables is right, how the business defines “active,” and which currency revenue is summed in. A semantic layer or a data dictionary that spells those things out improves accuracy more than a larger model does.
What to watch for
- Run generated queries under a read-only account with the user’s own row-level permissions rather than a service account that sees everything.
- Set query timeouts and row limits, because a model will happily write a query that joins every table.
- Show the SQL with the answer so an analyst can confirm it did what the question meant.
- Give the model good schema descriptions; cryptic column names such as CUST_FLG_3 are where most errors begin.