← Latest papers
🤖 AI

GeoContra: From Fluent GIS Code to Verifiable Spatial Analysis with Geography-Grounded Repair

GeoContra is a verification and repair framework that enhances LLM-driven GIS workflows by enforcing geospatial contracts through static inspection, runtime validation, and semantic feedback loops, significantly improving the spatial correctness of generated Python code across diverse models and real-world tasks.

Original authors: Yinhao Xiao, Rongbo Xiao, Yihan Zhang

Published 2026-05-04
📖 4 min read☕ Coffee break read

Original authors: Yinhao Xiao, Rongbo Xiao, Yihan Zhang

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have a very talented, fast-talking assistant who loves to write computer code for maps. This assistant is great at sounding confident and producing code that looks perfect on the surface. However, if you ask them to calculate how long it takes to walk from a park to a hospital, they might accidentally write code that says the walk takes -5 minutes (negative time!) or measures the distance in "degrees" instead of "meters."

In the world of maps and geography, these mistakes are like a chef serving a delicious-looking cake that is actually made of soap. It looks right, but it's geographically impossible.

This paper introduces GeoContra, a new system designed to act as a strict, geography-savvy "quality control inspector" for these AI assistants. Here is how it works, broken down into simple concepts:

1. The Problem: "Fluent" but Wrong

Currently, AI models can write code that runs without crashing (it's "fluent"), but they often break the fundamental rules of geography. They might mix up map projections, ignore traffic rules, or calculate distances in ways that make no sense in the real world. Before this paper, there wasn't a good way to catch these specific geographic errors automatically before the results were used.

2. The Solution: The "Geographic Contract"

Think of GeoContra as a contract or a rulebook that the AI must sign before it starts working.

  • The Old Way: You ask the AI, "How do I find the nearest hospital?" and it just guesses the code.
  • The GeoContra Way: Before the AI writes a single line of code, the system gives it a detailed contract. This contract says: "You must use this specific map grid (CRS), you cannot use negative numbers for time, you must check the walking path (not a straight line), and your output must look like this specific list."

It's like giving a construction worker a blueprint that explicitly says, "Do not build the roof with ice," rather than just hoping they know better.

3. The Three-Step Inspector Team

Once the AI writes the code based on the contract, GeoContra runs it through a three-layer inspection process:

  • The Static Inspector (The Code Reviewer): This looks at the code before it runs. It checks for obvious red flags, like trying to measure a walking path using a ruler meant for flying birds, or using a field name that doesn't exist in the data.
  • The Runtime Inspector (The Test Driver): This actually runs the code. It checks if the output file was created, if the numbers make sense (e.g., no negative travel times), and if the file isn't corrupted.
  • The Semantic Inspector (The Logic Check): This asks, "Did you actually do what was asked?" If the task was to find the nearest hospital, but the code just listed all hospitals, this inspector catches that the AI took a shortcut and didn't solve the real problem.

4. The Repair Loop: "Try Again, But Smarter"

If the code fails any of these checks, GeoContra doesn't just say "Error." It sends a specific note back to the AI: "You tried to measure distance in degrees, but the contract said use meters. Also, you forgot to check the walking network. Please fix these specific errors and try again."

The AI then rewrites the code with these specific instructions in mind. This happens in a loop until the code passes all checks or the system runs out of attempts.

5. The Results: From "Maybe" to "Trustworthy"

The researchers tested this system on 7,079 real-world map tasks using data from 15 different areas around Boston (covering cities, suburbs, parks, and waterways). They tested it on 11 different AI models, including some of the most powerful ones available.

  • Without GeoContra: The AI models produced code that was geographically correct only about 47% to 57% of the time.
  • With GeoContra: The accuracy jumped to 77% to 81%.

Even for smaller, less powerful AI models, the system helped them become much more reliable, turning code that would have failed completely into code that worked correctly.

The Big Takeaway

The main point of this paper is that for AI to be useful in geography and city planning, it shouldn't just be judged on whether the code runs. It must be judged on whether the code makes geographic sense.

GeoContra turns AI from a "code generator" that might produce dangerous errors into a "verifiable analyst" that respects the rules of the real world. It ensures that when an AI says a hospital is 10 minutes away, that 10 minutes is actually based on a real walking path, not a mathematical glitch.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →