GeoContra: From Fluent GIS Code to Verifiable Spatial Analysis with Geography-Grounded Repair
Yinhao Xiao, Rongbo Xiao, Yihan Zhang
TLDR
GeoContra verifies and repairs LLM-generated GIS code, significantly improving spatial correctness by enforcing geographic rules and catching common errors.
Key contributions
- Introduces GeoContra, a framework for verifying and repairing LLM-generated Python GIS code.
- Defines tasks using 'geospatial contracts' that specify rules, schemas, and expected outputs.
- Applies static inspection, runtime validation, and semantic verification with an automated repair loop.
- Boosts spatial correctness of LLM outputs by an average of 26.6% across 11 open models.
Why it matters
LLMs can generate GIS code, but it often lacks geographic reliability, leading to incorrect spatial analysis. GeoContra addresses this by ensuring generated code adheres to critical geographic rules. This advancement makes LLM-driven GIS workflows more trustworthy and practical for real-world applications.
Original Abstract
Reliable spatial analysis in GIScience requires preserving coordinate semantics, topology, units, and geographic plausibility. Current LLM-based GIS systems generate fluent scripts but rarely enforce these geographic rules at scale. We present GeoContra, a verification and repair framework for LLM-driven Python GIS workflows. It represents each task as an executable geospatial contract-including natural-language questions, schemas, CRS metadata, expected outputs, spatial predicates, topology, metrics, required operations, and forbidden shortcuts. Generated programs undergo static rule inspection, runtime validation, and semantic verification, with violations fed back into a bounded repair loop. Evaluated on 7,079 real geospatial tasks across 15 Boston-area zones, 9 task families, and 11 open-source models (600 runs each), GeoContra improves spatial correctness on closed models from 47.6% to 77.5% for DeepSeek-V4 and from 57.7% to 81.5% for Kimi-K2.5. Across 11 open models, average correctness rises by 26.6%. GeoContra turns fluent code production into verifiable spatial analysis, catching negative travel times, CRS/field-schema violations, missing predicates, and brittle output casts that otherwise yield executable but geographically invalid results.
📬 Weekly AI Paper Digest
Get the top 10 AI/ML arXiv papers from the week — summarized, scored, and delivered to your inbox every Monday.