Lune

ICLR2025Top-tier venue

IterGen: Iterative Semantic-aware Structured LLM Generation with Backtracking

Shubham Ugare, Rohan Gumaste, Tarun Suresh, Gagandeep Singh, Sasa Misailovic

Abstract

Large Language Models (LLMs) are widely used for tasks such as natural language and code generation, but their outputs often suffer from issues like hallucination, toxicity, and incorrect results. Current libraries for structured LLM generation rely on left-to-right decoding without support for backtracking, limiting the ability to correct or refine outputs mid-generation. To address this, we introduce IterGen, a user-friendly library 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 and maintaining the key-value (KV) cache state, 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.Our code and additional resources are available at https://structuredllm.com.

Ask Lune

Ask anything. The answer quotes the paper.

Lune reads all of it and the papers around it, then shows you the passages behind every answer.

Questions to start from

Lune answers from

the full paper · 4 top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Cited by top-tier papers4

  1. Generate, but Verify: Reducing Hallucination in Vision-Language Models with Retrospective ResamplingTsung-Han Wu, Heekyung Lee, Jiaxin Ge, Joseph E. Gonzalez et al.NeurIPS 2025 · 33 citations
  2. Token-Guard: Towards Token-Level Hallucination Control via Self-Checking DecodingYifan Zhu, Huiqiang Rong, Haoran LuoICLR 2026
  3. TreeCoder: Systematic Exploration and Optimisation of Decoding and Constraints for LLM Code GenerationHenrijs Princis, Arindam Sharma, Cristina DavidPLDI 2026
  4. Lookahead-Then-Verify: Reliable Constrained Decoding for Diffusion LLMs under Context-Free GrammarsYitong Zhang, Yongmin Li, Yuetong Liu, Jia Li et al.ISSTA 2026

Builds on7

  1. Synchromesh: Reliable Code Generation from Pre-trained Language ModelsGabriel Poesia, Alex Polozov, Vu Le, Ashish Tiwari et al.ICLR 2022 · 200 citations
  2. Prompting Is Programming: A Query Language for Large Language ModelsLuca Beurer-Kellner, Marc Fischer, Martin T. VechevPLDI 2023 · 114 citations
  3. Copiloting the Copilots: Fusing Large Language Models with Completion Engines for Automated Program RepairYuxiang Wei, Chunqiu Steven Xia, Lingming ZhangFSE 2023 · 111 citations
  4. Guiding LLMs The Right Way: Fast, Non-Invasive Constrained GenerationLuca Beurer-Kellner, Marc Fischer, Martin T. VechevICML 2024 · 93 citations
  5. Collecting and Characterizing Natural Language Utterances for Specifying Data VisualizationsArjun Srinivasan, Nikhila Nyapathy, Bongshin Lee, Steven Mark Drucker et al.CHI 2021 · 55 citations

Related papers

  1. ROCODE: Integrating Backtracking Mechanism and Program Analysis in Large Language Models for Code GenerationXue Jiang, Yihong Dong, Yongding Tao, Huanyu Liu et al.ICSE 2025 · 6 citations
  2. DocCGen: Document-based Controlled Code GenerationSameer Pimparkhede, Mehant Kammakomati, Srikanth Tamilselvam, Prince Kumar et al.EMNLP 2024 · 4 citations
  3. Structure-Guided Large Language Models for Text-to-SQL GenerationQinggang Zhang, Hao Chen, Junnan Dong, Shengyuan Chen et al.ICML 2025
  4. Automated Program Refinement: Guide and Verify Code Large Language Model with Refinement CalculusYufan Cai, Zhe Hou, David Sanán, Xiaokun Luan et al.POPL 2025 · 20 citations
  5. The First Prompt Counts the Most! An Evaluation of Large Language Models on Iterative Example-Based Code GenerationYingjie Fu, Bozhou Li, Linyi Li, Wentao Zhang et al.ISSTA 2025 · 3 citations
Dusk over the sea between two cliffs drawn in fine vertical lines