Table of Contents
Fetching ...

From Queries to Insights: Agentic LLM Pipelines for Spatio-Temporal Text-to-SQL

Manu Redd, Tao Zhe, Dongjie Wang

TL;DR

This work tackles natural-language interfaces to geospatial databases for spatio-temporal queries. It presents an agentic NL-to-SQL pipeline that embeds a naive SQL generator inside a ReAct-inspired controller with schema grounding, task decomposition, and visualization. On NYC and Tokyo check-in data, it achieves 91.4% correctness (32/35) versus 28.6% for the naive baseline, illustrating the value of orchestration. The approach yields more natural human–database interactions by providing maps, plots, and text summaries, and it offers practical design guidelines for building robust geospatial NL-to-SQL assistants.

Abstract

Natural-language-to-SQL (NL-to-SQL) systems hold promise for democratizing access to structured data, allowing users to query databases without learning SQL. Yet existing systems struggle with realistic spatio-temporal queries, where success requires aligning vague user phrasing with schema-specific categories, handling temporal reasoning, and choosing appropriate outputs. We present an agentic pipeline that extends a naive text-to-SQL baseline (llama-3-sqlcoder-8b) with orchestration by a Mistral-based ReAct agent. The agent can plan, decompose, and adapt queries through schema inspection, SQL generation, execution, and visualization tools. We evaluate on 35 natural-language queries over the NYC and Tokyo check-in dataset, covering spatial, temporal, and multi-dataset reasoning. The agent achieves substantially higher accuracy than the naive baseline 91.4% vs. 28.6% and enhances usability through maps, plots, and structured natural-language summaries. Crucially, our design enables more natural human-database interaction, supporting users who lack SQL expertise, detailed schema knowledge, or prompting skill. We conclude that agentic orchestration, rather than stronger SQL generators alone, is a promising foundation for interactive geospatial assistants.

From Queries to Insights: Agentic LLM Pipelines for Spatio-Temporal Text-to-SQL

TL;DR

This work tackles natural-language interfaces to geospatial databases for spatio-temporal queries. It presents an agentic NL-to-SQL pipeline that embeds a naive SQL generator inside a ReAct-inspired controller with schema grounding, task decomposition, and visualization. On NYC and Tokyo check-in data, it achieves 91.4% correctness (32/35) versus 28.6% for the naive baseline, illustrating the value of orchestration. The approach yields more natural human–database interactions by providing maps, plots, and text summaries, and it offers practical design guidelines for building robust geospatial NL-to-SQL assistants.

Abstract

Natural-language-to-SQL (NL-to-SQL) systems hold promise for democratizing access to structured data, allowing users to query databases without learning SQL. Yet existing systems struggle with realistic spatio-temporal queries, where success requires aligning vague user phrasing with schema-specific categories, handling temporal reasoning, and choosing appropriate outputs. We present an agentic pipeline that extends a naive text-to-SQL baseline (llama-3-sqlcoder-8b) with orchestration by a Mistral-based ReAct agent. The agent can plan, decompose, and adapt queries through schema inspection, SQL generation, execution, and visualization tools. We evaluate on 35 natural-language queries over the NYC and Tokyo check-in dataset, covering spatial, temporal, and multi-dataset reasoning. The agent achieves substantially higher accuracy than the naive baseline 91.4% vs. 28.6% and enhances usability through maps, plots, and structured natural-language summaries. Crucially, our design enables more natural human-database interaction, supporting users who lack SQL expertise, detailed schema knowledge, or prompting skill. We conclude that agentic orchestration, rather than stronger SQL generators alone, is a promising foundation for interactive geospatial assistants.

Paper Structure

This paper contains 32 sections, 3 figures, 2 tables.

Figures (3)

  • Figure 1: Agentic pipeline for spatio-temporal Text-to-SQL. The ReAct-style agent plans, calls tools (schema, SQL generation, execution, file read, plotting, mapping), observes results/errors, and returns a summarized answer with links to figures/maps. The "Action" and "Observation" arrows in the diagram between the agent and the tool set represent the ReAct chain of thought loop where the agent plans, acts, and observes repeatedly. The Generate SQL Query tool in the tool set is the same llama-3-sqlcoder-8b model that makes the backbone of the naive pipeline.
  • Figure 2: Hourly check-ins (line plot) generated by the agent for Q30: "How does check-in activity change across different times of day?". The agent produced this visualization without explicit request from the user.
  • Figure 3: Agent-generated heatmap of gym locations for Q16: "Where are most gyms located?". The agent produced this visualization without explicit request from the user. Dynamic generation of a heatmap demonstrates the agent's ability to capture the intent of the user question.