$\texttt{SEM-CTRL}$: Semantically Controlled Decoding
About
Ensuring both syntactic and semantic correctness in Large Language Model (LLM) outputs remains a significant challenge, despite being critical for real-world deployment. In this paper, we introduce $\texttt{SEM-CTRL}$, a unified approach that allows for enforcing rich context-sensitive constraints, and task and instance specific semantics directly on the LLM decoder. Our approach integrates token-level MCTS which is guided by specific syntactic and semantic constraints. The constraints over desired outputs are expressed using Answer Set Grammars, which is a logic-based formalism that generalizes context sensitive grammars while incorporating background knowledge to represent task-specific semantics. We show that our approach helps guarantee valid completions for any off-the-shelf LLM without the need for fine-tuning. We evaluate $\texttt{SEM-CTRL}$ on a range of tasks, including synthetic grammar synthesis, combinatorial reasoning, JSON parsing, and planning. Our experimental results demonstrate that $\texttt{SEM-CTRL}$ allows even small pre-trained LLMs to efficiently outperform larger variants and state-of-the-art reasoning models (e.g., $\textit{o4-mini}$) while simultaneously guaranteeing semantic validity.
Related benchmarks
| Task | Dataset | Result | Rank | |
|---|---|---|---|---|
| Synthetic Grammar Synthesis | Synthetic Grammar Synthesis a^n b^n c^n | Accuracy100 | 29 | |
| Combinatorial Reasoning | Combinatorial Reasoning | Graph Accuracy100 | 12 | |
| Grammar Synthesis | Synthetic Grammar Synthesis | Accuracy ($a^n b^n c^n$)100 | 12 | |
| Planning | Blocks (Blocksworld) | Accuracy96.8 | 12 | |
| Synthetic Grammar Synthesis | Synthetic Grammar Synthesis (a^m b^n c^m d^n) | Accuracy100 | 9 | |
| Combinatorial Reasoning | Graph Coloring | Accuracy100 | 9 | |
| Combinatorial Reasoning | Sudoku 3x3 | Accuracy100 | 9 | |
| Combinatorial Reasoning | Sudoku 4x4 | Accuracy100 | 9 | |
| Planning Efficiency | Blocksworld Planning | Ntokens589.3 | 4 | |
| Reasoning Efficiency | Syllogism Generation Task (SGS) | Ntokens250.2 | 4 |