Ask your database in plain English: how natural-language-to-SQL works
Every company has data locked in a database and a queue of people waiting on an analyst to pull it. A natural-language-to-SQL layer removes that bottleneck: someone types a question in plain English, the system writes the query, runs it, and returns the answer in seconds. We built exactly this for querying any database in plain English, and as the engineering partner behind QoreAI's QoreCloud for dealerships.
It is not "send the question to an LLM"
A model that hasn't seen your schema will hallucinate table and column names. The trick is to make the model schema-aware: retrieve the relevant tables, columns, relationships and a few example rows, and supply them as context — RAG, but for your database structure rather than documents.
- Understand the schema: tables, columns, types, foreign keys.
- Retrieve the slice relevant to the question (not the whole DB).
- Generate SQL constrained to that slice, with the model.
- Validate and run it read-only, then summarise the result.
Safety is the whole game
Letting a model write SQL against production data sounds terrifying — and would be, without guardrails. The pattern that makes it safe:
- Read-only connections and a hard allow-list of tables.
- Reject anything that isn’t a SELECT before it ever runs.
- Row limits and query timeouts so nothing runs away.
- Show the generated SQL so a person can verify it.
-- generated from: "top 5 products by revenue this quarter" SELECT p.name, SUM(oi.qty * oi.price) AS revenue FROM order_items oi JOIN products p ON p.id = oi.product_id WHERE oi.created_at >= date_trunc('quarter', now()) GROUP BY p.name ORDER BY revenue DESC LIMIT 5;
Why it changes who can use data
When anyone can ask a question without knowing SQL or waiting on a report, data stops being a specialist resource and becomes something the whole team uses to make decisions. That shift — not the model — is the real product.