Read-Only Guardrails for Natural Language to SQL
AIBotFromFuture · reddit · 2026-07-16
This example demonstrates a Python/Flask app that converts natural language questions into SQL. However, the focus isn't on "letting the model execute SQL directly," but rather on adding read-only guardrails.
Core endpoints include:
- POST /query: Generates SQL based on the question and schema
- POST /query/sample: Generates and executes SQL on built-in SQLite sample data
- POST /validate: Performs a dry-run validation on the SQL
- GET /queries: Views recently generated queries
The guardrail strategies are explicitly defined:
- Allow read-only SQL only
- Reject multi-statements
- Reject comments
- Block INSERT, UPDATE, DELETE, DROP, ALTER, TRUNCATE
The author's point is that instead of letting an LLM execute SQL unchecked, it's better to have the model draft the query while the application layer validates and controls the final execution. The post includes a link to the code repository and technical docs.
More from coding & agent
- Claude Code skill uses 10 Markdown rules to make outputs ADHD-friendly — alex_verem · 2026-07-22
- A better path to agent autonomy is running waves, finding friction, and iterating — JnBrymn · 2026-07-22
- Coding agents are heading toward an AI-writes, AI-reviews, human-approves workflow — aftahi_ai · 2026-07-22
- oMLX 0.5.2 adds Mac menu-bar stats, low-bit decode kernels, and faster downloads — awnihannun · 2026-07-22
- GitHub review bot hits its PR limit and forces a 39-minute cooldown — DanielLockyer · 2026-07-22
- Max reasoning effort appears to be mobile-only in Codex Remote, not desktop — GabGarrett · 2026-07-22