Skip to content
Free planNo credit card requiredStart writing

article · TUHH Open Research · 2025

Prompting techniques for secure code generation: a systematic investigation

Tony, Catherine, Díaz Ferreyra, Nicolás E., Mutas, Markus, Dhif, Salem, Scandariato, Riccardo

Cited by 0Open access

Abstract

Large Language Models (LLMs) are gaining momentum in software development with prompt-driven programming enabling developers to create code from Natural Language (NL) instructions. However, studies have questioned their ability to produce secure code and, thereby, the quality of prompt-generated software. Alongside, various prompting techniques that carefully tailor prompts have emerged to elicit optimal responses from LLMs. Still, the interplay between such prompting strategies and secure code generation remains underexplored and calls for further investigations. Objective: In this study, we investigate the impact of different prompting techniques on the security of code generated from NL instructions by LLMs. Method: First, we perform a systematic literature review to identify the existing prompting techniques that can be used for code generation tasks. A subset of these techniques are evaluated on GPT-3, GPT-3.5, and GPT-4 models for secure code generation. For this, we used an existing dataset consisting of 150 NL security-relevant code generation prompts. Results: Our work (i) classifies potential prompting techniques for code generation (ii) adapts and evaluates a subset of the identified techniques for secure code generation tasks, and (iii) observes a reduction in security weaknesses across the tested LLMs, especially after using an existing technique called Recursive Criticism and Improvement (RCI), contributing valuable insights to the ongoing discourse on LLM-generated code security.

Cite this paper

APA 7

Tony, C., Díaz Ferreyra, N. E., Mutas, M., Dhif, S., & Scandariato, R. (2025). Prompting techniques for secure code generation: a systematic investigation. TUHH Open Research. https://doi.org/10.15480/882.16085

MLA 9

Tony, Catherine, et al. “Prompting techniques for secure code generation: a systematic investigation.” TUHH Open Research, 2025, https://doi.org/10.15480/882.16085.

Chicago

Tony, Catherine, Nicolás E. Díaz Ferreyra, Markus Mutas, Salem Dhif, and Riccardo Scandariato. 2025. “Prompting techniques for secure code generation: a systematic investigation.” TUHH Open Research. https://doi.org/10.15480/882.16085.

Harvard

Tony, C. et al. (2025) ‘Prompting techniques for secure code generation: a systematic investigation’, TUHH Open Research. Available at: https://doi.org/10.15480/882.16085.

BibTeX
@article{tony2025prompting,
  title = {{Prompting techniques for secure code generation: a systematic investigation}},
  author = {Tony, Catherine and Díaz Ferreyra, Nicolás E. and Mutas, Markus and Dhif, Salem and Scandariato, Riccardo},
  journal = {TUHH Open Research},
  year = {2025},
  doi = {10.15480/882.16085}
}

Made from the index record. Check names, capitalisation and page numbers against the paper. Need another style? AI for Research has over 10,000.