← all posts
Oct 08, 2025·9 min read·GenAI

NLP-to-SQL across 300+ tables: what actually works

Schema retrieval, few-shot assembly, and validation loops that make natural-language SQL actually reliable at scale.

//Why the naive version fails

Dump 300 tables into a prompt and ask for SQL, and you get confident nonsense — invented columns, wrong joins, cross-schema leakage. The model isn't the bottleneck; context selection is.

//Schema retrieval first

Each question first retrieves only the handful of relevant tables from an indexed schema store. The model sees a focused, correct slice of the warehouse — not all 300 tables — which is what makes the joins right.

//Validate, then repair

Generated SQL is parsed, dry-run, and checked against guardrails before it ever touches data. On error, the failure is fed back for a single repair pass. Reliability comes from the loop around the model, not the model alone.

▸ key result
300+tables across 20+ schemas served reliably — the architecture, not the prompt, is what scales.
AS
Akshayaram Swaminathan
builds AI products 0→1
← previous
A never-mutate browser agent for enterprise UIs