Text-to-SQL with guardrails

The model writes SQL over a sample orders/customers database. A validator enforces read-only single SELECT, a table allowlist and a confidence gate before anything runs.

Guard: a strict parser-level allowlist (single plain SELECT, allowlisted tables/columns/functions/operators only - no subqueries, comments, loader functions or new-expressions), a 1000-char query cap and an enforced LIMIT of 200 rows. Rebuilt after review found the first guard bypassable.

Sample schema

customers(customer_id, name, city, signup_date, segment)
orders(order_id, customer_id, product, category, amount, order_date, status)