[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-detail-82797-en":3,"doc-seo-82797-105":29,"detail-sidebar-cat-0-en-105":83},{"code":4,"msg":5,"data":6},0,"success",{"doc_id":7,"user_id":8,"nickname":9,"user_avatar":10,"doc_module":4,"category_id":11,"category_name":12,"doc_title":13,"doc_description":14,"doc_content":15,"file_id":16,"file_url":17,"file_type":18,"file_size":19,"view_count":20,"is_deleted":4,"is_public":20,"is_downloadable":20,"audit_status":20,"page_count":21,"language":22,"language_code":23,"site_id":24,"html_lang":23,"table_of_contents":25,"faqs":26,"seo_title":13,"seo_description":14,"update_tm":27,"read_time":28},82797,4398048950312,"Violet","https://ap-avatar.wpscdn.com/avatar/400002538284de19e3c?_k=1778320343897328908",6,"Technology","Teaching Code LLMs to Reason with Intermediate Formal Specifications","Unlike natural-language specifications, executable formal specifications enable machine-checkable constraints for verifying, debugging, and repairing code. Current CodeLLM methods often infer only whole-program pre/postconditions, leaving out the intermediate semantic commitments used by programmers during algorithm reasoning. The study introduces executable checkpoint specifications with assertions placed at meaningful internal program points. SPECCODER is a verification-guided training framework using validated programs, behavior-changing mutants, and multi-turn refinement traces. HumanExec evaluates generation, correctness checking, and repair.","Teaching Code LLMs to Reason with Intermediate  \nFormal Specifications  \nMinh Le-Anh  \nFPT Software AI Center Hanoi Univ. of Science and Tech. Hanoi, Vietnam [minhla4@fpt.com](minhla4@fpt.com)  \nCuong Chi Le  \nUniversity of Texas at Dallas Texas, USA [cuong.le@utdallas.edu](cuong.le@utdallas.edu)  \nTien N. Nguyen  \nUniversity of Texas at Dallas Texas, USA  \n[tien.n.nguyen@utdallas.edu](tien.n.nguyen@utdallas.edu)  \narXiv :2607 .04232v 1 [ cs . SE] 5 Jul 2026  \nAbstract—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 verificationguided 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 competitiveprogramming 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.  \nI. INTRODUCTION  \nFormal specifications are symbolic constraints that describe expected program behavior and can be checked against executions [1],[2] . When a specification is written as an assertion, it becomes directly executable: the assertion can be evaluated on concrete program traces and used as feedback for verification, testing, debugging, and repair. Instead of only asking whether a program produces the correct final output, executable specifications can expose whether the program satisfies the properties needed to reach that output correctly.  \nRecent advances in Large Language Models (LLMs) have transformed software development. However, the hallucination and semantic unreliability of LLM-generated code have shifted the focus of software engineering research from merely generating code to a more fundamental question: how can we  \nverify that generated code is correct and aligned with user intent, and how can we help repair it when it is not? Program specifications provide an important vehicle for this goal. They make the intended behavior explicit and can serve as oracles for checking, explaining, and correcting generated implementations. Unfortunately, manually writing high-quality formal specifications for LLM-generated code is labor-intensive and requires substantial programming and verification expertise. This creates a clear need for automated techniques that can generate executable formal specifications.  \nRecent research has shown that LLMs can generate program specifications for a given implementation, including postconditions and natural-language correctness conditions [3] . For exampl","cbCaihidozxkutUB","https://ap.wps.com/l/cbCaihidozxkutUB","pdf",1361386,1,12,"English","en",105,"# Introduction\n## Executable formal specifications\n## Limitations of existing LLM-based specification methods\n## Coarse-grained vs intermediate obligations\n## Natural-language intermediate conditions and automation gaps","[{\"question\":\"How does SPECCODER improve specification quality compared with base CodeLLMs?\",\"answer\":\"SPECCODER is a verification-guided training framework that learns from validated reference programs, behavior-changing mutants, and multi-turn specification-refinement traces. It selects checkpoint specifications that hold on correct executions while rejecting faulty ones, improving inline-specification correctness, completeness, and executable validity.\"}]",1784183003,30,{"code":4,"msg":30,"data":31},"ok",{"site_id":24,"language":23,"slug":32,"title":13,"keywords":33,"description":14,"schema_data":34,"social_meta":78,"head_meta":80,"extra_data":82,"updated_unix":27},"teaching-code-llms-to-reason-with-intermediate-formal-specifications","",{"@graph":35,"@context":77},[36,53,68],{"@type":37,"itemListElement":38},"BreadcrumbList",[39,43,47,50],{"item":40,"name":41,"@type":42,"position":20},"https://docshare.wps.com","Home","ListItem",{"item":44,"name":45,"@type":42,"position":46},"https://docshare.wps.com/document/","Document",2,{"item":48,"name":12,"@type":42,"position":49},"https://docshare.wps.com/document/technology/",3,{"item":51,"name":13,"@type":42,"position":52},"https://docshare.wps.com/document/teaching-code-llms-to-reason-with-intermediate-formal-specifications/82797/",4,{"url":51,"name":13,"@type":54,"author":55,"headline":13,"publisher":57,"fileFormat":60,"inLanguage":23,"description":14,"dateModified":61,"datePublished":62,"encodingFormat":60,"isAccessibleForFree":63,"interactionStatistic":64},"DigitalDocument",{"name":9,"@type":56},"Person",{"url":40,"name":58,"@type":59},"DocShare","Organization","application/pdf","2026-07-17","2026-07-16",true,{"@type":65,"interactionType":66,"userInteractionCount":20},"InteractionCounter",{"@type":67},"ViewAction",{"@type":69,"mainEntity":70},"FAQPage",[71],{"name":72,"@type":73,"acceptedAnswer":74},"How does SPECCODER improve specification quality compared with base CodeLLMs?","Question",{"text":75,"@type":76},"SPECCODER is a verification-guided training framework that learns from validated reference programs, behavior-changing mutants, and multi-turn specification-refinement traces. It selects checkpoint specifications that hold on correct executions while rejecting faulty ones, improving inline-specification correctness, completeness, and executable validity.","Answer","https://schema.org",{"og:url":51,"og:type":79,"og:title":13,"og:site_name":58,"og:description":14},"article",{"robots":81,"canonical":51},"index,follow",{"doc_id":7,"site_id":24},{"code":4,"msg":5,"data":84},[85,89,93,97,102,105,110,114,119,122,126],{"id":20,"doc_module":4,"doc_module_name":45,"category_name":86,"show_sort_weight":87,"slug":88},"Story & Novel",90,"story-novel",{"id":46,"doc_module":4,"doc_module_name":45,"category_name":90,"show_sort_weight":91,"slug":92},"Literature",80,"literature",{"id":52,"doc_module":4,"doc_module_name":45,"category_name":94,"show_sort_weight":95,"slug":96},"Exam",70,"exam",{"id":98,"doc_module":4,"doc_module_name":45,"category_name":99,"show_sort_weight":100,"slug":101},5,"Comic",60,"comic",{"id":11,"doc_module":4,"doc_module_name":45,"category_name":12,"show_sort_weight":103,"slug":104},50,"technology",{"id":106,"doc_module":4,"doc_module_name":45,"category_name":107,"show_sort_weight":108,"slug":109},7,"Healthcare",40,"healthcare",{"id":111,"doc_module":4,"doc_module_name":45,"category_name":112,"show_sort_weight":28,"slug":113},8,"Research & Report","research-report",{"id":115,"doc_module":4,"doc_module_name":45,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":45,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":45,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":45,"category_name":128,"show_sort_weight":98,"slug":129},19,"General","general"]