Why LLMs Keep Getting Shortest-Path Problems Wrong
This article examines why large language models frequently fail on shortest-path and optimization tasks, covering three common failure modes: feasibility misjudgment, cost underestimation, and unverified optimality. It explains the underlying causes of this instability and outlines a practical engineering approach based on problem formalization, layered solving, independent verification, consensus across multiple runs, observability, and benchmark evaluation. The goal is not a single correct answer, but verifiable correctness.
1. Background: From “Looks Like It Can Compute” to “Actually Computes Correctly”
In real engineering work, handing problems like shortest path, minimum cost, and resource scheduling to an AI model has become a common experiment. On the surface, the model produces a plausible reasoning trace and a numerical answer, so it is easy to assume the problem is “solved.” But run the same problem repeatedly and the conclusions often contradict each other: some runs declare the problem unsolvable, some return a minimum cost, and others produce a number without being able to say whether that number can still be reduced.
The behavior in the source material is representative: across twelve runs from two baseline models, only five produced an “impossible” verdict, and four of those five gave an incorrect minimum cost. The single run that reached the right conclusion still admitted it had not verified whether the path was truly the shortest. The core issue here is not that “the model cannot do arithmetic,” but that the model lacks a stable grasp of feasibility, optimality, and verifiability. The breakdown below covers three layers.
2. Three Typical Failure Modes
2.1 Feasibility Misjudgment: Treating “Not Found” as “Does Not Exist”
When judging “impossible,” models tend to rely on a search intuition bounded by a limited number of steps. Once constraints get slightly more complex and the search space grows, the model easily equates “I did not find a solution within my limited attempts” with “no solution exists.” That inference is logically invalid: failing to find a solution may simply mean the search was incomplete, not that the problem is unsolvable.
In engineering terms, feasibility and optimality should be judged separately. Feasibility can be handed to an explicit decision procedure: first construct a feasible solution as an upper bound, then try to prove the lower bound is unreachable. Only when the upper and lower bounds meet can optimality be claimed. Conflating “not found” with “unreachable” is the main source of wrong conclusions.
2.2 Cost Underestimation: Local Optimum Passing as Global Optimum
Among the runs that returned a minimum cost, the errors concentrated on values that were too low. The usual cause is that the model accumulates cost along a single path that looks smooth, ignoring constraints elsewhere that raise the total cost, such as detours, waiting, or capacity limits that add overhead. A locally smooth path is not the globally cheapest one.
The correct approach can be expressed with this illustrative pseudocode:
best = +∞for candidate in feasible_solutions:cost = evaluate(candidate) # must include all additional cost termsif cost < best:best = costbest_path = candidateassert best < +∞ # if no feasible solution exists, report infeasibility explicitly
The key point is that evaluate must cover every cost term, and the loop must traverse the complete feasible region rather than converging early on the first path found.
2.3 Unverified Optimality: Right Answer, No Explanation of Why
Even the single run with the correct conclusion never verified whether the path was the shortest. This shows that “the answer is correct” and “the process is trustworthy” are two different things. Without a verification step, the model’s output is only a guess and cannot be used for production decisions. The trustworthy approach is to add independent checking: recompute with a different algorithm or an external solver, compare upper and lower bounds, and run a small-scale exhaustive comparison when necessary.
3. Why Models Are Unstable on These Problems
- Limited search depth: models favor short reasoning chains and truncate easily once constraints pile up.
- Ignored constraint coupling: with multiple constraints acting at once, the model often fixates on the main objective and drops additional cost terms.
- No symbolic verification: the problem is not turned into a decidable mathematical structure, so conclusions cannot be rechecked by a machine.
- Unreliable self-assessment: the model’s confidence in its own correctness correlates weakly with actual accuracy and cannot serve as a quality signal.
4. A Practical Engineering Approach
- Formalize the problem: turn the business description into an explicit definition of the graph and constraints, spelling out nodes, edges, the cost function, capacity, and time limits.
- Solve in layers: first obtain a feasible solution and an upper bound with a general solving approach, then tighten with a lower-bound estimate; output the optimum only when the bounds are equal.
- Close the loop with external verification: send the model’s candidate solution to an independent checking stage for recomputation, and fall back to re-solving on any mismatch instead of accepting it directly.
- Take consensus across multiple runs: sample the same problem several times; if the conclusions diverge widely, mark the result as low confidence and route it to a human or to an exact algorithm.
- Observability and traceability: log the constraint version, candidate solution, and verification result of each run so the source of an error can be traced back.
- Build an evaluation set: construct small-scale benchmarks with known optimal solutions, and continuously measure feasibility-decision accuracy, cost error rate, and optimality-verification coverage.
5. Conclusion
Handing shortest-path problems to a model should not aim for “one right answer,” but for “verifiable correctness.” Separating feasibility, optimality, and verifiability, combined with formal modeling and independent verification, is what turns occasional correctness into a stable capability. For developers, the real payoff is not how well the model reasons, but whether the whole pipeline can detect and correct errors.
