Paper · 2410.07295 · ICLR · 2025
IterGen: Iterative Semantic-aware Structured LLM Generation with Backtracking
Sasa Misailovic, Gagandeep Singh, Shubham Ugare, Tarun Suresh, Rohan Gumaste
arXiv · PDF · Open in the Atlas
Code that ran
2 of 2 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 0 failures of our instrument; 0 no recorded run), measured 2026-11-23; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.
- 2 ran with no instrument failure
0 honoured the contract we drafted, 0 violated it, 2 have no contract verdict
- 0 ran where Syntology's instrument failed
failures of Syntology's instrument, not of the code: 0 where our contract draft was wrong, 0 where the contract check could not run
- 0 have no recorded run
- 2 of those that ran constructed an object rather than computing a result
an executed sample whose run returned an instance of its own class (fixture_out_type equals the entry name): the run built an object and did not compute a result
- 0 are pointer only: the body is not served under this paper's link
"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2410.07295.json · badge: /api/ran/2410.07295.svg
Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.
| Repository | Role | Ran |
|---|
| uiuc-arc/itergen |
alias (classifier label) classifier basis: classifier_2025 |
2 ran · 0 no recorded run |
| Function | Status | Where it lives |
|---|
| Trace |
Ran ran on a synthesized input · constructed an object; no result was computed |
uiuc-arc/itergen/itergen/trace.py code served (permissive licence) · get_code("017c3487f2706da6") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, Trace: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import numpy as np
torch.manual_seed(0)
class Trace:
"""
This class stores the whole hisory of given IterGen session. This allows IterGen to provide additional
functionalities where it could avoid taking the generation paths that have already been taken in the past.
We store this history of LLM tokens as a directed graph where each node is a token and each edge is a
transition between two tokens. Each generated token is stored is uniquely identified by the position in the generation and the token index.
"""
def __init__(self):
self.root_token = TraceToken(tid=-1, position=-1, string='', prev_token=None, start_char=-1, end_char=0)
self.current_token = self.root_token
def add_token(self, tid, position, string, start_char, end_char, prob=None):
"""
Add a new token to the trace.
Args:
- tid: Token id
- position: Position in the generation
- string: String representation of the token
- start_char: Start character location of the token in the structured generation
- end_char: End character location of the token in the structured generation
- prob: Probability of the token
"""
new_token = TraceToken(tid, position, string, self.current_token, start_char, end_char, prob)
self.current_token.next_token.append(new_token)
self.current_token = new_token
def backtrack_steps(self, k):
"""
Backtrack k steps in the trace.
"""
for _ in range(k):
self.current_token = self.current_token.prev_token
def backtrack_to_char_pos(self, target_char_pos, keep_trace=True):
"""
Backtrack to a specific character position in the trace.
"""
while self.current_token.end_char > target_char_pos and self.current_token.prev_token is not None:
self.current_token = self.current_token.prev_token
if not keep_trace:
self.current_token.next_token = []
def get_next_token_ids(self):
"""
Get the next token set from the current token.
"""
return [tok.tid for tok in self.current_token.next_token]
def delete_last_token(self):
"""
Delete the last token from the trace.
"""
self.current_token = self.current_token.prev_token
self.current_token.next_token = []
class TraceToken:
"""
This class stores the information about a token in the trace. It stores the token id, the position in the generation, next and the previous token.
Args:
- tid: Token id
- position: Position in the generation
- string: String representation of the token
- prev_token: Previous token
- start_char: Start character location of the token in the structured generation
- end_char: End character location of the token in the structured generation
- prob: Probability of the token
"""
def __init__(self, tid, position, string, prev_token, start_char, end_char, prob=None):
self.tid = tid
self.position = position
self.string = string
self.next_token = []
self.prev_token = prev_token
self.start_char = start_char
self.end_char = end_char
self.prob = prob
ARGS = {}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Trace — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Trace output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| TraceToken |
Ran ran on a synthesized input · constructed an object; no result was computed |
uiuc-arc/itergen/itergen/trace.py code served (permissive licence) · get_code("57548d08b99e62d8") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, TraceToken: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
class TraceToken:
"""
This class stores the information about a token in the trace. It stores the token id, the position in the generation, next and the previous token.
Args:
- tid: Token id
- position: Position in the generation
- string: String representation of the token
- prev_token: Previous token
- start_char: Start character location of the token in the structured generation
- end_char: End character location of the token in the structured generation
- prob: Probability of the token
"""
def __init__(self, tid, position, string, prev_token, start_char, end_char, prob=None):
self.tid = tid
self.position = position
self.string = string
self.next_token = []
self.prev_token = prev_token
self.start_char = start_char
self.end_char = end_char
self.prob = prob
# Create a previous token (can be None for the first token)
prev_token = TraceToken(
tid=0,
position=0,
string="<start>",
prev_token=None,
start_char=0,
end_char=7,
prob=1.0
)
ARGS = {
"tid": 1,
"position": 1,
"string": "hello",
"prev_token": prev_token,
"start_char": 7,
"end_char": 12,
"prob": 0.95
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type TraceToken — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a TraceToken output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
Also present in other papers' code
Of 2 samples lifted from this paper's linked repositories, 2 carry a function identity and 0 do not. Of the 2 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 2 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).
Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.
Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.
Repositories linked to this paper
Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.
Abstract
Large Language Models (LLMs) are widely used for tasks such as natural language and code generation. Still, their outputs often suffer from issues like privacy violations and semantically inaccurate code generation. Current libraries for LLM generation rely on left-to-right decoding without systematic support for backtracking, limiting the ability to correct or refine outputs mid-generation. To address this issue, we introduce ITERGEN, an intuitive framework for iterative, grammar-guided LLM generation that enables users to move both forward and backward within the generated output based on grammar symbols. By leveraging a symbol-to-position mapping, ITERGEN ensures efficient and structured generation while allowing for corrections during the process. We demonstrate ITERGEN's effectiveness in two important applications: reducing privacy leakage in LLM outputs, improving the accuracy of LLM-generated SQL and Vega-Lite queries.
For agents
The same record, over MCP at https://syntology.ai/mcp:
get_harvested_code_for_paper("2410.07295")
get_code_for_paper("2410.07295")
have("2410.07295")
The run record, dated, one paper per request, free:
curl https://syntology.ai/api/ran/2410.07295.json
A badge for a README (the split and the date, never a ratio):
[](https://syntology.ai/paper/2410.07295)
Connect an agent — have() is free.