mlsanityData to 7 Oct 2026

Teaching Code LLMs to Reason with Intermediate Formal Specifications

arXiv 2607.04232 ↗First posted 5 Jul 2026cs.SE cs.CLcited by 1

On the map: LLM reasoning → Reasoning for agents, planning and code

Abstract (arXiv)

Unlike natural-language specifications, executable formal specifications provide machine-checkable constraints for verifying, debugging, and repairing code. However, writing such specifications is labor-intensive, and existing LLM-based methods mainly infer whole-program pre/postconditions, missing the intermediate semantic commitments that programmers rely on when reasoning about an algorithm. Our study further shows that prompting current CodeLLMs often produces executable assertions that are syntactically invalid, trivial, or too weak to reject behavior-changing faults. In this paper, we study executable checkpoint specification generation, where assertions are inserted at meaningful internal program points to describe expected intermediate states. We introduce SpecCoder, a verification-guided CodeLLM training framework that learns from validated reference programs, behavior-changing mutants, and multi-turn specification-refinement traces. SpecCoder selects specifications that hold on correct executions while rejecting faulty executions, turning specifications from passive annotations into executable evidence. To evaluate this setting, we introduce HumanExec, a benchmark built from recent Codeforces competitive programming problems with test suites, reference solutions, and human buggy submissions, supporting three tasks: specification generation, program correctness checking, and program repair. Experiments on HumanExec show that SpecCoder substantially improves checkpoint-specification quality over base CodeLLMs. Across Qwen2.5-Coder models, SpecCoder improves inline-specification correctness by up to 55.8%, completeness by up to 358.1%, and executable assertion validity by up to 26.6%. These gains further translate to downstream correctness reasoning and repair, showing that executable checkpoints provide fine-grained evidence for reliable verification.

Key facts. Cited by 1 paper in the map (data through 7 Oct 2026). Placed in Reasoning for agents, planning and code, one of 17 directions in LLM reasoning. Builds on 14 of its 46 references that are in the map. First posted on arXiv 5 Jul 2026.

Builds on

14 of 46 references.

Closest ancestors · 1

Same direction, newest first

  1. 2025HoarePrompt: Structural Reasoning About Program Correctness in Natural Language25 Mar

Other references · 13

  1. 2020Unit Test Case Generation with Transformers and Focal Contextcited by 118
  2. 2024SpecRover: Code Intent Extraction via LLMscited by 71
  3. 2021TOGA: A Neural Method for Test Oracle Generationcited by 57
  4. 2023Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions?cited by 53
  5. 2022Interactive Code Generation via Test-Driven User-Intent Formalizationcited by 50
  6. 2024CoverUp: Effective High Coverage Test Generation for Pythoncited by 36
  7. 2020Generating Accurate Assert Statements for Unit Test Cases using Pretrained Transformerscited by 30
  8. 2023Can Large Language Models Write Good Property-Based Tests?cited by 30
  9. 2022Using Transfer Learning for Code-Related Taskscited by 18
  10. 2020Learning Nonlinear Loop Invariants with Gated Continuous Logic Networks (Extended Version)cited by 17
  11. 2022Toward Trustworthy Neural Program Synthesiscited by 11
  12. 2021EvoSpex: An Evolutionary Algorithm for Learning Postconditionscited by 6
1 more
  1. 2026SpecMind: Cognitively Inspired, Interactive Multi-Turn Framework for Postcondition Inferencecited by 2

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2026: 1.

1 paper.

Similar, not cited

Close in wording, no citation either way

  1. 2025Can LLMs Reason About Program Semantics? A Comprehensive Evaluation of LLMs on Formal Specification Inference
  2. 2025Demystifying Errors in LLM Reasoning Traces: An Empirical Study of Code Execution Simulation
  3. 2026Teaching LLMs Program Semantics via Symbolic Execution Traces
  4. 2025Integrating Symbolic Execution with LLMs for Automated Generation of Program Specifications
  5. 2026Inferring Code Correctness from Specification
  6. 2024SemCoder: Training Code Language Models with Comprehensive Semantics Reasoning
  7. 2024Reasoning Through Execution: Unifying Process and Outcome Rewards for Code Generation
  8. 2026SpecCoder: Specification-Aware Code Generation with Curriculum Dual-Task Reinforcement Learning ↗