Table of Contents
Fetching ...

AskDB: An LLM Agent for Natural Language Interaction with Relational Databases

Xuan-Quang Phan, Tan-Ha Mai, Thai-Duy Dinh, Minh-Thuan Nguyen, Lam-Son Lê

TL;DR

AskDB addresses the challenge of making relational databases accessible to users with varying expertise by unifying data analysis and administrative tasks under a single LLM-powered agent built on Gemini 2. It introduces a ReAct-based framework and dynamic schema-aware prompting to ground natural language queries in complex database schemas, enabling autonomous multi-step SQL generation and problem solving with automated safety guardrails. Empirical results show strong performance on Spider 1.0 (89.8% execution accuracy) and more modest results on Spider 2.0 (36.3%), highlighting both feasibility and current limitations in handling deeply nested queries. The work suggests practical, cost-efficient database co-pilot capabilities with real-world deployment potential, while identifying future work in provider-agnostic architectures, broader benchmarking, and self-hosting options.

Abstract

Interacting with relational databases remains challenging for users across different expertise levels, particularly when composing complex analytical queries or performing administrative tasks. Existing systems typically address either natural language querying or narrow aspects of database administration, lacking a unified and intelligent interface for general-purpose database interaction. We introduce AskDB, a large language model powered agent designed to bridge this gap by supporting both data analysis and administrative operations over SQL databases through natural language. Built on Gemini 2, AskDB integrates two key innovations: a dynamic schema-aware prompting mechanism that effectively incorporates database metadata, and a task decomposition framework that enables the agent to plan and execute multi-step actions. These capabilities allow AskDB to autonomously debug derived SQL, retrieve contextual information via real-time web search, and adaptively refine its responses. We evaluate AskDB on a widely used Text-to-SQL benchmark and a curated set of DBA tasks, demonstrating strong performance in both analytical and administrative scenarios. Our results highlight the potential of AskDB as a unified and intelligent agent for relational database systems, offering an intuitive and accessible experience for end users.

AskDB: An LLM Agent for Natural Language Interaction with Relational Databases

TL;DR

AskDB addresses the challenge of making relational databases accessible to users with varying expertise by unifying data analysis and administrative tasks under a single LLM-powered agent built on Gemini 2. It introduces a ReAct-based framework and dynamic schema-aware prompting to ground natural language queries in complex database schemas, enabling autonomous multi-step SQL generation and problem solving with automated safety guardrails. Empirical results show strong performance on Spider 1.0 (89.8% execution accuracy) and more modest results on Spider 2.0 (36.3%), highlighting both feasibility and current limitations in handling deeply nested queries. The work suggests practical, cost-efficient database co-pilot capabilities with real-world deployment potential, while identifying future work in provider-agnostic architectures, broader benchmarking, and self-hosting options.

Abstract

Interacting with relational databases remains challenging for users across different expertise levels, particularly when composing complex analytical queries or performing administrative tasks. Existing systems typically address either natural language querying or narrow aspects of database administration, lacking a unified and intelligent interface for general-purpose database interaction. We introduce AskDB, a large language model powered agent designed to bridge this gap by supporting both data analysis and administrative operations over SQL databases through natural language. Built on Gemini 2, AskDB integrates two key innovations: a dynamic schema-aware prompting mechanism that effectively incorporates database metadata, and a task decomposition framework that enables the agent to plan and execute multi-step actions. These capabilities allow AskDB to autonomously debug derived SQL, retrieve contextual information via real-time web search, and adaptively refine its responses. We evaluate AskDB on a widely used Text-to-SQL benchmark and a curated set of DBA tasks, demonstrating strong performance in both analytical and administrative scenarios. Our results highlight the potential of AskDB as a unified and intelligent agent for relational database systems, offering an intuitive and accessible experience for end users.

Paper Structure

This paper contains 22 sections, 8 figures, 2 tables.

Figures (8)

  • Figure 1: Illustration for the advantage of AskDB compared to traditional approach.
  • Figure 2: High-level conceptual architecture diagram of AskDB.
  • Figure 3: The ReAct-based operational framework of AskDB. The agent iteratively cycles through reason, act, and observe phases, driven by an LLM, to execute tasks.
  • Figure 4: Step-by-step diagnostic reasoning process for identifying and resolving slow-running database queries. The system investigates recent logs, analyzes execution plans, identifies a full table scan on the orders table, and proposes indexing the "order_date" column as a potential optimization.
  • Figure 5: The dynamic schema-aware prompting mechanism. The agent uses semantic search to identify relevant tables and injects only their scoped schema information into the prompt, grounding the LLM in the current database context. This RAG-like approach mitigates challenges with large schemas and improves query accuracy.
  • ...and 3 more figures