What NL2SQL is
NL2SQL translates an everyday-language question into a SQL query, runs it against a database and returns the result. Its appeal is that the people with questions rarely write SQL. Because a wrong query can return a confident but wrong number, a good system shows its SQL so answers can be checked and re-run.
The appeal is simple: the people who have the questions are rarely the people who write SQL. The risk is just as simple: a wrong query returns a confident, wrong number. The build is therefore about making the answer checkable.
How NL2SQL goes wrong, and how to guard against it
Four failures are worth designing for, each with a control that reduces the risk. For wrong joins or columns, give the model the real schema and column descriptions and show the SQL. For ambiguous questions, clarify or state the assumption. Limit unsafe queries with read-only credentials, limits and timeouts. Store generated queries for re-runs.
| Failure | What it looks like | Control |
|---|---|---|
| Wrong joins or columns | A plausible number from the wrong tables | Give the model the real schema and column descriptions, and show the SQL |
| Ambiguous question | "Revenue" could mean booked, billed or collected | Ask a clarifying question, or state the assumption in the answer |
| Unsafe query | A write, a delete or a full-table scan on production | Read-only credentials, query limits and timeouts |
| Unrepeatable answer | Nobody can reproduce the result | Store and re-run the generated query |
NL2SQL compared with a BI dashboard
Dashboards fit best when you track the same metrics every week, while NL2SQL fits one-off questions that nobody planned for, which a dashboard would need an analyst to handle. Asking across several databases is possible with cross-database querying. The two can work together: dashboards for recurring numbers, natural-language querying for ad hoc questions.
| Need | Dashboard | NL2SQL |
|---|---|---|
| The same ten metrics, every week | Best fit | Unnecessary |
| A one-off question nobody planned for | Needs an analyst | Best fit |
| Ask across several databases at once | Often needs a data project first | Possible with cross-database querying |
A team can use both: dashboards for the recurring numbers, and natural-language querying for the questions that arrive on a Tuesday afternoon.
PlaywithDB: our product, built on the same work
Our AI database platform, PlaywithDB, turns plain English into SQL with explainable steps and re-runnable queries, scans for GDPR, HIPAA, SOC2 and PCI-DSS issues, generates dashboards and queries across PostgreSQL, MongoDB, SQL Server and MySQL. If you need that capability inside your own system instead, we build it for you.
PlaywithDB is the AI database platform from PAI Technologies. It turns plain English into SQL with explainable steps and re-runnable queries, scans for GDPR, HIPAA, SOC2 and PCI-DSS issues, generates dashboards, and queries across PostgreSQL, MongoDB, SQL Server and MySQL. If you want the product, see the PlaywithDB page. If you need the capability inside your own system, we build it for you.
How a custom NL2SQL pilot runs
A pilot starts by freezing scope to one user journey, choosing the authentication model and drafting a golden question set. The build uses read-only roles, cites the tables behind each answer and logs requests. Hardening adds authentication, rate limits, personal data handling, logging and a runbook, before handover of repositories, infra notes and scripts.
Scope
Freeze one user journey, such as an analyst asking a question of PostgreSQL data, choose the authentication model and draft a golden question set, even 20 rows.
Build
Build the slice with read-only roles, cite the tables behind each answer and set expected behaviour on the golden set before polishing prompts. Log every request.
Harden
Add authentication, rate limits, personal data handling, structured logging and a runbook.
Hand over
Repositories, infra notes, evaluation scripts and a short walkthrough.
Governance: who can ask what
Treat natural-language access to live data as carefully as any other access. Sensible controls include read-only credentials with query limits and timeouts, schema visibility by role backed by database permissions, a log of generated queries showing who asked and when, and column descriptions and business definitions that help terms keep agreed meanings.
Natural-language access to live data needs the same care as any other access to it. These controls are sensible for such a system. None of them removes every risk, so test each one.
- Read-only credentials, with query limits and timeouts, to reduce the risk of a question changing data or overloading production
- Schema visibility by role, backed by database permissions, because hiding a table from the prompt does not by itself block access
- Every generated query logged with who asked and when, and stored so it can be re-run
- Column descriptions and business definitions supplied to the model, to help a word like revenue mean one agreed thing