Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective

Emmanuel Anaya Gonzalez, Sairam Vaidya, Kanghee Park, Ruyi Ji, Taylor Berg-Kirkpatrick +1 more
6/6/2025
cs.AIcs.CLcs.LG

No confident code implementation found for this paper. 1 possible match can be shown below.

Abstract

Constrained decoding enables Language Models (LMs) to produce samples that provably satisfy hard constraints. However, existing constrained-decoding approaches often distort the underlying model distribution, a limitation that is especially problematic in applications like program fuzzing, where one wants to generate diverse and valid program inputs for testing purposes. We propose a new constrained sampling framework based on Markov Chain Monte Carlo (MCMC) that simultaneously satisfies three core desiderata: constraint satisfying (every sample satisfies the constraint), monotonically converging (the sampling process converges to the true conditional distribution), and efficient (high-quality samples emerge in few steps). Our method constructs a proposal distribution over valid outputs and applies a Metropolis-Hastings acceptance criterion based on the LM's likelihood, ensuring principled and efficient exploration of the constrained space. Empirically, our sampler outperforms existing methods on both synthetic benchmarks and real-world program fuzzing tasks.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. 1 weaker match is hidden by default — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{gonzalez2025constrained,
  title  = {Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective},
  author = {Emmanuel Anaya Gonzalez and Sairam Vaidya and Kanghee Park and Ruyi Ji and Taylor Berg-Kirkpatrick and Loris D'Antoni},
  year   = {2025},
  eprint = {2506.05754},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2506.05754v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2506.05754.svg)](https://codeofpaper.com/paper/2506.05754)

Discussion