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

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 (defog/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

References (12)

02LangGraph:BuildLanguageAgentsasGraphs2024 · langchain-ai.github.io/langgraph/
03Spider:ALarge-ScaleHuman-LabeledDatasetforComplex andCross-DomainSemanticParsingandText-to-SQLTask2018 · Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing (EMNLP)
052024. SQLCoder: LLaMA-3-based Text-to-SQLhuggingface.co/ defog/llama-3-sqlcoder-8b
06Efficiency. Reduce overhead by learning policies for when to call tools, distilling orchestration strategies, and caching common queries or visualizations
07Call the naive SQLCoder tool to generate SQL
08Ablations and tool attribution. Quantify the marginal contribution of each tool (schema inspection, retries, visualizations) and identify minimal tool sets for robust performance
09If results are incomplete, empty, or erroneous: retry with refinements (e.g., rephrase, broaden categories, substitute bounding boxes)
10We provide a head-to-head evaluation against the naive base-line, showing large gains in accuracy ( 91.4% vs. 28.6% ) despite both relying on the same underlying SQL generator
11Harrison Chase and contributorsLangChain
12Each record captures a user identifier, place identifier, latitude, lon-gitude, semantic category name, and timestampthe dataset

Similar papers

© 2026 NYSGPT2525 LLC