ChopChop: a Programmable Framework for Semantically Constraining the Output of Language Models
By: Shaan Nagy , Timothy Zhou , Nadia Polikarpova and more
Potential Business Impact:
Makes computer code work correctly every time.
Language models (LMs) can generate code, but cannot guarantee its correctness--producing outputs that often violate type safety, program invariants, or semantic equivalence. Constrained decoding offers a solution by restricting generation to programs that satisfy desired properties. Yet, existing methods are limited to shallow syntactic constraints or rely on brittle, ad hoc encodings of semantics over token sequences. We present ChopChop, the first programmable framework for semantic constrained decoding, enabling LMs to generate code that provably satisfies rich semantic properties. ChopChop connects token-level generation with reasoning over abstract program structures using a coinduction-based formalism and reduces constraint enforcement to a realizability problem over regular codata. We demonstrate ChopChop's generality through generation constrained by type safety and program equivalence, showing how formal methods can be seamlessly integrated into LM-driven code generation. ChopChop transforms semantic constrained decoding from a niche technique into a systematic, principled extension of LMs--improving success rates across models and tasks while maintaining practical decoding latency.
Similar Papers
Correctness-Guaranteed Code Generation via Constrained Decoding
Programming Languages
Makes computer code work perfectly the first time.
TreeCoder: Systematic Exploration and Optimisation of Decoding and Constraints for LLM Code Generation
Machine Learning (CS)
Makes computer code write itself correctly.
SLICET5: Static Program Slicing using Language Models with Copy Mechanism and Constrained Decoding
Software Engineering
Helps fix broken computer code, even if incomplete.