NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Interactive Code Generation via Test-Driven User-Intent Formalization

Shuvendu K. Lahiri, Sarah Fakhoury, Aaditya Naik, Georgios Sakkas, Saikat Chakraborty, Madanlal Musuvathi, Piali Choudhury, Curtis von Veh, Jeevana Priya Inala, Chenglong Wang, Jianfeng Gao

TL;DR

LLMs are powerful code generators but often stumble over ambiguous natural language prompts. This paper introduces TiCoder, a tool that uses an interactive, test-driven workflow to formalize user intent by asking the user to validate generated unit tests, which then prunes and ranks code suggestions to significantly boost accuracy.

What Problem Does This Paper Address?

While Large Language Models (LLMs) like Codex can generate impressive code snippets from natural language (NL), NL is inherently ambiguous. A prompt like "Write a function that returns true if the input string contains sequences of lowercase letters joined with an underscore" leaves several questions unanswered: Must the entire string match? How many sequences are allowed?

Because NL lacks formal semantics, it is difficult to define "correctness." Users often have to manually scan dozens of code suggestions, which is mentally taxing and error-prone. While "Programming by Example" (PBE) helps, users often struggle to come up with enough diverse examples to narrow down the search space effectively.

Methods

The authors propose a workflow called Interactive Test-Driven Code Generation (ITDCG). Instead of just showing the user a list of code, the system engages in a dialogue centered around unit tests.

The TiCoder Workflow

  1. Generation: Given an NL intent, the system uses an LLM to generate both candidate code snippets and candidate unit tests.
  2. Test Selection: The system selects a "discriminative" test—one that splits the pool of code candidates (e.g., half the candidates pass it, half fail).
  3. User Interaction: The system asks the user: "Is this test consistent with your intent?" The user responds with YES, NO, or UNDEFINED.
  4. Pruning & Ranking:
    • If the user says YES, all code candidates that fail the test are discarded.
  5. If the user says NO, all code candidates that pass the test are discarded.
  6. Iteration: This process repeats for a set number of rounds or until the candidate pool is sufficiently narrowed.
Fig. 1: Workflow for interactive test-driven code generation (ITDCG).

Key Technical Components

  • Test Mutation: TiCoder doesn't just rely on raw LLM output. It uses Static Mutation (pruning multi-assertion tests to single assertions to increase the chance of a clear user response) and Dynamic Mutation (executing candidate code to generate new, plausible output values for existing test inputs).
  • Discriminative Ranking: To minimize user effort, TiCoder prioritizes tests that maximize the "pruning power"—choosing tests that best differentiate between the current set of code suggestions.

Datasets

The researchers evaluated TiCoder using two standard Python benchmarks:

  • MBPP (Mostly Basic Python Problems): 427 tasks involving basic programming concepts.
  • HumanEval: 164 hand-written programming tasks.
  • Note: The authors modified HumanEval to remove explicit examples from the docstrings, ensuring the model had to rely on the NL description and the interactive loop rather than just copying provided examples.

Key Insights and Ideas

  • Tests as "Weak" Formal Specs: Validating an input-output pair is much easier for a human than writing a formal specification or a full suite of examples from scratch. It serves as a lightweight bridge between informal NL and formal code.
  • LLMs are Good Test Generators: One of the paper's "aha" moments is that LLMs are capable of generating useful test cases even before the correct code is finalized.
  • The Power of "NO": Negative feedback is incredibly potent. Rejecting a single test can prune a large number of "natural-looking" but logically incorrect code suggestions that a user might have otherwise overlooked.
  • Closing the Gap to "Ideal": The study shows that with just 5 user queries, TiCoder's performance approaches the "IdealRanking" (an upper bound where the system perfectly knows which codes are correct).

Key Results

TiCoder demonstrated massive improvements in the pass@1 metric (the probability that the top-ranked suggestion is correct):

  • MBPP: Accuracy improved by 22.49% with just one user query and 37.71% with five queries.
  • HumanEval: Accuracy jumped by 24.79% with one query and a staggering 53.98% with five queries.
  • Efficiency: On average, it took only 1.5 to 1.7 queries to find a test that correctly matched the user's intent.
Fig. 5: Code accuracy results.

As seen in Figure 5, TiCoder (green bars) consistently outperforms the raw LLM (Codex) and even recent non-interactive methods like CodeT, especially as the number of candidates ($k$) increases.

Limitations and Future Work

  • Simulated Users: The evaluation used the ground-truth reference code as an "oracle" to simulate user responses. Real-world human cognitive load and potential for user error in validating tests were not measured.
  • Scope: The current implementation focuses on single-function Python tasks. Extending this to multi-file projects or stateful APIs remains a challenge.
  • Stochasticity: The researchers noted that LLM outputs can be unstable; they mitigated this by caching responses, but real-time production systems would need to handle this variability.
  • Future Directions: The authors plan to conduct human user studies and explore richer formal specifications, such as parameterized tests or procedure summaries.

Summary updated

BibTeX
@misc{lahiri2022interactive,
  author = {Shuvendu K. Lahiri and Sarah Fakhoury and Aaditya Naik and Georgios Sakkas and Saikat Chakraborty and Madanlal Musuvathi and Piali Choudhury and Curtis von Veh and Jeevana Priya Inala and Chenglong Wang and Jianfeng Gao},
  title = {{Interactive Code Generation via Test-Driven User-Intent Formalization}},
  year = {2022},
  eprint = {2208.05950},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2208.05950},
}
Figure