TL;DR
When we ask Large Language Models (LLMs) to discover new algorithms, we usually grade their code with a single numeric score—like how many unit tests passed—leaving the model to guess why it failed. By borrowing a trick from formal verification, the authors instead give the LLM concrete counterexamples whenever its code violates a formal mathematical property. Applied to classical AI planning, this feedback loop slashes compute costs by an order of magnitude and produces heuristic functions so reliable they can march straight to a solution without ever backtracking.
What Problem Does This Paper Address?
Imagine debugging code where the compiler only tells you "Score: 42/100" instead of giving you a stack trace. That is how most LLM-based program synthesis works today: systems generate dozens or hundreds of candidate programs, run full evaluations on all of them, and rank them by a numeric fitness score. Because a raw number offers zero insight into how a program went wrong, you burn massive amounts of LLM inference and evaluation time just hoping to get lucky.
The authors tackle this inefficiency in the arena of classical planning—finding a sequence of actions to get from an initial state to a goal (like routing logistics vehicles or solving Sokoban puzzles), typically described in PDDL (Planning Domain Definition Language). Rather than asking an LLM to solve every puzzle from scratch (which is expensive and prone to hallucination), we want the LLM to write a single Python heuristic function—a compass that estimates how close any state is to the goal—for an entire problem domain.
Usually, planners rely on heavy search algorithms like Greedy Best-First Search (GBFS) to maintain huge queues of backup states in case the heuristic gets stuck in a local minimum or plateau. The authors ask: can we use rich, structural feedback to guide an LLM to write heuristics that never get stuck?
Methods
Instead of "sample-and-select" (generating a fixed pool of candidates and picking the highest scorer), the authors adapt Counterexample-Guided Inductive Synthesis (CEGIS) from formal methods.
They ask the LLM (testing Gemini 3.1 Pro, GPT-5.5, and open-weight Gemma 4 31B) to write a Python heuristic satisfying the direct property. A heuristic is direct if every non-goal state you can reach from the start by strictly improving steps also has at least one strictly improving next step (and avoids dead ends). Unlike stricter global rules that require every possible state in the universe to point downhill, a direct heuristic only cares about the paths a greedy algorithm would actually walk:
Here is how the synthesis loop works:
- Propose: The LLM writes one candidate Python heuristic for a planning domain.
- Validate & Stop Early: A validator runs Depth-First Search on small training tasks to check the direct property. The moment it hits any state where no successor strictly lowers the heuristic value (or hits a dead end), validation halts immediately.
- Repair: The validator hands the LLM a concrete counterexample—the exact failing state, its heuristic score, and all its successor states with their scores—alongside the history of previous attempts, asking for a repaired heuristic.
Once a heuristic passes the training set, it is deployed on massive test tasks using Hill Climbing (HC)—a dead-simple, memory-light local search that greedily steps downhill without keeping a backup queue or backtracking.
Datasets
- IPC 2023 Learning Track: Ten standard planning domains (e.g., Blocksworld, Sokoban, Rovers, Satellite). Training tasks are tiny (e.g., up to 4 boxes in Sokoban or 20 cars in Ferry), while the 900 test tasks (90 per domain) are aggressively out-of-distribution, scaling up to 79 boxes or 974 cars.
- Three Newly Created Domains: To prove the LLM isn't just reciting memorized textbook solutions, the authors built Cisterns (water siphon puzzles), Orrery (coupled mechanical wheels), and Qubit Routing (swapping logical qubits on a hardware graph)—domains that did not exist publicly when Gemini 3.1 Pro was trained.
Key Insights and Ideas
- Stopping early makes failure cheap: Instead of running full searches across an entire training suite for 25 candidates, halting at the very first counterexample turns hours of wasted evaluation into seconds.
- Numeric scores don't teach structure: In an ablation study (
Cov.), the authors ran the exact same iterative repair loop, but only told the LLM which task timed out and how many states were expanded. Without state-level counterexamples, the resulting heuristics collapsed when paired with Hill Climbing. - Small-scale verification generalizes remarkably well: Checking a formal property on toy problems forces the LLM to fix fundamental logical bugs—like detecting cyclic deadlocks between blocks in Blocksworld or respecting action-ordering constraints in Satellite—allowing the code to generalize to massive test puzzles.
Key Results
On the 900 out-of-distribution IPC test tasks using Gemini 3.1 Pro:
- Higher accuracy without search: Direct heuristics with simple Hill Climbing solved 623.3 tasks on average, beating the state-of-the-art LLM sample-and-select baseline using full GBFS (573 tasks) and the classic domain-independent FF heuristic (298 tasks).
- Massive synthesis speedups: The repair loop needed 7.4× fewer LLM calls (3.4 candidates per domain vs. 25) and spent ~40× less time evaluating training tasks (33.1 minutes vs. 1,339.8 minutes).
- Near-zero getting stuck: Across 2,700 out-of-distribution test runs (including PSPACE-complete Sokoban), Hill Climbing got stuck in a local minimum or plateau only once (the rest either solved the puzzle or hit the 5-minute clock).
- Orders-of-magnitude fewer state expansions: On mutually solved tasks, going straight to the goal expands drastically fewer states than backtracking search:
- Model & domain generality: The coverage advantage held up on GPT-5.5 (594.7 vs. 532) and open-weight Gemma 4 31B (494.7 vs. 463). On the three brand-new domains, Gemini 3.1 Pro converged in an average of 2.44 candidates, matched sample-and-select coverage (202.3 vs. 203/270), expanded ~3.5× fewer states, and hit zero property violations across 810 test runs.
Limitations and Future Work
- Requires a checkable property and solvable tasks: This paradigm relies on having a formal property that yields local, actionable witnesses on failure. Furthermore, because a direct heuristic only exists if a puzzle is solvable, training sets cannot contain unsolvable tasks.
- Bounded verification isn't a formal proof: Checking the property on small training tasks with a 30-second timeout does not mathematically guarantee the heuristic is flaw-free on infinite domains.
- Unconstrained Python is hard to verify: Because the LLM writes arbitrary Python rather than linear equations, formally proving correctness is tough. Future work could pair this synthesis loop with LLM-powered theorem provers to mechanically prove that a synthesized heuristic is direct across an entire domain.
Summary updated