arXiv:2610.12529cs.SEOct 2026

Manuscript Offprint

arXiv:2610.12529

Fix What's Wrong, Keep What's Right: Hallucination Repair for LLM-Based Optimization Modeling

Jiageng Wu, Chao Shen, Zihan Guo, Junyan Shao, Zongyan Zhang, Jie Song, Zhong Li, Mingyang Sun

Abstract

Large language models (LLMs) are increasingly being explored to automate operations research modeling, reduce modeling time and lower the expertise barrier to optimization based decision support. However, this process often introduces inconsistencies between generated artifacts and the original problem, which we refer to as optimization modeling hallucinations. Despite progress in general-purpose hallucination mitigation, optimization modeling poses a distinct repair challenge: restoring fidelity to the original problem through coordinated model–code updates. We introduce OPT-Kraken, a training-free hallucination repair framework. To the best of our knowledge, it is the first post-hoc framework for repairing hallucinations in LLM-based optimization modeling artifacts. It extracts problem requirements and instance data, localizes errors by checking problem–model fidelity, model–code consistency, and data grounding, and selects repair granularity by the affected scope. For local repair, category rules and instance evidence are compiled into contracts specifying permitted edits, expected effects, and protected content. Experiments on established optimization modeling benchmarks show positive gains across automatic modeling frameworks and fine-tuned models. On zero-shot artifacts from multiple base models, OPT-Kraken effectively repairs optimization modeling hallucinations while preserving initially correct artifacts. These results demonstrate effective and controlled repair for LLM-based optimization modeling artifacts.

1 Introduction

Large language models (LLMs) are increasingly being explored to translate natural language operations research (OR) problems into mathematical models M and solver code S. This workflow can lower the expertise barrier and reduce the modeling time required for decision support in manufacturing, logistics, and resource allocation. However, M and S generated by LLM often fail to remain faithful to the original problem, potentially misleading downstream decisions. We define optimization modeling hallucinations as errors in LLM-generated modeling artifacts that make them inconsistent with the original optimization problem. These include unsupported additions, omitted requirements, incorrect mathematical formulations, model–code inconsistencies, data-binding faults, and result-extraction errors, among other failures.

General hallucination research provides foundations for evidence checking, consistency estimation, and feedback-driven revision. However, unlike question-answering tasks whose primary outputs are general natural language responses, optimization modeling requires translating problem requirements into interrelated mathematical models and solver code. Merely checking support for generated statements does not establish that all problem requirements have been represented; successful code execution cannot rule out errors in

(a) Problem, initial model & code

P: Problem (illustrative example)

A factory produces A and B.

Outputs are nonnegative integers.

Unit profits: A = 3 yuan; B = 2 yuan.

Total output must not exceed 10 units.

B's output must be at least 2/5 of A's output.

Maximize total profit.

M: Initial mathematical model (excerpt)

{ "name": "ratio", "coefficients": {"B": 5, "A": -2}, "sense": "<=", "rhs": 0 }

5B ≤ 2A: "at least" becomes "at most"

S: Initial solver code (excerpt)

A and B are nonnegative integer variables

m.setObjective(3A + 2B, GRB.MAXIMIZE)

m.addConstr(A + B <= 10, name="capacity")

m.addConstr(5B <= 2A, name="ratio")

m.optimize()

The reversed inequality propagates from M to S.

(b) Evidence, detection & repair

Extract O / D from P (excerpt)

O · Problem requirements

B must be at least 2/5 of A.

Thus, 5B≥2A5B \geq 2A

D · Instance data

Unit profits: (3, 2); output limit: 10

Ratio parameter: 2/5

Detection: reversed inequality

P/O → M : FAIL

M ↔ S : PASS

M and S agree, but both violate the problem requirements.

Select local repair

RepairCard + problem evidence

Contract: flip only ratio's inequality

≤→≥\leq \rightarrow \geq

Preserve domains, profits and capacity

Update S → artifact audit

One root cause, two manifestations: M-S consistency does not imply fidelity to the problem.

