← Latest papers
💬 NLP

Constrained Adaptive Rejection Sampling

The paper introduces Constrained Adaptive Rejection Sampling (CARS), a method that enhances the sample efficiency of language model generation under strict constraints by adaptively pruning invalid continuations via a trie, thereby preserving the original distribution while improving acceptance rates and diversity compared to existing greedy or standard rejection sampling approaches.

Original authors: Paweł Parys, Sairam Vaidya, Taylor Berg-Kirkpatrick, Loris D'Antoni

Published 2026-06-04
📖 4 min read☕ Coffee break read

Original authors: Paweł Parys, Sairam Vaidya, Taylor Berg-Kirkpatrick, Loris D'Antoni

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are a chef trying to create a new recipe, but you have a very strict rule: the dish must contain exactly three ingredients, and they must be in a specific order. You have a brilliant sous-chef (the Language Model) who is great at suggesting ingredients, but they don’t always follow your strict rules. They might suggest "salt, pepper, and... a whole watermelon?" which breaks your rule.

This paper introduces a new technique called CARS (Constrained Adaptive Rejection Sampling) to help you get perfect recipes from your sous-chef without wasting time or ruining the flavor.

The Problem: Two Bad Options

Before CARS, chefs had two main ways to deal with this problem, and both were annoying:

  1. The "Trash Can" Method (Rejection Sampling): You ask the sous-chef for a recipe. If it’s wrong (e.g., has a watermelon), you throw it in the trash and ask for another. You keep doing this until you get a valid recipe.
    • The downside: You waste a lot of time and ingredients. If the sous-chef is bad at following rules, you might throw away 99 out of 100 recipes.
  2. The "Forced Hand" Method (Greedy Constrained Decoding): You grab the sous-chef’s hand and physically force them to pick only valid ingredients. If they try to pick a watermelon, you stop them and force them to pick salt instead.
    • The downside: The recipes become boring and unnatural. By forcing the sous-chef, you change their creative style. The final dish might be "valid," but it doesn’t taste like the sous-chef’s true style anymore. It’s like forcing a jazz musician to play only classical music—they’ll play correctly, but it won’t sound like jazz.

The Solution: CARS (The Smart Notebook)

CARS is like giving the sous-chef a smart notebook that learns from mistakes.

Here is how it works:

  1. Start Fresh: You ask the sous-chef for a recipe.
  2. Learn from Mistakes: If the sous-chef suggests "salt, pepper, watermelon," you reject it. But instead of just throwing it away, you write in the notebook: "Hey, if we start with 'salt, pepper,' we should never pick 'watermelon' next."
  3. Adapt: Next time, if the sous-chef starts with "salt, pepper," the notebook automatically blocks "watermelon" from even being considered. The sous-chef is forced to pick something else, but only because we know that path leads to a dead end.
  4. Keep the Style: Crucially, CARS doesn’t force the sous-chef to change their personality. It just removes the invalid options. The remaining options are still chosen based on the sous-chef’s original preferences. So, the final recipe is valid (follows the rules) AND authentic (sounds like the sous-chef).

Why CARS is Better

  • It Gets Smarter Fast: In the beginning, you might still get some bad recipes. But with every mistake, the notebook gets smarter. The paper shows that CARS learns very quickly. After just a few tries, it stops suggesting the same types of errors.
  • It Saves Time: Because it learns from past mistakes, it wastes far less time than the "Trash Can" method.
  • It Keeps the Flavor: Unlike the "Forced Hand" method, CARS doesn’t distort the sous-chef’s style. The recipes are statistically identical to what the sous-chef would have made if they had perfectly followed the rules from the start.

Real-World Examples from the Paper

The authors tested CARS on three tricky tasks where rules are strict:

  1. Program Fuzzing (Testing Software): Imagine trying to break a computer program by feeding it weird code. The code must be syntactically correct (like proper grammar) to be useful. CARS generated valid, diverse code much faster than other methods, helping testers find bugs more efficiently.
  2. Molecule Generation (Chemistry): Chemists want to create new molecules that are stable and have specific properties. The "grammar" here is the rules of chemistry (atoms must bond correctly). CARS created valid, diverse molecules with less wasted computation than other methods.
  3. Text-to-SQL (Database Queries): Asking an AI to write database queries. The query must be perfect SQL code. CARS produced correct queries more efficiently than other exact methods, and more accurately than approximate methods that sometimes "faked" the rules.

The Bottom Line

CARS is a way to get the best of both worlds: strict rule-following without losing creativity. It’s like having a sous-chef who learns from their mistakes in real-time, ensuring every dish is both delicious and perfectly compliant with your dietary restrictions.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →