SLM-SQL: Efficient NL2SQL with Small LMs
- SLM-SQL is a framework using sub-10B parameter models to translate natural language into SQL with significant cost and computational efficiency.
- It employs a schema-aware, agentic architecture combined with supervised fine-tuning, reinforcement learning, and corrective self-consistency for improved accuracy.
- Empirical benchmarks show competitive execution accuracy and lower per-query costs, making SLM-SQL suitable for privacy-preserving and local deployments.
SLM-SQL refers to a rapidly evolving set of frameworks and methodologies that leverage Small LLMs (SLMs) for the task of translating natural language queries into SQL (NL2SQL), with an emphasis on computational efficiency, privacy, and cost-effective deployment. These approaches respond to the increasing computational and privacy concerns associated with LLM–centric systems, seeking to maintain competitive SQL generation accuracy while dramatically reducing overhead (Onyango et al., 25 Feb 2026, Sheng et al., 30 Jul 2025, Hoang et al., 5 May 2026).
1. Definitions, Landscape, and Motivations
SLM-SQL broadly designates a range of techniques and architectures that use SLMs (sub-10B parameter neural models) as primary actors in NL2SQL pipelines. Motivating this paradigm shift are concrete limitations of LLMs: high inference latency, substantial cost per query, regulatory barriers due to external API dependencies, and inability to efficiently deploy on-premises or at the edge. SLMs offer 5–20× lower memory usage, can be run locally, and facilitate near-zero operational costs for standard queries (Onyango et al., 25 Feb 2026, Sheng et al., 30 Jul 2025, Hoang et al., 5 May 2026).
The SLM-SQL literature centers on several families of approaches:
- Agentic, schema-aware NL2SQL: Modular pipelines where SLMs handle most queries, with LLM fallback on failure (Onyango et al., 25 Feb 2026).
- Post-training-enhanced SLMs: SLMs are adapted by supervised finetuning, reinforcement learning, and inference-time self-consistency (Sheng et al., 30 Jul 2025, Hoang et al., 5 May 2026).
- Hybrid privacy-preserving NL2SQL: Integration of SLM-based abstraction/preprocessing with LLM reasoning under strict privacy constraints (Abedini et al., 27 Sep 2025).
- Statistical-relational learning via SQL: Use of SQL as the programming substrate for learning statistical models over relational data (“SLM-SQL” in SRL) (Schulte et al., 2015).
- Extension to semantic SQL with model predicates: Embedding ML/LLM inference as first-class predicates/operators in SQL queries (Kumarasinghe et al., 23 Jan 2026).
2. Agentic Architectures and Schema Awareness
A prominent SLM-SQL instantiation is the schema-aware agentic system for NL2SQL generation (Onyango et al., 25 Feb 2026). Its architecture features:
- Controller/Orchestrator: Manages pipeline flow.
- Extractor Agent (SLM): Responsible for schema metadata retrieval and RAG-based enrichment.
- Decomposer Agent (SLM): Converts an NL query into a structured, stepwise execution plan using schema context.
- Generator Agent (SLM primary, LLM fallback): Initial SQL draft generation by SLM (Llama-3.1, 8B); if validation fails, a GPT-4-based LLM is invoked for up to 3 repair attempts.
- Validator & Executor Agent: Multi-stage validation: value checks, syntax, execution, semantics, all performed in a sandbox.
Prompt templates encode schema knowledge by listing tables, columns (with types and [PK/FK] markers), explicit relationship declarations, and natural-language data-dictionary notes. This schema-aware prompting is essential—a key insight is that carefully structured prompts can compensate for SLM deficiencies in schema linking and query disambiguation (Onyango et al., 25 Feb 2026).
3. Post-training and Correctional Methodologies
To address the inherent reasoning weaknesses of SLMs, several SLM-SQL pipelines combine data-centric post-processing with advanced training regimes:
- Supervised Fine-Tuning (SFT): Maximizing log-likelihood of chain-of-thought (CoT) plus SQL pairs (Sheng et al., 30 Jul 2025, Hoang et al., 5 May 2026).
- Reinforcement Learning (RL) with Group Relative Policy Optimization (GRPO): SLMs are further optimized using execution-based rewards, including dense, interpretable feedback (e.g., partial credit for SQL structure overlap and conformity to prior reasoning traces) (Hoang et al., 5 May 2026). The GRPO loss is:
where is relative advantage within sampled rollouts.
- Corrective Self-Consistency (CSC): At inference, SLMs sample multiple candidate SQLs, filter by execution equivalence, and, when needed, invoke a merge-revision model to reconcile discrepancies (Sheng et al., 30 Jul 2025).
- Specialization and Action Decomposition: Hierarchical pipelines split error correction into schema-only and logic-only stages, with each handled by a dedicated SLM operating over action-trajectories (e.g., pandas-like operator sequences) (Qu et al., 31 May 2025).
Ablation results highlight the absolute necessity of SFT, the additive value of RL (typically +4–5 EX points improvement), and the incremental benefit of CSC, especially on complex queries (Sheng et al., 30 Jul 2025, Hoang et al., 5 May 2026). Dense signal RL stabilizes training and avoids policy collapse, a weakness of sparse binary reward schemes (Hoang et al., 5 May 2026).
4. Performance, Benchmarks, and Trade-offs
SLM-SQL frameworks are empirically validated on large, complex datasets such as BIRD and Spider:
- Execution accuracy (EX)—fraction of predictions matching gold SQL’s execution result—is the standard metric.
- On BIRD-dev, SLMs in the 1.5–3B parameter range achieve 63–67% EX, within 5–10 points of 14–32B LLMs (Alpha-SQL, CodeS) (Sheng et al., 30 Jul 2025, Hoang et al., 5 May 2026).
- Agentic SLM-SQL systems (with fallback) resolve 67% of queries SLM-only, yielding an EX of 47.78% at 1/10th the cost of LLM-only approaches (average cost per query: $0.0085 vs$0.094) (Onyango et al., 25 Feb 2026).
- Dense RL (FINER-SQL) and merge-revision steps correct up to 30% of structural/semantic errors among remaining SLM failures (Hoang et al., 5 May 2026, Sheng et al., 30 Jul 2025).
A summary of key results on BIRD:
| System | Model Size | EX (%) | Typical Cost per Query |
|---|---|---|---|
| MAC-SQL (GPT-4) | >10B | 59.59 | $0.094 |
| SLM-SQL (Ours) | 8B | 47.78 | $0.0085 |
| SLM-SQL-1.5B | 1.5B | 67.08 | $0.00046 (CSC, k=64) |
| FINER-SQL-3B | 3B | 67.73 | ~5.57s/sample |
Critical trade-offs include:
- Model size vs. accuracy: Larger SLMs mitigate under-generation on complicated queries, but remain below best LLMs for deep nesting and exotic joins (Onyango et al., 25 Feb 2026, Sheng et al., 30 Jul 2025).
- Compute vs. performance: Higher candidate sample counts and more aggressive merge steps improve EX, but with sub-linear returns and higher inference latency (Sheng et al., 30 Jul 2025).
- Cost vs. privacy/coverage: Local SLM inference enables privacy preservation; the fallback mechanism can selectively relax this when strict correctness is required.
5. Privacy, Abstraction, and Hybrid SLM-LM Pipelines
SLM-SQL frameworks address privacy and data residency by deploying SLMs for sensitive processing stages:
- In privacy-constrained scenarios, abstraction (MaskSQL) is used to mask sensitive schema/value tokens (per policy π), generating abstract SQL via untrusted LLMs, followed by deterministic reconstruction (Abedini et al., 27 Sep 2025). This balances privacy (high masking recall, MR) with accuracy (execution accuracy up to 62.66% under category-based masking).
- All logic for linking, masking, and de-abstraction is performed locally by SLMs, ensuring that concrete data never leaves the controlled environment.
- Performance under strict privacy (full masking) trails state-of-the-art LLMs by ~20 EX points, but outperforms other trusted SLM-based methods by 5+ points on complex BIRD queries (Abedini et al., 27 Sep 2025).
6. Extensions: SLMs in SQL Engines and Statistical-Relational Learning
Beyond NL2SQL, SLM-SQL encompasses two advanced directions:
- Statistical-relational learning via SQL (FACTORBASE): All components—random variable metadata, sufficient statistics, model parameters—are directly represented as SQL tables/views, with all computation (join, aggregation, scoring, iterative structure search) executed as SQL queries (Schulte et al., 2015).
- Embedding ML/LLMs as first-class SQL operators: iPDB extends SQL with model-upload and LLM predicates, defining a minimal predict operator δ with explicit cost accounting and optimizer support. This allows for model predictions as semantic projections, selections, joins, and groupings, fully integrated into query planning and physical execution (Kumarasinghe et al., 23 Jan 2026).
Such systems emphasize the importance of optimizer-level awareness of inference cost, semantic-aware rewrites (e.g., deduplication, batching), and explicit operator algebra for integrating ML within declarative SQL. This lays the foundation for a generalized SLM-SQL paradigm where ML inference is a fundamental, cost-aware primitive within relational engines.
7. Current Limitations and Future Directions
Several open areas remain:
- SLM accuracy still lags LLMs on complex, deeply nested, or rare queries.
- RL post-training requires access to executable environments, and merge pipelines increase deployment complexity (Sheng et al., 30 Jul 2025).
- There are challenges in practical configuration (e.g., sample counts vs. latency), adaptive parameter tuning in hybrid privacy-precision trade-offs, and extending abstraction to structured outputs (e.g., JSON).
- Integration of structured CoT (structured query plans for distillation) further reduces syntactic errors and enhances student SLM reliability, indicating the promise of formalized reasoning steps (Thaker et al., 18 Dec 2025).
- Joint optimization of SLM and LLM fallback selection, as well as richer model catalog support (type-aware outputs, dynamic re-planning), remains a research frontier (Kumarasinghe et al., 23 Jan 2026).
SLM-SQL frameworks thus present a pragmatic and technically sophisticated alternative to LLM-centric NL2SQL, combining modular schema-aware agentic designs, dense RL-based post-training, privacy-preserving abstraction, and extensible integration into database systems, achieving cost-effective, deployable, and increasingly competitive SQL generation performance (Onyango et al., 25 Feb 2026, Sheng et al., 30 Jul 2025, Hoang et al., 5 May 2026, Schulte et al., 2015, Abedini et al., 27 Sep 2025, Kumarasinghe et al., 23 Jan 2026).