All projects
LLM + Data

QueryWise

Governed text-to-SQL analytics assistant

Plain-English business questions become verified SQL, a table, a chart and a summary whose numbers are checked against the result — over a 45k-row e-commerce warehouse.

Live demo Source code
PythonsqlglotPostgreSQLpgvectorGeminiFastAPIDockerpytest

57/57

malicious queries blocked

0

false blocks

5 s

hard query timeout

274

automated tests

The problem

An LLM writing SQL can delete data, read personal information, or launch a query that freezes the database — and its summaries can quote numbers that are not in the result.

Architecture

  1. Question
  2. Schema linking
  3. LLM SQL draft
  4. AST guard
  5. Cost check
  6. Read-only execution
  7. Verified summary

How it works

  • Semantic layer of approved metric definitions, so “revenue” always means the same thing.
  • Embedding-based schema linking and few-shot examples ground generation in the real schema.
  • Bounded self-repair (at most two attempts) and clarifying questions for ambiguous requests.
  • Every number in the summary is verified against the query result.

Safety & reliability

  • SQL AST guard rejects anything but a single read-only SELECT.
  • Read-only database role limited to curated views without personal data.
  • EXPLAIN cost ceiling and a 5-second statement timeout stop runaway queries.

What I learned

Most of the safety lives outside the model: a parser, a database role and a cost check are cheaper and more reliable than asking the model to behave.