Skip to content
Open access

NL2SQL+: An Extended Framework for SQL Generation With On-Demand Embedded ML Functions

2026 · IEEE Access · Vol 14, pp. 126645-126660 · 0 citations · 49 references

Abstract

Modern enterprise systems are increasingly adopting natural language (NL) interfaces for querying structured data. However, most natural language to SQL (NL2SQL) approaches focus on retrieval and aggregation over stored records, whereas many business queries require predictive computation through embedded machine learning (ML) functions. We introduce NL2SQL+, an extended NL2SQL framework for generating SQL with on-demand embedded ML functions. Given an NL query and database metadata, NL2SQL+ determines whether predictive ML is required, extracts a structured representation of the user intent, retrieves or selects a suitable ML model or function, and instantiates platform-specific training or inference SQL templates for database-native ML platforms. The framework consists of a Router for detecting ML-aware NL queries, an Extractor for intent parsing, a Model Explorer that uses an ML Model Pool for model/function selection, and a template-based SQL Generator targeting BigQuery ML and Postgres ML. We evaluate NL2SQL+ using platform-agnostic intent matching for structured intent extraction and by executing generated training SQL during ML Model Pool construction. The Router achieves an F1 score of 94%. For structured intent extraction, a fine-tuned small language model improves exact-match performance by 67.08% over OpenAI o1-mini and 9.77% over OpenAI o3-mini, and achieves nearly a fourfold gain compared with a direct LLM baseline using GPT-5-mini under the same metric. The empirical findings indicate that factorizing ML-aware SQL generation into four distinct stages—query routing, structured intent extraction, model or function selection, and template-guided SQL synthesis—enhances semantic controllability and token efficiency when formulating predictive natural language queries over database-native ML systems. These results are useful for database researchers, enterprise analytics teams, and practitioners who aim to provide natural-language access to predictive analytics over database-native ML platforms. The code, dataset, and prompts are available at https://github.com/simonjisu/NL2ML-SQL

Read PDF