arXiv:2610.41998cs.CROct 2026

Manuscript Offprint

arXiv:2610.41998

SecPO: Principled Adversarial Training for Prompt Injection Security

Sizhe Chen, Yibo Peng, Jaewon Chang, Chawin Sitawarin, David Wagner

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Recognized as a top threat to AI agents, prompt injection allows instructions from untrusted data (email, documents, websites) to manipulate the agent's operation. The existing best-defended LLM, Meta-SecAlign, is trained with the DPO loss but still suffers from attack success rates (ASRs) approaching 100% under adaptive prompt injections. One reason is that DPO anchors the model around the undefended reference model, which is insecure. We show an idealized reference model—an injection-invariant, utility-preserving oracle—can nevertheless be approximated, as its output distribution in training is interestingly accessible. This new observation motivates a theoretically principled SecPO loss. Another Meta-SecAlign shortcoming is that it trains on weak simulated attacks. We implement an efficient adversarial training (AT) pipeline that synthesizes strong injected inputs (best@240), and train the model on them. Our AT reduces ASRs by 1.5–14.5× across three SoTA adaptive attacks, compared with Meta-SecAlign; the SecPO loss reduces them by a further 2.4–4.6× compared with using DPO loss. In agentic workflows, our SecPO + AT QWEN3.6-27B is much more secure than Meta-SecAlign: 8.8% vs. 78.8% AgentDojo ASR@800 under the AttackerMovesSecond attack. Moreover, our defended model shows no noticeable reduction in benign utility in nine benchmarks covering agentic tool calling, instruction following, science, and math. We release our code, training data (with optimized injections from AT), and model.

1 Introduction

Rapid progress in large language models (LLMs) unlocks exciting agentic applications: a software engineering agent can work autonomously for seven hours on a complex task in a codebase containing 12.5 million lines of code, with only occasional human guidance [1]. A running agent interacts frequently with the real-world environment (e.g., code repositories, websites, documents) that may not be trusted. An attacker can post malicious content to hijack an agent's execution. In an actual incident, the attacker created a GitHub issue

with a specially crafted title; a coding agent read the malicious title and was hijacked into executing attacker-controlled code [2]. This prompt injection attack is listed as the top threat to AI agents [3]. Vulnerabilities to prompt injection allow external attackers to control the agent through simple actions, such as creating a GitHub issue [2], sending an email [4], or writing a sentence (“disregard all prior instructions and ...”) in a file [5]. AI agent deployment has been held back due to uncontrollable security risks from prompt injections [6].

To mitigate prompt injections, AI agents are expected to only follow instructions from the trusted inputs, while still processing untrusted inputs as context [7]. This behavior can be implemented in the model weights [7–12] or in the system around the model [13–18]. This paper focuses on developing robust LLMs. The current best-defended LLM, Meta-SecAlign [9], is fine-tuned on simulated attacks using direct preference optimization (DPO [19]). Meta-SecAlign, however, has been broken by the latest adaptive prompt injections [20–22] with >95% attack success rates (ASRs).

We show one reason for Meta-SecAlign's vulnerability is that its DPO loss anchors the model around the undefended model. This regularization is intended to avoid drifting too far from its initialization and losing utility when there is no attack. However, this hinders security improvements, as the undefended model is insecure. We therefore ask:

Can we achieve both goals: strong security and the same utility as the undefended model?

If we had an ideal oracle model that achieves both, we could simply approximate its output distribution. We do not have such a model, so there is no way to actually instantiate it. However, we introduce a scheme to predict how an oracle LLM would respond to an injected sample in training. Then, we fine-tune our model to approximate the output distribution of this simulated oracle: we propose Secure Preference Optimization (SecPO), a new loss for optimizing models to be robust against prompt injection. The SecPO loss overcomes this shortcoming in Meta-SecAlign's training objective.

Figure

Figure 1: Our defense, when applied alone, mitigates the strongest prompt injections [20] in real-world agentic tasks [24], even when an attacker makes 800 attempts per task. Our standalone scheme matches the security of GPT-5.5 despite GPT-5.5's substantial resource advantages, including using multiple strong proprietary defense schemes and a model at least two orders of magnitude larger than ours. See Appendix B.6 for details of this figure.

We combine SecPO with adversarial training (AT). AT mitigates another shortcoming of Meta-SecAlign, which trains the model only on weak attacks, but does not train it on strong attacks. We implement an efficient AT pipeline that synthesizes strong attacks using PAIR [23] (best@240), and trains the model on these attacks, equipping it with the ability to defeat unseen test-time adaptive attacks that are more sophisticated.

Our AT reduces ASRs by 1.5–14.5× across three SoTA adaptive attacks, compared with Meta-SecAlign; the SecPO loss reduces them by a further 2.4–4.6× compared with using DPO loss. Trained from QWEN3.6-27B, our SecPO + AT model is much more secure than Meta-SecAlign: 8.8% vs. 78.8% AgentDojo ASR@800 under the current strongest adaptive prompt injection [20]; see Figure 1 for more comparisons. Besides, the maximum ASR of three state-of-the-art (SoTA) adaptive prompt injection attacks [20, 21, 25] is only 13.3% for our model, compared with 94.0% for Meta-SecAlign. We also achieve 7.6% ASR on DTaP-Bench [26], which contains challenging real-world agentic tasks and strong injected prompts. Evaluations on nine challenging benchmarks covering agentic tool calling [24, 26, 27], instruction following [28, 29], science [30, 31], and mathematics [32, 33] show that our defended LLM maintains similar utility on benign tasks as the undefended one.

To make the benefits of computationally expensive AT more widely available, we release our training set with optimized injections from our AT pipeline. Training on it requires no additional attack generation, but yields 2.5–22.5× lower ASRs in our study. Further analysis shows our defended model is interestingly secure against adaptive visual prompt injections [34], even though we do not specify this defense goal. We release our code, training data, and model weights.

References (89)