Chat with your database: a practical guide, not a product pitch
By Arshad Ansari
"Ask your data a question in plain English" demos beautifully and disappoints in production. The demo works because someone picked a clean schema and a friendly question. Making it genuinely useful for a non-technical team — reliably, safely, on your real database — is the other 80%. Here's what that 80% is.
What it actually is
Under the hood, "chat with your database" is: take a plain-English question, use an LLM to turn it into SQL, run the SQL, return the answer. The translation step is the easy part now — models are good at SQL. Everything that makes it trustworthy sits around that step.
What separates useful from garbage
1. Give the model your semantics, not just your schema. This is the number-one thing. A model handed raw table and column names guesses at meaning — and guesses wrong. rev, revenue, and net_rev are different things, and only you know that "active user" means "logged in within 30 days." The fix is a semantic layer: business definitions, column meanings, metric definitions, relationships. Feed the model what your data means, and answers go from plausible-nonsense to correct.
2. Curate the surface. Don't point it at 400 raw tables. Give it a curated set of clean views built for questions — the same move that makes it safe (see connecting an LLM to your database safely) also makes it accurate. A small, well-named, well-documented surface produces far better SQL than the full internal schema.
3. Always show the SQL. For a non-technical user this feels counterintuitive, but it's essential: never make it a black box. Show the query it generated and the assumptions it made. It builds trust, it lets a technical person spot-check, and it turns a wrong answer into a teachable correction instead of a silent mistake someone acts on.
4. Guardrails, always. Read-only access, query timeouts, row caps. A natural-language interface is a natural-language interface to your database — the safety rules from the previous piece are not optional here.
5. Plan for confident wrong answers. The failure mode that hurts is the model returning a clean, confident, wrong number. Defences: show the SQL and the assumptions, prefer "I'm not sure, here's what I'd need" over a fabricated answer, and validate against known-good results. A tool that occasionally says "I can't answer that reliably" is worth more than one that always answers and is sometimes wrong.
6. Build a feedback loop. Capture the corrections. When someone fixes a bad query, that becomes a validated example the system reuses. Over a few weeks a curated library of trusted questions-and-queries does more for accuracy than any prompt tweak.
When it's worth building — and when it isn't
Be honest about the alternative. If the questions people ask are the same ten every week, a good dashboard answers them faster and more reliably than any chatbot. Natural-language querying earns its keep for the long tail — the ad-hoc, one-off questions nobody built a dashboard for, asked by people who can't write SQL. Build it for exploration, not for questions a dashboard already nails.
How I approach it
A useful "chat with your database" is a data-modelling and guardrails problem wearing an AI hat. The model is the easy 20%; the semantic layer, the curated views, the verification and the safety are the work — and they're exactly the kind of thing I build as AI Automation, on the same principles as AEGIS: scoped access, human oversight where it matters, nothing that acts without a check. The scoping call below is free.
Building something data-heavy?
I build lean data platforms and AI automation for a living — three live systems, internals public. The first step is a short call about what you're trying to build.
Book a free 30-minute scoping callNot ready to talk? Take the free book — Local-First Analytics, on cutting data-infrastructure cost the local-first way.