Manuscript Offprint
arXiv:2610.41511Specification-Guided Generation for Large Language Models
Abstract
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.
Introduction
The success of Large Language Models (LLMs) (Brown et al. 2020; Touvron et al. 2023; Anil et al. 2023; Guo et al. 2025) has motivated constrained-generation methods (Poesia et al. 2022; Beurer-Kellner, Fischer, and Vechev 2024; Park et al. 2024), which restrict decoding so that only tokens preserving syntactic validity are admissible. These methods guarantee conformity to regular expressions, context-free grammars, or structured schemas without model retraining, making them useful for applications such as API generation, information extraction, code synthesis, and tool invocation.
However, existing constrained-decoding methods are limited to syntactic structure and cannot directly enforce a formal specification expressed as logical constraints. Here, a formal specification is a mathematically precise description of the properties that every admissible output must satisfy. As a result, generated outputs may be syntactically valid while still
violating logical relationships and dependencies among variables. Such guarantees are increasingly important as LLMs are used for monitoring, configuration, and decision-making in domains including telecommunications, software systems, healthcare, and finance (Li et al. 2025b,a; Cai et al. 2025; Wu, Barrett, and Narodytska 2024; Singhal et al. 2023; Liu et al. 2023, 2024).
We introduce specification-guided decoding, which integrates a symbolic reasoner directly into LLM generation. Before each assignment, the reasoner computes the values that remain compatible with the specification and restricts decoding to those values. Consequently, every completed output satisfies the formal specification by construction. Unlike approaches that translate natural-language requirements into formal constraints (Ye et al. 2023; Wu, Barrett, and Narodytska 2024; Zhang et al. 2025; Pan et al. 2023), we assume that the specification is provided as input, analogously to the predefined grammar or schema required by structured-output tools. Our approach is therefore complementary to specification-synthesis methods, is model-agnostic, requires no retraining, and builds on existing constrained-decoding mechanisms.
The LLM and the symbolic reasoner have complementary roles. The specification captures hard requirements, while the prompt expresses the user's goals and preferences within the feasible space. The reasoner guarantees validity, whereas the LLM guides the choice among potentially many valid outputs toward one that better reflects the prompt. The LLM's preferences over feasible values are context-dependent and revealed only during autoregressive generation, so they cannot be fully formalized in advance. Moreover, the constrained variables may form only part of a broader grammar-guided output, and their preferred values may depend on surrounding content generated during decoding. Solving the specification independently would therefore neither preserve these context-dependent choices nor replace the overall generation process. Our procedure instead preserves the model's native generation process as much as possible: similarly to structured-output decoding, it intervenes only to exclude infeasible choices while otherwise following the model's conditional distribution.
Figure 1 illustrates the distinction. Existing schema-
*Corresponding author
class LaptopConfig(BaseModel):
CPU: Literal['i5', 'i7', 'i9']
RAM: Literal['ram8', 'ram16', 'ram32']
GPU: Literal['integrated', 'dedicated']
HARD_DISK: Literal[256, 512, 1024]
BATTERY: Literal['standard', 'extended']
Constraints:
1. If GPU is Dedicated, Battery must be Extended.
2. If CPU is an i7 or i9, RAM must be at least 16GB.
3. If RAM is 16GB or more, Battery must be Extended.
Figure 1: A JSON schema expressed as a Pydantic model, with additional relational constraints.
constrained tools (Lundberg, Ribeiro et al. 2023; Gerganov 2023; Willard and Louf 2023) can ensure that each laptop parameter takes an allowed value, but cannot enforce dependencies among parameters. For example, CPU = i7, RAM = ram8, GPU = dedicated, HARD_DISK = 512, and BATTERY = standard is syntactically valid, yet violates both the CPU–RAM and GPU–battery constraints. Our method prevents such assignments while retaining the LLM's ability to interpret a high-level request, such as generating a gaming laptop configuration.
The same setting arises in information extraction and structured decision-making tasks such as product configuration, software feature selection, scheduling, routing, and package management, where outputs must satisfy relationships among variables.
Main Contributions We make the following contributions:
-
We introduce a model-agnostic specification-guided decoding framework that integrates symbolic reasoning into LLM generation without retraining.
-
We develop a forward-only procedure that restricts each assignment to feasible values, guaranteeing specification satisfaction by construction without post-hoc validation or trial-and-error generation.
-
We introduce a backtracking extension that revises earlier assignments when their consequences conflict with the model's interpretation of the prompt, while preserving specification compliance.
-
We evaluate both methods on configuration and constraint-solving benchmarks. Forward decoding reduces repeated LLM inference with modest reasoning overhead, while backtracking resolves many prompt conflicts and improves adherence to the model's stated preferences.
SMT We use Satisfiability Modulo Theories (SMT) to express formal specifications; see (Barrett and Tinelli 2018) for background. Our approach is not specific to SMT and applies to any formalism whose solver can check satisfiability and refine variable domains.
Let be a formula over variables , where each has domain . A possibly partial assignment maps variables to values in their domains and satisfies , written , when is true under . We write for the free variables of .
Definition 1. The feasible domain of under is
For example, if and contains , , and , then .
Grammar-Constrained Decoding Let be the language-model vocabulary and let be a grammar defining the valid outputs . Grammar-constrained decoding (Poesia et al. 2022; Beurer-Kellner, Fischer, and Vechev 2024; Park et al. 2024) masks tokens that would prevent the generated prefix from being extended to a string in , and selects the next token from the resulting constrained distribution. In the remainder of this paper, we assume greedy decoding and write for greedy grammar-constrained generation from prompt under grammar . Our method applies this mechanism sequentially. Before generating an assignment for each variable, it computes the variable's feasible domain under the formal specification and the assignments generated so far, and constructs a grammar that accepts exactly the values in that domain.
Specification-Guided Decoding
In this section, we present the core idea of our approach. Specification-guided decoding integrates symbolic reasoning into generation so that each decoding step preserves compatibility with the formal specification. As a result, every partial output remains extendable to a satisfying completion, avoiding post-hoc rejection.
Let be the set of variables of a satisfiable specification . We denote by the ordered trail after assignments. The residual specification induced by the trail is
We denote by the output prefix containing the first assignments, and by the language of complete assignment sequences whose corresponding assignments satisfy . Our method operates at the assignment level, with each assignment generated by the constrained-decoding procedure . We next define the token-level greedy decoding performed internally by .
Definition 2 (Token-level specification-guided greedy decoding). Given a current token prefix , specification-guided greedy decoding selects
Algorithm 1 Specification-Guided Decoding
Require: Satisfiable specification , prompt
Output:
Invariant: is satisfiable
1:
2:
3:
4:
5: while do
6:
7:
8:
9: if then
10:
11: else
12:
13:
14:
15:
16: return
where is the LLM's conditional probability of token given the current prefix, and is the set of tokens whose addition still permits a completion satisfying .
The function applies this rule repeatedly until it produces a complete value for the current variable. The resulting value constitutes the next assignment in the assignment-level procedure. Before assigning a variable , the symbolic reasoner computes its feasible domain under the current residual specification. The feasible domain is then translated into a grammar such that , where denotes the textual representation of . Feasible domains are represented compactly whenever possible: integer and real-valued domains are typically stored as lists of intervals, whereas Boolean domains and small enumerated domains are represented as explicit sets of values. The grammar therefore acts as an interface between the symbolic reasoner and the language model: the reasoner identifies the feasible values, while the grammar prevents the decoder from generating any other value.
Algorithm 1 processes the variables in the chosen order. At each iteration, it computes the feasible domain of the next variable. If the domain is a singleton, the unique value is propagated directly, avoiding an unnecessary call to . We refer to assignments obtained from singleton domains as propagated implied values. Otherwise, the algorithm constructs a grammar that accepts exactly the feasible values and invokes constrained decoding to select one of them. The selected assignment is then appended to both the trail and the generated output . The invariant follows because , and therefore is satisfiable at every iteration. Hence every generated partial assignment can be extended to a model of , and the final output belongs to . The procedure is therefore sound and backtrack-free. It performs at most one call to per variable and requires no such call when the corresponding
Algorithm 2 Specification-Guided Decoding with Backtracking
Require: Specification , Prompt
Output: or P-UNSAT
Invariant: is satisfiable at the beginning of each iteration
1:
2:
3:
4:
5: while do
6:
7:
8:
9: if then
10:
11:
12:
13:
else
14:
15:
16:
17: while do
18: if then
19:
20:
21:
22:
23: else
24: return P-UNSAT
25: return
feasible domain is a singleton.
Regarding completeness, the procedure excludes only values that cannot be extended to a satisfying assignment and therefore does not eliminate any solution of the current residual specification. This does not imply that every satisfying assignment can be generated, since the LLM may assign zero probability to some admissible choices.
Table 1 illustrates the execution of Algorithm 1 on the laptop configuration introduced in Figure 1. The model first assigns i7 to CPU. Under this assignment, the feasible domain of RAM is reduced to [ram16, ram32], from which the model selects ram16. The GPU variable is not further constrained, and the LLM chooses dedicated, consistent with the gaming requirement in the prompt. Similarly, HARD_DISK remain unconstrained by the previous assignments, and the model selects 1024. Finally, the specification reduces the feasible domain of BATTERY to the singleton [extended]; consequently, this value is propagated directly without an additional decoding call and marked *.
Specification-Guided Decoding with Backtracking
In this section, we introduce a backtracking extension for resolving cases where specification-compliant decoding forces values that the LLM itself judges unsuitable for the prompt. Algorithm 1 guarantees satisfaction of the formal specifi-
| 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.”
cation, but an early greedy assignment may unnecessarily restrict the feasible domains of later variables and eventually force the decoder to select a value that is valid but poorly aligned with the prompt. To detect such situations, before assigning the current variable we ask the LLM whether its feasible domain, as determined by the specification and the current partial assignment, contains at least one value compatible with the prompt. A negative answer indicates that, although the domain is formally feasible, the LLM considers all of its values unsuitable for the prompt. Its judgment is not an objective measure of user intent, but reflects the model's own assessment of the values that remain feasible. When the LLM judges that none of the values in the current feasible domain adequately satisfies the prompt, we say that a prompt conflict (P-CONFLICT) occurs. Although the specification still admits one or more feasible values, the method backtracks and revises earlier assignments responsible for restricting the current domain. This allows the decoder to explore a different specification-compliant trajectory instead of committing to a locally feasible but undesirable value. Our focus is on resolving such mismatches once detected, rather than on developing a general characterization of prompt adherence. In principle, the relevant signal is the discrepancy between the constrained and unconstrained distributions, since the latter reflects what the model would prefer to generate in the absence of specification-based filtering. In particular, we would like to avoid forcing the decoder to select tokens that have very low probability under the unconstrained distribution. In practice, we approximate this discrepancy using the domain probe described above, which is simpler to integrate and proved effective in our experiments.
Consider again the laptop example, with a prompt requiring battery to be standard. The decoder may first assign , although this is not required by the prompt. Under the constraints, this choice restricts RAM to ram16 or ram32, which in turn forces . The resulting configuration satisfies the formal specification but conflicts with the request in the prompt. Backtracking makes it possible to revise the earlier CPU assignment and search for an alternative satisfying configuration.
When a P-CONFLICT occurs, the current feasible domain is excluded from the specification, causing the algorithm to reconsider earlier assignments. For a variable and a domain , let denote a formula such that iff . Conjoining with the specification restricts its satisfying assignments to those in which takes a value in . Consequently, conjoining excludes all satisfying assignments in which takes a value in .
Algorithm 2 extends Algorithm 1 by allowing the trail, the stack of unassigned variables, and the generated output to be revised. At each step, the reasoner computes the feasible domain of the current variable under the partial assignment. The function then returns true if the LLM judges that this domain contains at least one value compatible with the prompt. If so, constrained decoding selects a feasible value and generation proceeds as in the forward-only method. If the domain is rejected, the algorithm conjoins to . The updated specification, together with the current partial assignment, becomes inconsistent, so assignments are retracted until satisfiability is restored and generation can resume. If backtracking reaches the root level, the algorithm returns P-UNSAT, indicating that the accumulated prompt-based exclusions are jointly inconsistent with the original specification. This form of backtracking revises locally attractive assignments whose downstream consequences conflict with the prompt. Unlike clause learning in SMT (Nieuwenhuis, Oliveras, and Tinelli 2006), which typically blocks specific combinations of assignments, our blocking is global: once the current feasible domain of a variable is rejected, its values are excluded from all subsequent branches. This avoids enumerating partial assignments and supports real-valued or unbounded domains, where blocking assignments individually may require infinitely many exclusions and cannot guarantee termination. For finite domains, the number of value exclusions is bounded by the sum of the domain sizes, whereas context-sensitive blocking may require exponentially many combinations. This is particularly undesirable in our setting because exploring those combinations entails additional LLM calls, which dominate the computational cost and are precisely what the method aims to minimize. This design deliberately trades conditioning prompt-based exclusions on earlier assignments for bounded progress and is best suited to single-variable preferences, similarly to interactive product configuration, where users choose a value for one parameter at a time from the currently feasible options.
As with Algorithm 1, every assignment returned by Algorithm 2 satisfies the formal specification. The algorithm may additionally report P-UNSAT when the accumulated prompt-based exclusions eliminate every value of some variable.
Experimental Evaluation
In this section, we present an experimental evaluation of our approach, implemented in the SureGen tool. SureGen supports a forward-only variant, SureGen-fw (Algorithm 1), and a backtracking variant, SureGen-bt (Algorithm 2). We evaluate whether SureGen-fw reduces the cost of trial-and-error generation without substantial runtime overhead, and whether SureGen-bt better preserves the LLM's own interpretation of the prompt by resolving detected prompt conflicts through backtracking.
Benchmark We evaluate on 89 instances from four benchmark sources: 23 constraint-based configuration instances from CLib (Subbarayan et al. 2004), 24 feature models from the S.P.L.O.T. collection (Mendonça, Branco, and Cowan 2009), 9 configuration instances from COOM Suite (Baumeister et al. 2026), and 33 instances from the QF_LIA and QF_LRA logics of SMT-LIB (Barrett, Fontaine, and Tinelli 2016). We selected instances that supported repeated feasible-domain analysis within our experimental budget and whose variables admitted meaningful natural-language interpretations for LLM-guided generation. The complete benchmark set covers product and software configuration, scheduling, routing, package management, graph and combinatorial problems, and other numeric constraint tasks. They include Boolean, enumerated, integer, and real-valued variables, range from a few to several thousand variables, and contain both propositional and arithmetic constraints. All instances are represented in SMT-LIB 2 format (Barrett et al. 2010) and solved using Z3 (De Moura and Bjørner 2008).
Experimental setup All experiments were conducted using gpt-oss-120b, deployed with vLLM v0.23.0 on a single NVIDIA B300 SXM6 GPU with tensor parallelism set to 1. The model was served in its native MXFP4 format, with BF16 used for the remaining weights, activations, and computation. The deployment was allocated 10 CPU cores and 60GiB of system memory. Constrained decoding used vLLM's automatic backend selection, with XGrammar as the primary backend and LLGuidance as fallback. The maximum context length was 131072 tokens.
Compared methods and implementation details We implement SureGen-fw and SureGen-bt by assigning variables sequentially, using one OpenAI-compatible API call per non-sinleton domain; throughout the evaluation, we refer to each such API request as an LLM call. Each call receives a JSON Schema describing the current feasible domain and a prompt containing the user requirements together with the previous assignments. The schema supports Boolean, numeric, and enumerated values, including ranges and finite value sets, consistently with existing constrained-decoding tools (Lundberg, Ribeiro et al. 2023; Gerganov 2023). For Boolean and enumerated variables, feasible domains are computed directly from Definition 1; for integer and real variables, possibly with unbounded domains, we use the procedure of (Previti et al. 2017). We compare against sequential rejection sampling (SRS), which mirrors token-level semantic constrained decoding (Nagy et al. 2026) at the variable level: proposed values are retained only if the resulting partial assignment remains extendable to a satisfying assignment; otherwise, they are blocked and resampled.

Figure 2: Runtime comparison between SureGen-fw and SRS.
We also consider S_RND_S, which uses the same procedure but selects values uniformly at random, to assess the benefit of LLM-guided value selection. We additionally implemented complete rejection sampling (RS), which generates one complete assignment at a time, using structured output only, checks it against the formal specification, and retries whenever the candidate is invalid. We tested RS with temperatures 0.2 and 0.5 to introduce sufficient variability and avoid repeatedly producing the same assignment. We also considered variants of RS and SRS in which the formal constraints are included in the prompt (RS_C and SRS_C). Since RS was not competitive in runtime or number of solved instances, and adding the constraints to the prompt provided no consistent reduction in the number of LLM calls while also increasing runtime, we omit these variants from the main results. A detailed account of these negative results is omitted for space.
Evaluation of Forward-Only Decoding
This section evaluates whether specification-guided generation benefits from shifting consistency reasoning to the symbolic solver rather than relying on trial-and-error search. The latter may require many costly LLM calls and depends on the model proposing effective values, which cannot be assumed in general.
We compare SureGen-fw (Algorithm 1) with SRS using the same fixed variable ordering and temperature 0. For finite domains, both SureGen-fw and SRS eventually find a solution whenever one exists. However, SRS relies on value enumeration and therefore does not retain this guarantee for real-valued or unbounded domains. In contrast, SureGen-fw employs the procedure of (Previti et al. 2017) to compute feasible domains without explicitly enumerating their values, allowing it to handle real-valued and

