FactorSpec: Serving Exact Relational Constraints as Speculative Drafts

Jianchang Su, Dawei Xiang, Wei ZhangarXiv 2026

TL;DR

FactorSpec transforms complex relational constraints (like those in trip planning or tool calls) into a high-speed speculative drafter for LLMs. By offloading exact feasibility checks to parallel worker processes and using factor graphs, it achieves up to 1.43x faster decoding and a massive 13.9x increase in valid structured outputs compared to standard syntax-only baselines.

What Problem Does This Paper Address?

LLMs are increasingly tasked with generating structured data—JSON records, tool calls, or complex plans. While current serving engines (like SGLang and vLLM) use grammar masks to ensure syntactic correctness (e.g., "is this valid JSON?"), they struggle with relational correctness.

For example, in a trip itinerary, an LLM might generate a syntactically perfect JSON object that is logically impossible because it schedules a stay in a city without a connecting flight. The authors found that models like Qwen3-8B only produce valid itineraries for about 10% of problems in the NATURAL PLAN benchmark. Standard speculative decoding methods (like n-gram drafters) don't help here because they don't "understand" the underlying rules of the data.

Figure 2. When the model must satisfy the relations, trip and meet- ing records violate them, and retries and reasoning repair few. The share of each full set at 64 in flight whose record is valid, Qwen3- 8B, 95% Wilson intervals; Trip 10 is all 1,599 trip problems; enum schemas on every workload except the ledger; thinking on 64 prob- lems of each planning workload at 8 in flight, range of three runs.

Methods

FactorSpec's core innovation is treating the constraint itself as a speculative drafter.

  1. Factor Graph Compilation: It compiles a JSON Schema and its associated relational constraints into a factor graph. This allows for an exact feasibility check: the system can determine precisely which tokens are "certain" (the only valid choice given previous tokens) and which are "possible."
  2. Lossless Speculative Drafting: Instead of guessing, FactorSpec drafts every token that the constraints determine as certain. This is "lossless" because these tokens must be accepted by a valid decoder.
  3. Parallel Constraint Service: Relational checks (like ensuring all cities in a list are different) are computationally heavier than simple grammar masks. FactorSpec offloads this work to a pool of worker processes that run on the CPU while the GPU is executing the LLM's forward pass.
  4. Per-Request Verify Widths: Unlike standard engines that use a fixed draft length for a whole batch, FactorSpec dynamically adjusts the "verification width" for each request based on how many "certain" tokens it has drafted.
Figure 3: The FactorSpec architecture integrates into a serving engine, using worker processes to compute exact supports and mask rows in parallel with GPU execution.

Datasets

The authors evaluated FactorSpec across six diverse workloads:

  • NATURAL PLAN: Includes Trip, Meeting, and Calendar planning tasks where fields are highly interdependent.
  • Tool-Calling: Includes a synthetic Ledger task, $\tau$-bench retail, and BFCL multi-turn calls, requiring the model to reference specific identifiers (orders, items, files) declared in the prompt.

Key Insights and Ideas

  • Constraints are Drafters: The "aha moment" is realizing that a strict constraint isn't just a filter to be applied at the end; it's a source of information that can proactively propose tokens, speeding up the model.
  • Hiding Latency: By moving the heavy lifting of constraint satisfaction (which can take milliseconds) to worker processes that overlap with GPU time, the cost of "exactness" becomes virtually free in terms of system throughput.
  • Handling State Explosion: Traditional grammars (automata) struggle with joint relations like "all-different" because the number of states explodes. Factor graphs provide a much more compact and efficient way to represent these dependencies.
Figure 5. One decode step at 64 requests in flight, schematic. On the scheduler thread the GPU waits for the constraint’s work; with the service, workers compute ahead during verify t and build the trees while the scheduler processes the result.

Key Results

  • Speedup: FactorSpec decodes up to 1.43x faster than speculators tuned specifically for the workload.
  • Efficiency: It yields up to 10.5 tokens per verify step on planning tasks, significantly outperforming n-gram drafters.
  • Validity: Because it enforces exact constraints, it serves up to 13.9x more valid records per GPU-second than syntax-only baselines.
  • Low Overhead: The exact check's cost is effectively hidden; the system maintains throughput parity with simple grammar engines like XGrammar while providing much stronger guarantees.
Figure 8. Exactness costs what a grammar mask costs, and every record completes. (b) at 8 in flight, enum schemas on every workload except the ledger; (c) over 200 gold records and records served at 64 in flight; (d) at 64 in flight.

Limitations and Future Work

  • Finite Domains: Currently, the system requires variables to have finite domains (e.g., a specific list of cities or a bounded range of days) to build the factor graph.
  • Manual Specification: Users must explicitly declare the relations in the JSON Schema, which requires effort and domain knowledge.
  • Hardware Scaling: As GPUs get faster and forward-pass times shrink, the system may require more CPU worker processes to keep the constraint checking "hidden" behind the GPU latency.
  • Future Direction: The authors suggest extending this to more dynamic relations and potentially automating the extraction of relations from natural language prompts.

Summary updated

Abstract

Speculative decoding speeds up LLM serving by drafting tokens that the target model verifies in one pass, and its gain grows with the drafts the target accepts. Structured outputs should be an ideal case, because much of a record follows from relations among its fields: an itinerary's days follow from its cities' stays and flights. Serving engines, however, draft such text by proposing it from the prompt or a learned head, and their grammar masks enforce only syntax, so the model must satisfy the relations, which it violates: on NATURAL PLAN's trip problems, Qwen3-8B writes a valid itinerary for 10%, and retries that name the violated relation raise this to 14%. We present FactorSpec, which serves exact relational constraints as speculative drafts. FactorSpec compiles a JSON Schema and its relations into a factor graph with an exact feasibility check, drafts every token the constraint determines as certain, verifies each request at a width chosen for it, and computes the masks in worker processes outside the scheduler while the GPU runs. In SGLang, its drafts yield up to 10.5 tokens per verify step, up to 1.9x those of the fastest n-gram drafter, and it decodes up to 1.43x faster than speculators tuned per load, at a grammar mask's cost; it also leads in vLLM. Because every record is also valid, it serves up to 13.9x the valid records per GPU-second of syntax-only baselines.
BibTeX
@misc{su2026factorspec,
  author = {Jianchang Su and Dawei Xiang and Wei Zhang},
  title = {{FactorSpec: Serving Exact Relational Constraints as Speculative Drafts}},
  year = {2026},
  eprint = {2611.02297},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.02297},
}
Figure