Safety
Text-to-SQL with guardrails
Read-only queries, row limits, schema-grounded columns and an entity map from business terms to columns.
The problem
Letting an LLM write SQL against a production database is risky: it can write unsafe queries, invent columns, or misread business words.
The approach
- SELECT-only queries, and every query gets a row limit.
- The schema (with column descriptions) is the only source of truth for column names.
- An entity-resolution table maps business words (team, leader, service) to the right columns and values.
- Default filters apply business rules, and the agent suggests follow-up questions.
What I learned
- Guardrails belong in both the prompt and the code; never trust only one layer.
- Most wrong answers come from ambiguous business terms, not from SQL syntax.