Large language models (LLMs) can generate structured outputs, but existing constrained-decoding methods mainly enforce syntax and cannot directly enforce satisfaction of a formal specification. We introduce a neuro-symbolic, specification-guided decoding framework that combines LLM generation with symbolic reasoning. At each step, the framework refines the decoding grammar by filtering out values that cannot be extended to an output satisfying the specification. We present a forward-only variant that guarantees specification satisfaction by construction, and a backtracking variant that revises earlier feasible choices when their downstream consequences leave only values that the LLM itself judges unsuitable. The framework is model-agnostic, requires no retraining, and builds on existing grammar-constrained decoding mechanisms. Experiments on configuration and constraint-solving benchmarks show that the forward-only variant reliably produces specification-compliant outputs while reducing repeated LLM inference compared with rejection sampling and incurring modest symbolic-reasoning overhead. The backtracking variant further reduces cases in which the model is forced to select values that it has itself judged unsuitable, thereby substantially improving adherence to the LLM's stated interpretation of the prompt.
Figures & tables
Figure 1: A JSON schema expressed as a Pydantic model, with additional relational constraints.
Algorithm 1 Specification-Guided Decoding
Initial Domain
Feasible Domain
Assignment
CPU
[i5, i7, i9]
[i5, i7, i9]
i7
RAM
[ram8, ram16, ram32]
[ram16, ram32]
ram16
GPU
[integrated, dedicated]
[integrated, dedicated]
dedicated
HARD_DISK
[256, 512, 1024]
[256, 512, 1024]
1024
BATTERY
[standard, extended]
[extended]
extended ∗
Table 1: Execution trace for the laptop configuration example. Prompt: “Generate a configuration for a gaming laptop.”
Algorithm 2 Specification-Guided Decoding with Backtracking
Figure 2: Runtime comparison between SureGen-fw and SRS .
Figure 3: Comparison of the number of LLM calls made by SureGen-fw and SRS