PFT: Enhancing Prompt Injection Robustness via Position-Enhanced Finetuning

Zihao Wang, Yibo Jiang, Jiahao Yu, Heqing HuangOpenReview 2025 · Submission to ICLR 2025 · Rejected

Abstract

Large Language Models (LLMs) are widely adopted in closed-domain applications, where differentiating between system instructions and user input is crucial to prevent unintended malicious actions. However, instruction-following LLMs often blindly follow instructions in user inputs, opening up the risk of prompt injection attacks. This paper investigates whether Supervised Fine-Tuning (SFT) can teach LLMs to strictly distinguish system instructions from user input. Our study reveals a key weakness: SFT-tuned models follow system instructions reliably only when the key instruction is placed immediately after the initial tokens. We find that the proximity of the key instruction to the initial tokens significantly influences the model's ability to execute the intended task, and consequently, its susceptibility to prompt injection attacks.To address this issue, we propose PFT, a novel position-enhanced fine-tuning approach that leverages position IDs to more effectively distinguish between system and user tokens. The experimental results demonstrate that PFT improves the robustness of SFT-tuned models against prompt injection attacks, even when the key instruction is placed arbitrarily in the system prompt, without compromising performance. Our work sheds light on the importance of prompt format in enhancing the security of LLMs and offers a practical solution to improve their robustness.
BibTeX
@misc{wang2025pft,
  author = {Zihao Wang and Yibo Jiang and Jiahao Yu and Heqing Huang},
  title = {{PFT: Enhancing Prompt Injection Robustness via Position-Enhanced Finetuning}},
  year = {2025},
  url = {https://openreview.net/forum?id=l3bUmPn6u5},
  howpublished = {OpenReview},
  note = {Submitted to ICLR 2025},
}

Loading related content...

Figure