Guidelines to Prompt Large Language Models for Code Generation: An Empirical Characterization
Alessandro Midolo, Alessandro Giagnorio, Fiorella Zampetti, Rosalia Tufano, Gabriele Bavota, Massimiliano Di Penta

TL;DR
This paper presents empirically derived guidelines to improve prompt engineering for large language models in code generation, based on iterative testing and practitioner feedback.
Contribution
It introduces a set of 10 specific prompt improvement guidelines for code generation, developed through an iterative, test-driven approach and validated with practitioners.
Findings
Practitioners use prompt improvement patterns variably.
Guidelines enhance understanding of effective prompt design.
Practitioners' perceived usefulness varies from actual usage.
Abstract
Large Language Models (LLMs) are nowadays extensively used for various types of software engineering tasks, primarily code generation. Previous research has shown how suitable prompt engineering could help developers in improving their code generation prompts. However, so far, there do not exist specific guidelines driving developers towards writing suitable prompts for code generation. In this work, we derive and evaluate development-specific prompt optimization guidelines. First, we use an iterative, test-driven approach to automatically refine code generation prompts, and we analyze the outcome of this process to identify prompt improvement items that lead to test passes. We use such elements to elicit 10 guidelines for prompt improvement, related to better specifying I/O, pre-post conditions, providing examples, various types of details, or clarifying ambiguities. We conduct an…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSoftware Engineering Research · Software Engineering Techniques and Practices · Model-Driven Software Engineering Techniques
