Language models asked chained geographic questions, such as "which schools lie within 500 meters of the river that crosses the county where the airport is," usually fail partway. They write a database query that runs but returns the wrong region, or one that returns nothing, or one that cannot be parsed. Today those failed attempts are thrown away. This proposal argues that in spatial databases a failed attempt is often a free, exactly correct training example. When a model's query runs against a geographic database, the database returns the true answer to the query the model actually wrote. Translating that executed chain back into a question gives a verified question–answer–reasoning triple, with no human label and no LLM judge.
The proposal uses this to close the multi-hop gap in spatial retrieval-augmented generation, meaning systems that fetch facts from an external store before answering. Spatial chain-of-thought, where the model writes intermediate coordinates and geometries into its reasoning, is what makes the relabeling exact: each hop's output is a concrete geometry the database can check. The central question is not whether hindsight relabeling helps. The question is whether relabeled failures help more than the obvious cheaper option, which is generating random executable queries and back-translating those.
Core Claim
Hindsight relabeling, meaning the reinterpretation of a failed attempt as a success at whatever it actually achieved, can be made verifier-exact in multi-hop spatial question answering. Each hop is an executable query over OpenStreetMap-style geometry, and the result of each hop is written into the reasoning trace as coordinates or entity identifiers.
From one failed chain we can extract three kinds of supervision.
- Relabeled full chains. The whole chain becomes the answer to a back-translated question.
- Relabeled prefixes. Hops $1..k$ executed correctly against the intended question before diverging at hop $k+1$, so the prefix is a valid $k$-hop example for the original question family.
- Contrastive pairs. At the divergence hop, the failed hop is paired with a repaired hop found by search.
The specific claim is that these near-miss examples, because they lie at the model's own error frontier, improve multi-hop spatial accuracy more per example than random synthetic programs of matched count and hop depth. The claim is especially about the hard operations of intersection and metric distance.
Where This Sits
Three papers motivate the gap.
- MapQA builds 3,154 OpenStreetMap questions across nine types. It shows that LLMs reach 100% on one-hop amenity questions but have their highest error rates on intersection and distance questions, often through malformed SQL. It diagnoses the failure but treats failed executions as dropouts. Our method treats those dropouts as raw material.
- Spatial-RAG translates questions into spatial SQL, scores candidates by geometry plus semantics, and filters them with a Pareto frontier. It operates in a single turn and depends on a proprietary model. We keep its SQL interface but make retrieval multi-hop and trained into an open-weight model.
- MultiHop-RAG shows that GPT-4 drops from 0.89 accuracy with gold evidence to 0.56 with retrieved evidence. This is the clearest evidence that intermediate retrieval, not final reasoning, is the bottleneck.
Two papers supply the method.
- AgentHER relabels failed web and tool trajectories. It reports +7.6–11.4% success after fine-tuning and parity with success-only training at half the successful data. However, it verifies relabels with a cross-model LLM judge and itself flags judge bias as a limitation. Execution against a database removes that judge entirely. That is the main technical difference, not just a change of domain.
- GRAT runs Monte Carlo tree search (repeatedly expanding and scoring partial reasoning paths) over text retrieval. Self-training a Llama3-8B on its successful trajectories lifts 2WikiMultiHopQA from 60.6% to 66.8%. It discards failed branches. We reuse its search to find repairs at divergence hops, and we keep the failed branches it throws away.
Two papers constrain the design.
- SCOUT shows that structured traces with explicit boxes and depth, trained with process rewards, beat free-form reasoning: its ablation removing tag-level credit loses nearly 3%. It also warns that rigid tag grammars are brittle. We therefore anchor only hop outputs, as geometry identifiers and coordinates, rather than imposing a full template.
- Artemis reports that purely linguistic intermediate reasoning can hurt perception. This is why the trace must carry geometry rather than prose.
Disentangling Extraction and Reasoning supports separating "what the hop retrieved" from "what is deduced." Executable hops enforce that separation by construction.
Research Program
Environment. We load the MapQA OpenStreetMap regions into PostGIS, a SQL database extension for geometric data. Our MapQA-Chain test split composes MapQA's single-operation types into two- to four-hop chains, where each hop's output geometry parameterizes the next. Gold answers are computed by executing hand-verified gold programs. MapQA itself contains multi-hop types, and those are evaluated unchanged as well. A small human audit checks that the composed questions read naturally.
Model and trace format. The model is an open-weight 8B model, matching GRAT's Llama3-8B for comparability. At each hop it emits a short rationale, a spatial query, and then a line recording the returned geometry IDs, centroid coordinates, and counts. This line is the spatial chain-of-thought. It is cheap to produce, it is checkable, and it is the handle relabeling needs.
Relabeling pipeline. We collect rollouts on training questions and classify each failure by hop:
- parse error
- empty result
- result that runs but disagrees with the gold intermediate geometry
For a chain that runs but is wrong, we back-translate the executed program into a natural-language question using templates seeded from MapQA's question types and paraphrased by the model. We keep it only if re-executing a fresh parse of the back-translated question reproduces the same result set. This round-trip check replaces AgentHER's judge.
Correct prefixes are relabeled as shorter questions. At the first wrong hop, a small tree search in the style of GRAT looks for a repair whose output matches the gold intermediate. The failed and repaired hops then form a preference pair, which is used for direct preference optimization (training the model to prefer one output over another).
Parse errors and empty results cannot be relabeled as positives. We keep them only as negatives in pairs. This tests the AdaMEM observation in AdaMEM that models struggle to learn from failures that come without counterfactual guidance.
Analysis. We will measure where relabeled examples sit relative to the original question distribution, by hop depth, operation type, and geometric scale. We will also measure whether gains concentrate on intersection and distance, the operations MapQA identifies as failing.
Baselines
Do-nothing reference. The base 8B model prompted few-shot with the same trace format and the same database tool. This establishes the floor and shows how much the trace format alone contributes.
Frontier single-turn system. The Spatial-RAG pipeline run with its proprietary parser and reranker on MapQA-ADJ, MapQA-AME, and our chain split. It is the strongest published spatial RAG system. Spatial-RAG reports only relative gains over its own baselines, not absolute scores: 32.0% NDCG on MapQA-ADJ, 52.6% NDCG and 75.4% recall on MapQA-AME, and 19.9% Precision@1 on TourismQA-NYC. We therefore rerun it rather than copy numbers. Beating it with an open 8B model on multi-hop chains, while staying within a few points on its single-hop home benchmarks, would count as success.
Success-only self-training. The method that most directly competes on this question. Rejection sampling plus GRAT-style tree search, fine-tuning only on chains that reach the gold answer. GRAT's reported analogue is 60.6% to 66.8% on 2WikiMultiHopQA for Llama3-8B, a text task, so there is no reported result on Lacuna for this baseline on spatial chains. It receives the same rollout budget, the same search budget, the same number of gradient steps, and the same hyperparameter sweep as our method.
Random-program synthesis. Sample executable multi-hop programs over the same database, back-translate them with the identical round-trip filter, and match the relabeled set in count and hop-depth histogram.
Ablations. These isolate each ingredient:
- relabeled full chains only
- relabeled prefixes only
- contrastive pairs only
- relabeling with an LLM judge instead of execution round-trip, which isolates the verifier
- removing the geometry line from the trace, which isolates spatial anchoring
Beating success-only self-training at equal compute is necessary. Beating random synthesis at equal count is what would make the near-miss claim true.
Why not just…?
Why not just train on successes, as rejection sampling does? This is the default, and on easy one-hop types it may be enough, since MapQA already shows 100% there. On hard chains, though, successes are rare. AgentHER notes that GPT-4o succeeds on under 15% of WebArena tasks, so rejection sampling discards most data, and relabeling matched success-only training with half the successes. Our success-only baseline at equal rollouts directly tests whether the same holds when the hard cases are intersections and distances.
Why not just generate random executable programs and back-translate them? This is the real threat. If execution makes relabels exact, it makes random synthesis exact too, and synthesis needs no failed rollouts. Our bet is distributional: failed chains concentrate on the operations, scales, and parameter choices the model actually gets wrong, while random programs spread effort uniformly. The matched-count comparison settles it. If random synthesis ties or wins, the honest conclusion is that the gain comes from executable back-translation and not from failure. We would report it that way and reframe failures as a cheap source of synthesis seeds. A mixed arm that seeds the random sampler with the failure-type distribution will show whether only the statistics of failures matter.
Why not just feed the error back at test time and let the model retry? Self-repair from execution errors handles parse errors and empty results cheaply, and may capture much of the gain on those. It cannot detect queries that run but return the wrong geometry, because nothing signals a problem. We include a retry loop with a matched retry budget as a test-time baseline and stack it on top of every trained model. Our method is supported only if the gain persists under retry and concentrates on silently wrong hops.
Why not just give a long-context frontier model all the data? FRIEDA found frontier models below 40% on multi-step map reasoning whether they were given only the needed maps or a larger set. MultiHop-RAG shows a 0.89 to 0.56 collapse when GPT-4 relies on retrieved rather than gold evidence. The Spatial-RAG baseline covers the strongest version of this alternative.
Decisive Checks
The primary metric is exact-match answer accuracy on MapQA-Chain, broken down by hop count and by operation type. Secondary metrics are hop-level intermediate accuracy, defined as Jaccard overlap of each hop's returned geometry IDs with gold, and the Spatial-RAG retrieval metrics on MapQA-ADJ, MapQA-AME, and TourismQA-NYC to confirm that single-hop ability is not lost.
The proposal succeeds if four things hold:
- Executable relabeling beats success-only self-training at equal compute, especially on intersection and distance chains.
- It beats random-program synthesis at equal example count.
- Replacing execution round-trip verification with an LLM judge measurably increases label noise, measured by hand audit, and lowers accuracy.
- Removing the coordinate line from traces removes most of the prefix-relabeling gain.
If only the first holds, the paper becomes a careful negative result on the value of failures relative to synthesis. That result is still worth knowing before others build hindsight pipelines for tool-using models.
References
- MapQA: Open-domain Geospatial Question Answering on Map Data
- Spatial-RAG: Spatial Retrieval Augmented Generation for Real-World Spatial Reasoning Questions
- MultiHop-RAG: Benchmarking Retrieval-Augmented Generation for Multi-Hop Queries
- AgentHER: Hindsight Experience Replay for LLM Agent Trajectory Relabeling
- GRAT: Guiding Retrieval-Augmented Reasoning through Process Rewards Tree Search
- SCOUT: Unlocking Enhanced Spatial Reasoning via Structured Chain-of-Thought and Multi-Objective Process Reward
- Artemis: Structured Visual Reasoning for Perception Policy Learning
- Disentangling Extraction and Reasoning in Multi-hop Spatial Reasoning
- AdaMEM: Test-Time Adaptive Memory for Language Agents
- FRIEDA: Benchmarking Multi-Step Cartographic Reasoning in Vision-Language Models