The scale and complexity of modern cloud infrastructure have made "Infrastructure-as-Code" (IaC) essential for managing deployments through declarative configurations. While large language models (LLMs) are increasingly used to generate IaC configurations from natural language, user requests are often ambiguous and underspecified. Unlike traditional code generation, it is costly and time-consuming to test IaC configurations during the synthesis, forcing the LLMs into an almost one-shot regime. We observe that ambiguity in IaC synthesis exhibits a compositional structure: configurations decompose into three axes (resources, topology, attributes) where higher-level decisions constrain lower-level ones. We propose a training-free, multi-level disambiguation framework that generates diverse candidate specifications, identifies structural disagreements across these axes, ranks them by informativeness, and produces targeted clarification questions that progressively narrow the configuration space. We further introduce Ambig-IaC, an expert-verified benchmark of 300 validated IaC tasks with ambiguous requests, and define evaluation metrics based on graph edit distance and exact attribute matching. Comprehensive experiments show that our method outperforms existing interactive clarification baselines, with gains that scale with the interaction budget and generalize across models. Extensive ablation studies and analyses further demonstrate its robustness for interactive IaC synthesis.
Figures & tables
Figure 1: An underspecified user request can be satisfied by many plausible cloud infrastructure configurations, each represented as a resource dependency graph (left). Ambiguity arises in choosing resource abstractions and services for compute, networking, storage, in inter-resource topology, and in per-resource configuration attributes, when translating intent into Infrastructure-as-Code (right).
Figure 2: Overview of the iterative disambiguation process for interactive Infrastructure-as-Code synthesis. 1. Users provide an initial IaC request. 2. Initially, a pool of diverse structured specifications is generated based on the current interpretations. 3. Symbolically compute disagreements among the current pool of candidates. 4. These disagreements are ranked to identify the most informative differences measured by entropy. 5. Based on the top-ranked disagreement, the system generates a targeted clarification question. 6. Interaction with the user. 7. If the candidate pool is non-empty, prune candidates inconsistent with the user’s answer. 8. The refined candidate pool is fed back into the next iteration, repeating the process until the interaction budget is exhausted. Otherwise, pool regeneration will be triggered.
Dataset
Natural.
Ambig.
Target Cons.
Normalized score ( 0 – 1 )
IaC-Eval
0.25
0.24
0.90
Ambig-IaC
0.78
0.89
0.99
Inter-coder agreement (Gwet’s AC)
IaC-Eval
0.71
0.82
0.70
Ambig-IaC
0.65
0.82
0.98
Table 1: Human validation of Ambig-IaC and IaC-Eval on 100 samples, with normalized ratings and inter-coder agreement measured by Gwet’s AC. Higher ratings indicate greater naturalness, ambiguity, and target consistency.
Method
Budget K
Struct. (%)
Δ Struct.
R+A F1 (%)
Δ F1
Direct Q Generation
5
43.08 [39.90, 46.31]
-5.87 ( ↓ 11.99% )
17.69 [15.40, 20.05]
-4.35 ( ↓ 19.74% )
Best-of-N
5
41.28 [37.97, 44.68]
-7.67 ( ↓ 15.67% )
18.18 [15.80, 20.68]
-3.86 ( ↓ 17.51% )
Self-Consistency
5
38.59 [35.48, 41.73]
-10.36 ( ↓ 21.16% )
15.63 [13.40, 17.97]
-6.41 ( ↓ 29.08% )
ATD
5
42.23 [38.55, 45.85]
-6.72 ( ↓ 13.73% )
22.70 [20.21, 25.21]
+0.66 ( ↑ 2.99% )
Ours
5
48.95 [45.95, 51.91]
–
22.04 [19.57, 24.63]
–
Direct Q Generation
10
44.38 [41.31, 47.52]
-6.60 ( ↓ 12.95% )
18.72 [16.58, 20.97]
-5.49 ( ↓ 22.68% )
Table 2: Main results on Ambig-IaC using GPT-4o-mini. We report means with 95% task-level bootstrap CIs over 300 tasks (10,000 resamples). Struct. is normalized-GED similarity; R+A F1 is exact-match resource-and-attribute F1; and Δ gives each baseline’s absolute and relative difference from ours. ATD is evaluated at K∈{5,10} due to its substantially higher cost.
Method
Δ Struct.
Δ R+A F1
Direct Q Gen.
+1.62 ( ↑ 3.68% )
+0.38 ( ↑ 2.19% )
Best-of-N
+0.92 ( ↑ 2.25% )
+0.67 ( ↑ 3.62% )
Self-Consistency
-0.20 ( ↓ 0.52% )
+0.25 ( ↑ 1.59% )
Ours
+2.95 ( ↑ 5.86% )
+2.25 ( ↑ 9.71% )
Table 3: Question-budget scaling (GPT-4o-mini): average gain in points per 5-question budget increase, with the relative gain in parentheses ( 5→10 and 10→15 increments, from Table 2 ).
Figure 3: Per-round dynamics show the candidates converging toward a shared interpretation.
Figure 4: Most tasks require three to five regenerations, with performance generally improving as regenerations increase.
Table 8: Hyperparameters of our method. N and Tdiv are swept in the main paper’s sensitivity ablation; the rest are fixed across all experiments.
Model
Method
Tokens/task
Time/task
Claude Opus 4.6
Ours
35.8k
75s
Direct Q Gen.
2.5k
16s
Best-of-N
10.0k
64s
Self-Consistency
10.6k
43s
GPT-4.1-mini
Ours
35.0k
58s
Direct Q Gen.
1.9k
7s
Appendix
Table 9: Per-task cost across five backbone LLMs at K=5 (Ambig-IaC, 300 tasks).
Method
K=5
K=10
K=15
Ours
31.8k / 28s
61.8k / 50s
93.8k / 69s
Direct Q Gen.
1.8k / 3s
2.0k / 4s
2.2k / 6s
Best-of-N
8.2k / 14s
18.0k / 31s
30.0k / 48s
Self-Consistency
8.6k / 13s
25.9k / 38s
55.4k / 91s
Direct ( K=0 )
0.7k / 1s
Appendix
Table 10: Per-task cost (Tokens/task / Time/task) vs. interaction budget K (GPT-4o-mini, Ambig-IaC). Direct is the no-clarification reference.
K
Method
Tokens/task
Time/task
5
Ours
31.8k
28s
ATD
129.1k
303s
10
Ours
61.8k
50s
ATD
1451.6k †
512s
Appendix
Table 11: Per-task cost of ATD vs. ours (GPT-4o-mini, Ambig-IaC). † Includes prompt-cache reads ( ∼ 4.1M cached tokens per task); 188.0 k excluding them.
Method
Struct. (%)
R+A F1 (%)
Ours
54.84
26.53
Ours-BaselineOut
49.07 ( ↓ 10.5% )
26.01 ( ↓ 2.0% )
Direct Q Generation
46.31 ( ↓ 15.5% )
18.45 ( ↓ 30.5% )
Best-of-N
43.12 ( ↓ 21.4% )
19.52 ( ↓ 26.4% )
Self-Consistency
38.19 ( ↓ 30.4% )
16.12 ( ↓ 39.2% )
Appendix
Table 12: Output-protocol ablation (GPT-4o-mini, K=15 , Ambig-IaC). Ours-BaselineOut keeps our question selection but emits the final spec via the baseline clarified-intent regeneration. Parentheses give the relative drop from Ours .
Large language model (LLM)-based program synthesis turns natural-language goals and examples into executable programs, often using tests or formal constraints.
Coding agents can generate code that appears correct but implements behavior the user never intended. This mismatch can arise when an agent silently resolves underspecified requirements through its own assumptions. As subsequent development builds on these assumptions, correcting the resulting behavior can become increasingly costly. Early clarification can help prevent such mismatches, but unnecessary questions can interrupt developers and slow down development. Existing methods struggle to identify key clarification questions while avoiding unnecessary ones. Therefore, we propose CONTRA, a training-free method that combines broad question discovery with semantic and execution-based question qualification. CONTRA first generates candidate questions and filters out those unrelated to required behavior or already resolved by the requirement. For each remaining question, it generates programs conditioned on two plausible answers and checks for stable behavioral differences on shared inputs. It then uses the interaction history to select among qualified questions or stop asking. Experiments on ClarifyCodeBench show that CONTRA achieves the highest F1 with all four coding agents, exceeding the best baseline macro-average F1 by 13.88 percentage points. With the same LLM and evaluation protocol, CONTRA also achieves higher clarification recall and F1 than the coding harnesses Claude Code and OpenHands. To support practical use, we also implement CONTRA as a Claude Code plugin that integrates selective clarification into everyday development.
As LLMs become increasingly capable of implementing software, a critical bottleneck emerges: whether they truly understand what users want. Users often begin with vague intent, leaving important requirements to be clarified through interaction. In repository-level development, misunderstandings can propagate and cause costly rework. However, existing benchmarks typically evaluate implementation from complete specifications or underspecified requests, overlooking pre-coding requirement clarification. Prior clarification studies mainly focus on function-level tasks. It therefore remains unclear how well LLMs can transform vague intent into clear requirements through interaction and how this capability affects subsequent code generation. We introduce ReqClarifyBench, an interactive requirement clarification benchmark for repository-level software development. It contains 341 tasks spanning game, miniapp, and web development, each with a vague user intent, a human-validated requirement document, and code evaluation artifacts. We employ LLM-based user simulators with diverse personas derived from real-world conversations. We evaluate six LLMs in terms of clarification effectiveness and generated requirement document quality. Results show that stronger clarification effectiveness does not necessarily translate into higher document quality, and performance varies substantially across user personas. We also find that coding-agent harnesses do not further improve requirement document quality compared with their base LLMs. These findings offer insights for building LLM-based end-to-end software development systems.
Mingyu Chen, Zhiqing Zhong, Manyi Wang +3
The Chinese University of Hong Kong, Shenzhen, Guangdong, China
Instruction-tuned LLMs faced with underspecified queries often commit to a single interpretation rather than ask for clarification, producing confidently wrong answers. In our experiments, prompting alone is insufficient: models either ask for clarification on every query or ask vague questions that fail to recover the missing information. Addressing this failure requires learning two coupled skills: when to ask rather than answer and how to ask a question that recovers the disambiguating information. Existing recipes either address only one of these skills or require a separately trained critic. We propose CIGAsk, an RL recipe that teaches both skills through two complementary reward signals within a multi-turn GRPO loop. Counterfactual Information Gain (CIG) compares the gold-answer log-likelihood under a frozen reference model with and without the user response, providing per-turn credit that guides how to ask. The Asymmetric Ambiguity Bonus assigns a signed reward at the terminal token based on the gold ambiguity label, guiding when to ask. Across three clarification benchmarks spanning table, passage, and open-domain QA, CIGAsk-7B outperforms the strongest external baseline despite using a smaller backbone. It also transfers across datasets without per-dataset tuning while preserving single-turn QA performance on out-of-distribution benchmarks.
Yunxiang Li, Xixin Wu, Helen Meng
The Chinese University of Hong Kong, Hong Kong SAR, China