Ask in English,check the SQL
A text-to-SQL agent for the retail database from my retail analytics project. Business questions go in; an answer, a chart, the table and the SQL behind it come out. It only helps if it can be trusted, so it is built around two independent locks and measured against known answers.
DataUCI Online Retail II, about 1 million cleaned order lines, Dec 2009 to Dec 2011, in GBP. The agent sees 13 tables; scratch and raw tables are removed.
A question to a checked answer
Each dot is a question. Queries the guard rejects drop out and go back to the model with the reason, up to two retries; the rest run in a locked, read-only database. Click a stage to read what happens there.
Errors become feedback
If the guard or the database rejects a query, the error goes back to the model, which gets up to two more tries. API failures stop at once rather than retrying, so a broken key never loops.
Schema notesThe model is told an order is a distinct invoice, guest checkouts have no customer id, December 2011 is a partial month and percentages run from 0 to 100.
Either one alone blocks every write
The guard gives the model useful feedback. The connection is the real security boundary, and it holds even if the parser is fooled. In the tests, each lock on its own blocks every write and every file read.
SELECT.main, or CTEs built on them.read_csv and functions that touch files, settings or the environment.read_only=True, enable_external_access=false, then lock_configuration.Why bothA parser can be wrong about an edge case. A read-only connection with external access locked off can't be talked out of it.
Measured, not demoed
30 business questions, each with a hand-written gold query. The score is execution accuracy: the agent's rows must match the gold rows, with numbers within 0.5%, text ignoring case and dates by day. Extra columns, other names and other column orders are allowed.
StatusThe eval set and scorer are built and tested. Accuracy numbers aren't in the repo yet, so none are shown here.
For the long tail, not the dashboard
Built onThe cleaning and modelling SQL from the retail analytics case study, so the agent answers over tables already checked by hand.