Figure 3: Comparison of the number of LLM calls made by SureGen-fw and SRS
unbounded domains. Figure 2 compares the running times of SureGen-fw and SRS using a timeout of 1200 seconds per instance. SureGen-fw is faster on most matched instances, often substantially so. SRS timed out on three instances, whereas SureGen-fw timed out on one of them. Moreover, SRS failed to return grammar-compliant values on four instances involving real-valued variables, which may be due to the highly fragmented feasible domains produced by repeatedly blocking individual values, making them harder for constrained-decoding tools to represent and enforce reliably. Figure 3 shows that SRS requires substantially more LLM calls than SureGen-fw, which helps explain the runtime difference. In SRS, additional calls are needed whenever a proposed value is rejected by the solver. By filtering the entire feasible domain before decoding, SureGen-fw avoids these retries and directly propagates singleton domains without invoking the LLM. Implied assignments occurred in 96.6% of successful runs, and the median instance had 51.0% of its variables assigned by implication. The additional symbolic reasoning performed by SureGen-fw remained modest: its median share of total runtime was 1.1%, and it remained below 10% on 90.2% of matched solved instances. Thus, shifting consistency reasoning from repeated LLM interaction to the symbolic reasoner reduced inference calls without introducing substantial overhead on the evaluated benchmarks. These results also suggest that, once feasible-domain computation itself becomes prohibitive, repeatedly invoking the LLM to explore and reject infeasible choices is unlikely to improve overall scalability.
Finally, we compare SRS with S_RND_S to assess whether the LLM provides a useful value-selection heuristic. While S_RND_S solved instances with small finite domains, it required more attempts and failed on all QF_LIA and QF_LRA instances. These results suggest that the LLM can provide useful guidance on the large or unbounded domains considered here, although this observation should not be interpreted as a general guarantee. At the same time, this improved guidance does not translate into better runtime performance, since LLM calls remain comparatively expensive.
Evaluation of Backtracking
The goal of backtracking is to improve consistency with the model's judgment by revising earlier assignments when they leave only values it considers unsuitable. To evaluate this behavior, we focus on P-CONFLICT events, which occur when the domain probe judges that the current feasible domain contains no value compatible with the user request and the current partial assignment. In forward mode, a P-CONFLICT is ignored, forcing the decoder to select a value that the LLM itself judged unsuitable. Backtracking instead revises earlier choices, aiming to produce a satisfying assignment that better reflects the model's own interpretation of the prompt. We compare the final assignments produced by the two modes using a post-hoc model-based evaluator. The results therefore measure consistency with the model's own stated preferences while preserving satisfaction of the formal specification, rather than objective semantic optimality. Because the domain probe is only an approximate preference signal, an incorrect negative judgment may exclude a trajectory that would otherwise produce a valid and intent-adherent assignment. Accordingly, P-UNSAT denotes unsatisfiability with respect to the accumulated probe-based exclusions, rather than definitive unsatisfiability of the original prompt and specification. For this evaluation, we instrument forward mode with the same domain probe used by backtracking. Before each assignment, the probe evaluates the current feasible domain under the partial assignment. Forward mode records and ignores negative judgments, whereas backtracking attempts to resolve them by revising previous choices.
Instance Selection We selected 35 of the 89 instances used in the preceding experiment. Whereas the previous experiment evaluated the performance of our approach on instances containing as many as 3,189 variables, this evaluation focuses on the quality of the generated results. We therefore restrict the analysis to instances with at most 66 variables. In addition, a thorough quality assessment required running each instance multiple times with different prompts, substantially increasing the total number of experimental runs.
Results We evaluate output quality through two experiments. First, we construct prompts whose ground-truth outcome is unsatisfiable and measure how often backtracking mode correctly returns P-UNSAT. Second, for each instance, we generate multiple prompts, obtain satisfying assignments from both forward and backtracking modes, and use an LLM judge to determine whether each assignment conflicts with the prompt.
P-UNSAT test To construct ground-truth unsatisfiable prompts, we first computed a complete falsifying assignment and then extracted a minimal falsifying assignment (MFA), defined as a falsifying assignment involving a minimal number of variables. We translated each MFA into a natural-language prompt and asked the backtracking algorithm to find a satisfying assignment. Across 35 instances, backtracking mode correctly returned P-UNSAT for 33. In the remaining two cases, the domain probe failed to recognize that the feasible domains were incompatible with the prompt and instead returned a solution. As expected, forward mode always returned a satisfying solution that, by construction, conflicted with the prompt.
SAT test. In this experiment, we evaluate whether backtracking produces satisfying assignments that better reflect the model's interpretation of the user request. We generated multiple prompts for each instance and retained those for which both backtracking mode and forward mode encountered at least one intent conflict. This yielded 98 instance-prompt pairs, covering all 35 original instances, with most instances contributing more than one prompt. To identify conflicts ignored by forward mode, we instrumented it with the same domain probe used by backtracking mode. Before each assignment, the probe checked whether the current domain contained at least one value compatible with the prompt. Unlike backtracking mode, however, forward mode ignored negative judgments and still selected one of the available values. We then collected the satisfying assignments produced by both modes and evaluated them with two LLM judges, gpt-oss-120b and gpt-5.5. Each judge processed one variable at a time and determined whether its assigned value conflicted with or adhered to the prompt. This post-hoc evaluation is simpler than domain probing during generation, since it assesses a single assigned value rather than an entire domain. All assignments were generated using gpt-oss-120b, which was also used for domain probing. Consequently, the judgments produced by gpt-oss-120b are not independent of the generation process and may be affected by self-consistency bias. This evaluation is nevertheless consistent with our goal of measuring adherence to the generating model's own interpretation of the prompt. To test whether the observed effect also holds under a different evaluator, we additionally judged the same assignments with gpt-5.5. We therefore interpret the gpt-oss-120b results as measuring alignment with the generating model's stated preferences, and the gpt-5.5 results as complementary evidence that the improvement is not solely an artifact of same-model evaluation. Using gpt-oss-120b as the judge, 13 of the 98 assignments produced in backtracking mode were classified as non-adherent to the prompt, compared with 92 of the 98 assignments produced in forward mode. Using gpt-5.5 as the judge, the corresponding counts were 14 and 90, respectively. Thus, both judges found that backtracking substantially reduced assignments containing values judged unsuitable for the prompt.
Related Work
While most existing approaches that combine large language models with reasoning focus on translating natural-language requirements into a formal representation (Ye et al. 2023; Wu, Barrett, and Narodytska 2024; Zhang et al. 2025; Pan et al. 2023), our setting assumes that the formal problem is already given and therefore targets a different, complementary problem. For simplicity, we present the forward method for outputs consisting entirely of assignments to variables in the specification. However, since its target is the token-level specification-guided decoding problem of Definition 2, it can also constrain variables embedded in broader generation processes containing variables outside the specification or content that cannot be fully formalized and may influence the preferred constrained values. Methods that formalize and solve the complete task therefore address a different setting. Related to our approach, but addressing a different problem setting, ChopChop (Nagy et al. 2026) performs semantic constrained decoding for code generation by checking the realizability of partial programs. As discussed in the experimental evaluation, its token-level propose-and-reject procedure corresponds closely to SRS at the assignment level. Bonlarron et al. (2025) combine symbolic reasoning with large language models for constrained text generation. Unlike our setting, their constraints govern textual properties and are introduced dynamically during generation, whereas ours encode semantic relationships over a fixed, pre-specified set of variables.
Conclusions and Future Work
We introduced a specification-guided decoding approach that integrates symbolic reasoning into LLM generation. By incrementally refining the decoding grammar according to feasible values derived from a logical specification, the method goes beyond syntactic validity by enforcing logical dependencies among generated values and guaranteeing that every completed output satisfies the specification by construction. The approach is model-agnostic, requires no retraining, and builds directly on existing grammar-constrained decoding techniques.
Experiments across diverse configuration and constraint-solving benchmarks show that incorporating reasoning into generation reduces repeated LLM inference while guaranteeing compliance with the formal specification.
We also introduced a backtracking extension that prevents forward decoding from selecting values the LLM itself judges unsuitable merely because they remain feasible.
Both approaches depend on the tractability of the underlying reasoning tasks, and some instances may exceed practical resource limits. However, formal specifications of practical interest are not necessarily hard, and our experiments show that many can be handled effectively. By filtering the entire feasible domain before invoking the LLM, our design shifts most of the computational burden to the symbolic solver. This trade-off is favorable because LLM inference is the main performance bottleneck, whereas solver calls are comparatively inexpensive on the instances considered. Moreover, when complete domain filtering is already intractable, methods requiring additional LLM calls or repeated exploration of infeasible choices are unlikely to scale better.
Future work includes developing context-sensitive blocking strategies that retain termination guarantees for real-valued or unbounded domains, and using token probabilities or value rankings to improve domain evaluation.
Acknowledgments
This work was supported by Vinnova, Sweden's innovation agency, the Swedish Research Council, with support through the SAFIR project (Secure AI for Intelligent Resilience and Confidentiality in the Cloud; reference no. 2025-03039).
References
Anil, R.; Borgeaud, S.; Alayrac, J.-B.; Yu, J.; Soricut, R.; et al. 2023. Gemini: A Family of Highly Capable Multimodal Models. CoRR, abs/2312.11805.
Barrett, C.; Fontaine, P.; and Tinelli, C. 2016. The Satisfiability Modulo Theories Library (SMT-LIB). https://www.smtlib.org.
Barrett, C.; Stump, A.; Tinelli, C.; et al. 2010. The smt-lib standard: Version 2.0. In Proceedings of the 8th international workshop on satisfiability modulo theories (Edinburgh, UK), volume 13, 14.
Barrett, C.; and Tinelli, C. 2018. Satisfiability modulo theories. In Handbook of model checking, 305–343. Springer.
Baumeister, J.; Hahn, S.; Herud, K.; Ostrowski, M.; Reutelshöfer, J.; Rühling, N.; Schaub, T.; and Wanko, P. 2026. Towards Industrial-Scale Product Configuration. Theory and Practice of Logic Programming, 1–31.
Beurer-Kellner, L.; Fischer, M.; and Vechev, M. 2024. Guiding LLMs The Right Way: Fast, Non-Invasive Constrained Generation. In Salakhutdinov, R.; Kolter, Z.; Heller, K.; Weller, A.; Oliver, N.; Scarlett, J.; and Berkenkamp, F., eds., Proceedings of the 41st International Conference on Machine Learning, volume 235 of Proceedings of Machine Learning Research, 3658–3673. PMLR.
Bonlarron, A.; Régin, F.; Maria, E. D.; and Régin, J. 2025. Large Language Model Meets Constraint Propagation. In IJCAI, 10036–10044. ijcai.org.
Brown, T. B.; Mann, B.; Ryder, N.; Subbiah, M.; Kaplan, J.; Dhariwal, P.; Neelakantan, A.; Shyam, P.; Sastry, G.; Askell, A.; Agarwal, S.; Herbert-Voss, A.; Krueger, G.; Henighan, T.; Child, R.; Ramesh, A.; Ziegler, D. M.; Wu, J.; Winter, C.; Hesse, C.; Chen, M.; Sigler, E.; Litwin, M.; Gray, S.; Chess, B.; Clark, J.; Berner, C.; McCandlish, S.; Radford, A.; Sutskever, I.; and Amodei, D. 2020. Language Models are Few-Shot Learners. In NeurIPS.
Cai, Y.; Hou, Z.; Sanan, D.; Luan, X.; Lin, Y.; Sun, J.; and Dong, J. S. 2025. Automated Program Refinement: Guide and Verify Code Large Language Models with Refinement Calculus. Proceedings of the ACM on Programming Languages, 9(POPL).
De Moura, L.; and Björner, N. 2008. Z3: An efficient SMT solver. In International conference on Tools and Algorithms for the Construction and Analysis of Systems, 337–340. Springer.
Gerganov, G. 2023. llama.cpp.
Guo, D.; Yang, D.; Zhang, H.; Song, J.; Wang, P.; Zhu, Q.; Xu, R.; Zhang, R.; et al. 2025. DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning. CoRR, abs/2501.12948.
Li, F.; Zhong, J.; Liang, B.; Guo, Z.; and Wang, X. 2025a. Configchecker: Automated Network Configuration Validation with Large Language Model and Knowledge Graph. In 2025 IEEE/ACM 33rd International Symposium on Quality of Service (IWQoS), 1–10.
Li, S.; Gan, Z.; Liu, J.; Gao, C.; Li, F.; Wu, S.; Hu, P.; and Li, F. 2025b. ConfAgent: Towards Intelligent Network Configuration Via LLM Agent. In IWQoS, 1–10. IEEE.
Liu, X.; Yu, H.; Zhang, H.; Xu, Y.; Lei, X.; Lai, H.; Gu, Y.; Ding, H.; Men, K.; Yang, K.; Zhang, S.; Deng, X.; Zeng, A.; Du, Z.; Zhang, C.; Shen, S.; Zhang, T.; Su, Y.; Sun, H.; Huang, M.; Dong, Y.; and Tang, J. 2024. AgentBench: Evaluating LLMs as Agents. In ICLR. OpenReview.net.
Liu, X.-Y.; Wang, G.; Yang, H.; and Zha, D. 2023. FinGPT: Democratizing Internet-scale Data for Financial Large Language Models. In NeurIPS 2023 Workshop on Instruction Tuning and Instruction Following.
Lundberg, S.; Ribeiro, M. T.; et al. 2023. Guidance: A Guidance Language for Controlling Large Language Models. GitHub repository.
Mendonça, M.; Branco, M.; and Cowan, D. D. 2009. S.P.L.O.T.: software product lines online tools. In Arora, S.; and Leavens, G. T., eds., Companion to the 24th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2009, October 25-29, 2009, Orlando, Florida, USA, 761–762. ACM.
Nagy, S.; Zhou, T.; Polikarpova, N.; and D'Antoni, L. 2026. ChopChop: A Programmable Framework for Semantically Constraining the Output of Language Models. Proceedings of the ACM on Programming Languages, 10(POPL).
Nieuwenhuis, R.; Oliveras, A.; and Tinelli, C. 2006. Solving SAT and SAT Modulo Theories: From an abstract Davis–Putnam–Logemann–Loveland procedure to DPLL(T). J. ACM, 53(6): 937–977.
Pan, L.; Albalak, A.; Wang, X.; and Wang, W. Y. 2023. Logic-LM: Empowering Large Language Models with Symbolic Solvers for Faithful Logical Reasoning. In EMNLP (Findings), 3806–3824. Association for Computational Linguistics.
Park, K.; Wang, J.; Berg-Kirkpatrick, T.; Polikarpova, N.; and D'Antoni, L. 2024. Grammar-Aligned Decoding. In NeurIPS.
Poesia, G.; Polozov, A.; Le, V.; Tiwari, A.; Soares, G.; Meek, C.; and Gulwani, S. 2022. Synchronesh: Reliable Code Generation from Pre-trained Language Models. In ICLR. OpenReview.net.
Previti, A.; Ignatiev, A.; Järvisalo, M.; and Marques-Silva, J. 2017. On Computing Generalized Backbones. In ICTAI, 1050–1056. IEEE Computer Society.
Singhal, K.; Azizi, S.; Tu, T.; et al. 2023. Large language models encode clinical knowledge. Nature, 620: 172–180.
Subbarayan, S. K.; Jensen, R. M.; Hadzic, T.; Andersen, H. R.; Hulgaard, H.; and Møller, J. 2004. Comparing Two Implementations of a Complete and Backtrack-Free Interactive Configurator. In Proceedings of the CP-04 Workshop on CSP Techniques with Immediate Application, 97–111. Toronto, Canada.
Touvron, H.; Lavril, T.; Izacard, G.; Martinet, X.; Lachaux, M.; Lacroix, T.; Rozière, B.; Goyal, N.; Hambro, E.; Azhar, F.; Rodriguez, A.; Joulin, A.; Grave, E.; and Lample, G. 2023. LLaMA: Open and Efficient Foundation Language Models. CoRR, abs/2302.13971.
Willard, B. T.; and Louf, R. 2023. Efficient Guided Generation for Large Language Models. arXiv:2307.09702.
Wu, H.; Barrett, C. W.; and Narodytska, N. 2024. Lemur: Integrating Large Language Models in Automated Program Verification. In ICLR. OpenReview.net.
Ye, X.; Chen, Q.; Dillig, I.; and Durrett, G. 2023. SatLM: Satisfiability-Aided Language Models Using Declarative Prompting. In NeurIPS.
Zhang, Y.; Cai, Y.; Zuo, X.; Luan, X.; Wang, K.; Hou, Z.; Zhang, Y.; Wei, Z.; Sun, M.; Sun, J.; Sun, J.; and Dong, J. S. 2025. Position: Trustworthy AI Agents Require the Integration of Large Language Models and Formal Methods. In Singh, A.; Fazel, M.; Hsu, D.; Lacoste-Julien, S.; Berkenkamp, F.; Maharaj, T.; Wagstaff, K.; and Zhu, J., eds., Proceedings of the 42nd International Conference on Machine Learning, volume 267 of Proceedings of Machine Learning Research, 82441–82459. PMLR.