Last updated:
Which Prompting Technique Should I Use? An Empirical Investigation of Prompting Techniques for Software Engineering Tasks
E. G. Santana Jr et al.
In collections: AI Evals Prompting AI for coding
A growing variety of prompt engineering techniques has been proposed for large language models (LLMs), yet a systematic evaluation of each technique across individual software engineering (SE) tasks remains understudied. In this study we present a systematic evaluation of 14 established prompting techniques on 10 SE tasks using four LLMs. In line with earlier literature, the selected prompting techniques cover six main dimensions (Zero-Shot, Few-Shot, Thought Generation, Ensembling, Self-Criticism and Decomposition). They were evaluated on tasks such as code generation, bug fixing and code-oriented question answering, to name just a few. Our results show which prompting techniques are most effective for SE tasks that require complex logic and intensive reasoning, compared with those that rely more on understanding context and example-based scenarios. We also analyze the correlations between the linguistic features of prompts and the factors that contribute to how effective prompting techniques are at improving SE task performance. In addition, we report the time and token consumption of each prompting technique when applied to a specific task and model, offering practitioners guidance in choosing the optimal technique for their use cases.
Strategies from the report:
Decomposition: A strategy of breaking complex engineering problems into smaller, sequential subtasks. It helps models handle software architecture without losing context and logic.
Thought Generation: Forcing the model to analyze and describe the business logic before it generates the final code or bug fix. This significantly improves effectiveness on tasks that require intensive reasoning.
Self-Criticism: Making the model analyze its own initially generated solution, find errors in it and propose an improved, final version before presenting it to the user.
Ensembling (combining answers): Having the AI generate several different approaches to solving one problem and choosing the most optimal one, e.g. in terms of performance or code cleanliness.
Best practices:
Matching the technique to the specific task: The report indicates that for tasks requiring complex logic (e.g. bug hunting) "Thought Generation" works best, whereas for template-based tasks (e.g. code formatting, writing tests) example-based "Few-Shot" techniques give much better results.
Awareness of time and token costs: Always keep resources in mind. Complicated techniques such as Ensembling or Self-Criticism significantly increase token usage and waiting time for a response, so they should not be used for trivial tasks.
Optimizing the linguistic features of the prompt: The authors note a strong correlation between the precision of the language used and the quality of the generated code. Specific technical vocabulary helps steer the model toward the right solution.
What to avoid
Using one complicated template for everything (One-size-fits-all): Not every prompt engineering technique works equally well on every programming task. Imposing heavy reasoning techniques on simple problems only lowers efficiency and lengthens working time.
Demanding the solution to a huge system all at once: Overly large and complex software engineering requests sent in a single prompt (without using decomposition) drastically increase the risk of "hallucinations" and of generating code that does not work.
Ignoring the context around the code: Using Zero-Shot mode (without giving examples or broader context) when editing complicated software projects leads to code that does not integrate with the rest of the related application.
Support this project by buying me a coffee ;)