This guide is for engineering and data leads who want managers to ask a database questions in plain language without risking the data. It sits in our generative AI development work, and it assumes the tables and metric definitions are already in reasonable shape; if they are not, start with data engineering.
In this guide
- Why do text-to-SQL assistants fail on real company databases?
- What schema context should the model see?
- Which guard layers keep the assistant read-only?
- How do you design an accuracy benchmark?
- Where AI fits
- What delivery record exists, and what does not?
- Alternatives: when is a custom assistant the wrong choice?
- What are the limits of this guide?
- Frequently asked questions
- Next step
Why do text-to-SQL assistants fail on real company databases?
They fail mainly because the model does not know what the business means by its tables, not because it cannot write SQL. A column called status with codes 3, 7 and 9, two revenue tables that disagree, and a fiscal year that starts in April are invisible in a raw schema dump, so the model writes valid SQL that answers the wrong question.
Public benchmarks show the size of the gap. The Spider 2.0 benchmark uses 632 workflow problems from enterprise databases that often hold more than 1,000 columns, and its authors report that a strong commercial model solving most tasks of the older academic benchmark solved only about one in ten of these. The BIRD benchmark, with 12,751 question and SQL pairs over 95 databases, puts human data engineers at about 93% execution accuracy, a useful ceiling to remember when someone promises a perfect assistant.
The practical reading for a buyer: the hard part is context and testing on your own schema. Model choice matters less than what the model is shown and how its output is checked.
What schema context should the model see?
The model should see a small, curated slice of the schema, written for a person who has never worked at the company. A dump of every table adds noise, leaks names of tables staff should not query and raises cost.
A context pack that works usually holds:
- Approved tables and views only, preferably modelled views over raw tables, each with a one-line purpose.
- Column descriptions with real values, for example that
status = 7means shipped, and the unit of every amount. - Join paths the business trusts, written out, so the model does not invent a join on two columns that only look alike.
- Metric definitions such as net revenue or active customer, ideally generated from the metrics layer rather than typed by hand.
- A handful of verified question and SQL pairs close to the question asked, selected by search at run time.
- Dialect notes for the database engine, since date and string functions differ.
When the schema is large, retrieval picks the relevant tables per question, the same problem as document retrieval; our guide to retrieval quality tuning covers the search side. Google Cloud's engineering notes on text-to-SQL describe the same pattern: schema annotations, similar examples and business rules retrieved per question, plus clarifying questions when intent is ambiguous.
Which guard layers keep the assistant read-only?
Treat every generated query as untrusted input. OWASP lists excessive agency as a top risk for LLM applications and recommends limiting an extension's database permissions to the minimum, such as read access to the needed tables only. No single layer is enough, so the matrix below shows what each one stops and what it misses.
| Layer | What it stops | What it misses |
|---|---|---|
| Database role with SELECT on approved views only | Writes, schema changes and reads of tables outside the allowlist, whatever SQL the model writes | Expensive queries, and sensitive columns left inside an approved view |
| Read-only transaction and statement timeout | Writes that slip past a role mistake; runaway queries that hold the database | Reads of data the role can see but the user should not |
| Statement parser and allowlist in code | Multiple statements, functions on a deny list, unknown tables, missing row limits; gives a clear refusal message | Logic errors and queries that are valid but wrong |
| Row-level filters per user | One manager seeing another region's or client's rows | Aggregates that reveal small groups; needs the user identity passed through |
| Audit log of question, SQL, user and result size | Nothing at run time; makes every answer reviewable and supports incident review | Harm already done, so it never replaces the layers above |
In PostgreSQL, for example, default_transaction_read_only makes each new transaction read-only and statement_timeout aborts a statement that runs too long, as the PostgreSQL client configuration documentation describes; column-level GRANT SELECT limits a role to named columns. Other engines have equivalents. The rule we apply is that the database itself must refuse a write even if every check in code fails.
How do you design an accuracy benchmark?
-
Collect real questions
Ask the future users for 100 to 200 questions they would type, in their own words, and keep the vague ones.
-
Sort them into four classes
Answerable, ambiguous (needs a clarifying question), unanswerable from the data (should be refused) and forbidden (asks for data the user may not see or for a change). The last two classes test safety, not SQL skill.
-
Write reference answers with a data owner
For each answerable question, store the reference SQL and its result on a frozen snapshot of the data, signed off by the person who owns that metric.
-
Score by execution, then review the misses
Compare result sets, not SQL text; allow column order and naming to differ. Execution match can accept a wrong query that happens to return the right rows, so a person reviews a sample of passes too.
-
Record each failure by type
Wrong table, wrong join, wrong filter or period, wrong metric definition, refused when it should answer, answered when it should refuse. The counts per type tell you whether to fix context, guards or the model.
-
Set release thresholds per class
For example, every forbidden question refused, every unanswerable question refused or clarified, and an agreed accuracy level on answerable ones.
-
Re-run on every change
Any change to the schema, the context pack, the prompt or the model version re-runs the full set before release; add each production miss as a new test.
A general evaluation harness for AI agents gives the scaffolding; the text-to-SQL part is the four classes, the frozen data snapshot and the execution comparison. Before launch, a red-team exercise tries to break the read-only guards on purpose.
Where AI fits
AI writes the SQL, proposes clarifying questions and helps draft the first version of the context pack and benchmark questions. Engineers still own the role and grants, the parser rules, the reference answers and the release decision. Netbase works with commercial and open-weight models, chosen per project.
- In delivered work
RAG knowledge assistant
A retrieval-augmented assistant that answers from company knowledge, the closest delivered pattern to schema retrieval; the client is not named.
- In delivered work
4over4 recommendation engine
Product suggestions from browsing history and previous purchases, the named AI feature Netbase delivered with a client.
- Available capability
Text-to-SQL assistants with read-only guards
Context packs, guard layers and benchmark design as described on this page; not yet tied to a published case.
What delivery record exists, and what does not?
- What exists. Netbase has delivered retrieval-augmented knowledge assistants, document AI and MLOps pipelines for clients that are not named, and the named 4over4 recommendation engine. It works with the major commercial and open-source models, chosen per project. Most Netbase projects are delivered on fixed-price contracts.
- What does not. No published Netbase case describes a delivered text-to-SQL assistant, and no accuracy, speed or cost figure from client work is offered here. The guard matrix and benchmark steps are method guidance; the figures on this page come from the cited benchmarks.
Alternatives: when is a custom assistant the wrong choice?
A custom text-to-SQL assistant is one option among several. Choose by these criteria: how varied the questions are, who asks them, how sensitive the data is and how mature the data model is.
- Fixed reports with parameters win when most questions are the same dozen with different dates or regions. They are exact, cheap to test and need no model.
- The assistant built into your BI tool wins when the company already runs a modelled BI layer and the questions stay inside it. You inherit its guards, but check its row-level security and test it with the same four question classes.
- A metrics layer with a query API wins when several tools and teams need the same numbers; an assistant can sit on top later.
- Do not build at all when the data model is not trusted yet. An assistant over messy tables gives fast, confident wrong answers, and fixing the data first is the better spend.
A custom assistant fits when questions vary widely, span several systems, need company-specific rules or must feed another application through an API.
What are the limits of this guide?
- It covers read-only question answering; an assistant that writes data needs approval steps beyond this page.
- Benchmark figures quoted here come from public research datasets and do not predict accuracy on your schema.
- Guard examples use PostgreSQL terms; check the equivalent settings on your engine.
Plan the next step with a Netbase consultant
Frequently asked questions
Not if the database role it uses has read access only to approved views and every session runs in read-only mode. Checks in code add clearer refusals, but the database itself must reject a write even when a generated query slips past every other check.
Agree the threshold per question class with the data owners before testing starts. Forbidden and unanswerable questions should be refused every time, while the accuracy level for answerable questions depends on how the answers are used and whether a person reviews them.
Usually not at the start. Better schema context, verified example queries and clarifying questions fix most failures; fine-tuning, or a small model trained for the task, becomes worth testing when the benchmark shows the same error type persisting after the context is right.
Re-run the full benchmark whenever the schema, the context pack, the prompt or the model version changes, and add every confirmed production miss to the set so the same mistake cannot return unnoticed.
Next step
Send us the questions your managers ask today and a description of the tables behind them, and we will book a solution review to sketch the context pack, the guard layers and a first benchmark. For assistants that answer from documents rather than tables, see enterprise knowledge and RAG, and for monitoring once live, responsible AI and MLOps.
Related services and solutions
Generative AI development with evaluation and human review Netbase builds generative AI features for product and operations teams: drafting, summarising, rewriting and content generation inside the software your people and customers already use. Every feature ships with an evaluation set, a human review step where output matters and limits on cost. Generative AI is a capability we are growing, and we label its maturity honestly.
Learn More
Data engineering platforms for reporting and AI Netbase builds data pipelines and analytics foundations for companies whose data is spread across a store, an ERP, a CRM and spreadsheets. We collect it, clean it, model it and check its quality, so reports agree with each other and AI projects start from data people trust. Data engineering is a capability we are growing alongside the platforms we deliver.
Learn More
Responsible AI and MLOps for AI in production MLOps and responsible AI keep an AI feature trustworthy after launch. Netbase's practice for monitored, governed AI in production covers evaluation before every release, versioning of models, prompts and data, monitoring of quality and cost, and incident controls with a named owner. It is a growth capability, backed by an MLOps pipeline delivered for an unnamed client.
Learn More
AI knowledge assistant: answers from company knowledge, with sources and access control An AI knowledge assistant is an internal tool that answers employees' questions from your company's own documents and systems, cites the source behind every answer and shows each person only what they may see. Netbase offers it as a growth capability, designed with retrieval, evaluation and human review from the first pilot, and has delivered one for an unnamed client.
Learn More
Work with Netbase remotely
Every Netbase engagement is delivered remotely, so clients in any country and any industry can work with us; Netbase has worked with clients in 80 countries. Contracts and invoices are issued by Netbase JSC, and payment is made by bank transfer to Netbase JSC's company account or PayPal Business. Talk to the CEO, Huy Nguyen (David), on WhatsApp or by email.
Discuss a project
Netbase JSC helps organizations design, build, modernize, and operate digital products and AI-enabled business systems.project@netbasejsc.com
+84 937 869 689
91 Nguyen Chi Thanh, Dong Da, Hanoi, Vietnam
Get in touch
Tell us what you want to build, modernize, or operate.