Python Code Generation by Asking Clarification Questions
Haau-Sing Li, Mohsen Mesgar, André F. T. Martins, Iryna Gurevych
Abstract
Code generation from text requires understanding the user's intent from a natural language description and generating an executable code snippet that satisfies this intent. While recent pretrained language models demonstrate remarkable performance for this task, these models fail when the given natural language description is under-specified. In this work, we introduce a novel and more realistic setup for this task. We hypothesize that the underspecification of a natural language description can be resolved by asking clarification questions. Therefore, we collect and introduce a new dataset named CodeClarQA containing pairs of natural language descriptions and code with created synthetic clarification questions and answers. The empirical results of our evaluation of pretrained language model performance on code generation show that clarifications result in more precisely generated code, as shown by the substantial improvement of model performance in all evaluation metrics. Alongside this, our task and dataset introduce new challenges to the community, including when and what clarification questions should be asked. Our code and dataset are available on GitHub. 1
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
4 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesis cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation cites BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehension
- ClarifyGPT: A Framework for Enhancing LLM-Based Code Generation via Requirements Clarification cites CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesis
- ClarifyGPT: A Framework for Enhancing LLM-Based Code Generation via Requirements Clarification cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
- Identifying & Interactively Refining Ambiguous User Goals for Data Visualization Code Generation cites ClarifyGPT: A Framework for Enhancing LLM-Based Code Generation via Requirements Clarification
Cited by top-tier papers4
- ClarifyGPT: A Framework for Enhancing LLM-Based Code Generation via Requirements ClarificationFangwen Mu, Lin Shi, Song Wang, Zhuohao Yu et al.FSE 2024 · 49 citations
- Topological Active Inference for Task DisambiguationYangbo Wei, Zhen Huang, Shaoqiang Lu, Junhong Qian et al.ICML 2026
- Talking to a Know-It-All GPT or a Second-Guesser Claude? How Repair reveals distinct Multi-Turn Behavior in LLMsClara Lachenmaier, Hannah Bultmann, Sina ZarrießACL 2026
- Identifying & Interactively Refining Ambiguous User Goals for Data Visualization Code GenerationMert Inan, Anthony Sicilia, Alex Xie, Saujas Vaduguru et al.EMNLP 2025
Builds on8
- BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and ComprehensionMike Lewis, Yinhan Liu, Naman Goyal, Marjan Ghazvininejad et al.ACL 2020 · 1,224 citations
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and GenerationYue Wang, Weishi Wang, Shafiq R. Joty, Steven C. H. HoiEMNLP 2021 · 1,224 citations
- CodeGen: An Open Large Language Model for Code with Multi-Turn Program SynthesisErik Nijkamp, Bo Pang, Hiroaki Hayashi, Lifu Tu et al.ICLR 2023 · 234 citations
- Retrieval Augmented Code Generation and SummarizationMd. Rizwan Parvez, Wasi Uddin Ahmad, Saikat Chakraborty, Baishakhi Ray et al.EMNLP Findings 2021 · 141 citations
- Building and Evaluating Open-Domain Dialogue Corpora with Clarifying QuestionsMohammad Aliannejadi, Julia Kiseleva, Aleksandr Chuklin, Jeff Dalton et al.EMNLP 2021 · 61 citations
Related papers
- Prompting with Pseudo-Code InstructionsMayank Mishra, Prince Kumar, Riyaz A. Bhat, Rudra Murthy V et al.EMNLP 2023 · 4 citations
- Clarify Before You Draw: Proactive Agents for Robust Text-to-CAD GenerationBo Yuan, Zelin Zhao, Petr Molodyk, Bin Hu et al.ICML 2026 · 6 citations
- The Vault: A Comprehensive Multilingual Dataset for Advancing Code Understanding and GenerationDung Nguyen Manh, Le Nam Hai, Anh T. V. Dau, Anh Minh Nguyen et al.EMNLP Findings 2023 · 6 citations
- Efficient Hallucination Detection in Automatic Code GenerationGeorgii Andriushchenko, Roman Garaev, Lyudmila Rvanova, Artem Shelmanov et al.ACL Findings 2026
- When Prompts Go Wrong: Evaluating Code Model Robustness to Ambiguous, Contradictory, and Incomplete Task DescriptionsMaya Larbi, Amal Akli, Mike Papadakis, Rihab Bouyousfi et al.ICSE 2026
