LLM-generated SQL can be correct yet leak data: separating query validity from authorization

awsamanai · reddit · 2026-09-14

A Reddit post highlights a key gap in NL2SQL systems: a syntactically correct query isn't necessarily an authorized one. In multi-tenant apps, an LLM can generate valid SQL that omits the tenant-restriction condition, exposing other tenants' data.

The proposed architecture inserts a structured intermediate layer: natural language → structured query → validation and policy checks → database execution, with the app independently enforcing tenant scope and field/operation policies, and asking for clarification on ambiguity. The author says the pattern works in production and open-sourced it as queryforge.

Original post →

More from coding & agent

coding & agent channel →