ChopChop: a Programmable Framework for Semantically Constraining the Output of Language Models

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Nagy, Shaan, Zhou, Timothy, Polikarpova, Nadia, D'Antoni, Loris
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866917117038690304
author Nagy, Shaan
Zhou, Timothy
Polikarpova, Nadia
D'Antoni, Loris
author_facet Nagy, Shaan
Zhou, Timothy
Polikarpova, Nadia
D'Antoni, Loris
contents Language models (LMs) can generate code but cannot guarantee its correctness$\unicode{x2014}$often producing outputs that violate type safety, program invariants, or other semantic properties. Constrained decoding offers a solution by restricting generation to only produce programs that satisfy user-defined properties. However, existing methods are either limited to syntactic constraints or rely on brittle, ad hoc encodings of semantic properties over token sequences rather than program structure. We present ChopChop, the first programmable framework for constraining the output of LMs with respect to semantic properties. ChopChop introduces a principled way to construct constrained decoders based on analyzing the space of programs a prefix represents. It formulates this analysis as a realizability problem which is solved via coinduction, connecting token-level generation with structural reasoning over programs. We demonstrate ChopChop's generality by using it to enforce (1) equivalence to a reference program and (2) type safety. Across a range of models and tasks, ChopChop improves success rates while maintaining practical decoding latency.
format Preprint
id arxiv_https___arxiv_org_abs_2509_00360
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle ChopChop: a Programmable Framework for Semantically Constraining the Output of Language Models
Nagy, Shaan
Zhou, Timothy
Polikarpova, Nadia
D'Antoni, Loris
Programming Languages
D.3.0
Language models (LMs) can generate code but cannot guarantee its correctness$\unicode{x2014}$often producing outputs that violate type safety, program invariants, or other semantic properties. Constrained decoding offers a solution by restricting generation to only produce programs that satisfy user-defined properties. However, existing methods are either limited to syntactic constraints or rely on brittle, ad hoc encodings of semantic properties over token sequences rather than program structure. We present ChopChop, the first programmable framework for constraining the output of LMs with respect to semantic properties. ChopChop introduces a principled way to construct constrained decoders based on analyzing the space of programs a prefix represents. It formulates this analysis as a realizability problem which is solved via coinduction, connecting token-level generation with structural reasoning over programs. We demonstrate ChopChop's generality by using it to enforce (1) equivalence to a reference program and (2) type safety. Across a range of models and tasks, ChopChop improves success rates while maintaining practical decoding latency.
title ChopChop: a Programmable Framework for Semantically Constraining the Output of Language Models
topic Programming Languages
D.3.0
url https://arxiv.org/abs/2509.00360