Sign in

Glossary

Text-to-SQL

Turning a question in plain English into a SQL query that runs against a database and returns the answer.

DefinitionTurning a question in plain English into a SQL query that runs against a database and returns the answer.

Text-to-SQL is a technique in which a language model reads a question such as "revenue by region last quarter," looks at the database schema and writes the SQL query that answers it. The database does the arithmetic, which is its strength. The weakness is that a query can run cleanly and still answer a different question from the one asked.

How it is computed

The question and a description of the tables and columns go to the language model, which returns a query. The query runs, and the result is checked before it is shown: row counts, totals against a known control figure, and the filters actually applied.

Example

Orders for the quarter total $600,000. A generated query joins orders to a contacts table in which every account has two contacts, so each order appears twice and the query returns $1,200,000. A control-total check against $600,000 catches it.

Where it goes wrong

Fan-out joins like that one, wrong date columns, and ambiguous business terms such as "active customer." The full guide is text-to-SQL.