(c) Repaired model & code

M*: Repaired mathematical model (excerpt)

5B ≥ 2A: restore the "at least" requirement

{ "name": "ratio", "coefficients": {"B": 5, "A": -2}, "sense": ">=", "rhs": 0 }

Reverse the inequality; keep the coefficients.

S*: Repaired solver code (excerpt)

A and B are nonnegative integer variables

m.setObjective(3A + 2B, GRB.MAXIMIZE)

m.addConstr(A + B <= 10, name="capacity")

m.addConstr(5B >= 2A, name="ratio")

m.optimize()

Update only the inequality direction in ratio.

Domains, objective and other constraints stay unchanged.

Problem evidence Original error Repaired parts

Figure 1: A shared optimization-modeling hallucination in the model and code.

the mathematical model. Therefore, repairing optimization modeling hallucinations requires locating errors using evidence from the original problem and defining the scope of coordinated model–code updates.

These requirements motivate treating hallucination repair as a standalone post-hoc task on optimization modeling artifacts. Rather than simply generating another model and code, the task is to identify errors in existing artifacts using evidence from the original problem, perform necessary repairs, and use validation to decide whether to accept the changes. Figure 1 illustrates a shared modeling hallucination and its localized repair: both the mathematical model and solver code use 5B≤2A5B \leq 2A, whereas the original problem requires 5B≥2A5B \geq 2A. The repair corrects the inequality direction in both artifacts while leaving variable domains, objective coefficients, and other constraints unchanged.

We study hallucination repair through the joint lens of error correction and content preservation. Incorrect outputs deemed hallucination-free lose repair opportunities; false alarms can corrupt correct outputs through unnecessary edits. Repair must correct errors while preserving valid content. We therefore use three metrics: Rescue, Regression, and Error Coverage. Rescue is the share of initially incorrect outputs corrected, Regression is the share of initially correct outputs made incorrect, and Error Coverage is the share of initially incorrect outputs retained as repair opportunities by the screening stage. Together, they capture gains, outcome-level harm, and coverage of opportunities.

OPT-Kraken provides plug-and-play post-processing of a problem PP, model M0M_{0}, and code S0S_{0}, without retraining or changing the upstream generator. It extracts requirements O and instance data D from problem P, localizes errors through directional fidelity checks, and selects the repair scope. Contracts bind category rules to case evidence; commit gates protect valid content.

To the best of our knowledge, OPT-Kraken is the first post-hoc framework for repairing hallucinations in LLM-generated optimization-modeling artifacts, targeting problem–model–code fidelity while controlling repair scope and regression. Our contributions can be summarized as follows:

(1) Post-hoc formulation of hallucination repair for LLM-based optimization modeling: We formulate hallucination repair for LLM-based optimization modeling as a post-hoc transformation of frozen problem-model-code artifacts. Unlike generation-time correction, the task requires correcting unfaithful content while preserving valid content. We evaluate repair effectiveness, preservation, and coverage of repair opportunities using Rescue, Regression, and Error Coverage, defined respectively as the shares of initially incorrect outputs corrected, initially correct outputs made incorrect, and initially incorrect outputs flagged by screening for examination or potential repair.

(2) Evidence-guided and scope-controlled hallucination repair framework: We introduce OPT-Kraken, a generic training-free framework that operates as a post-processor for different upstream generators. It (a) diagnoses artifacts through source-grounded checks of problem-model fidelity, model-code consistency, and data grounding; (b) selects the minimum sufficient repair scope based on error location and dependency scope; and (c) compiles category-level repair knowledge and instance-specific evidence into executable contracts for reliable local repair, followed by artifact-level auditing and safe commit.

(3) Consistent improvements across diverse optimization-modeling generators: We evaluate six benchmarks, four generation pipelines, four fine-tuned generators, and three repair backbones. Accuracy improves by 6.3–20.1 percentage points across the four generation pipelines. Three complementary ablations examine the roles of dual-evidence detection, evidence-guided repair granularity, and contract-constrained local repair.

References (19)