A Secure and Efficient LLM-Based System for Natural Language Query-to-SQL Translation in IoT Data Management
Mario San Emeterio de la Parte, Yiting Wang, José-Fernán Martínez-Ortega, Néstor Lucas Martínez · IEEE Access · 2026
Structured data embodies vast reservoirs of actionable knowledge, yet non-technical users often lack the tools to effectively access or leverage these resources. This paper presents a novel middleware system architecture that harnesses Large Language Models (LLMs) to translate natural language queries (NLQs) into executable SQL statements, enabling seamless interaction with relational databases without requiring technical expertise. To bridge a critical gap in existing research, the proposed system integrates a robust security framework featuring multi-factor authentication and fine-grained, role-based access control. A comprehensive evaluation was conducted using over 813,000 real spatio-temporal IoT samples from the H2020-AFarCloud international project, comparing both general-purpose LLMs and models fine-tuned for NLQ-to-SQL translation. Two complementary evaluation metrics—Execution Accuracy (EX) and Valid Efficiency Score (VES)—were employed to assess syntactic correctness, semantic fidelity, and runtime efficiency. Experimental results show that GPT-o3 mini-high achieves the highest overall performance in terms of average VES, while DeepSeek R1 exhibits the most consistent behavior across heterogeneous query scenarios, as reflected by lower performance variability. These findings underscore the interplay between model capability and computational efficiency, demonstrating the potential of LLM-driven middleware to democratize structured data access and enhance data-driven decision-making.