SecOPD: Mitigating Adaptive Prompt Injections by On-Policy Distillation
Organizations: University of California, Berkeley
Abstract
Prompt injection is listed as the #1 threat to AI agents. When an agent accesses external data from websites, files, or emails, an attacker may inject a prompt into the data, saying, "Ignore all prior instructions and perform <an attacker's task>." To prevent arbitrary manipulation of agents, defenders try to train secure LLMs, which, however, still suffer from near 100% attack success rates (ASRs) against adaptive prompt injections. We note that this is because existing defensive finetuning recipes rely on sequence-level feedback signals (in DPO or GRPO). Treating an entire output equally prevents the model from learning precisely which output tokens are insecure. In this paper, we propose Secure On-Policy Distillation (SecOPD) that provides token-level feedback to guide defensive fine-tuning. The LLM receives an injected sample and produces a rollout, whose tokens are scored by the initialization model given the corresponding clean input. With more fine-grained training signals, our defended Qwen3.6-27B achieves a 9.0% ASR against the SoTA PISmith adaptive prompt injections, compared to 94.0% for the prior SoTA, Meta-SecAlign. The obtained security generalizes to domains completely unseen in training: in agentic tool calling, SecOPD achieves a 4.7% ASR compared to 5.5% for Meta-SecAlign. Code and the model are available at https://github.com/pppyb/SecOPD and https://huggingface.co/pybbb/Qwen3.6-27B-SecOPD.
Figures & tables
| Defense Attack | SEP Static | SEP Basic Adaptive | SEP PISmith Adaptive | AgentDojo Static |
| Undefended | 99.4% | 99.0% | 97.9% | 26.7% |
| Meta-SecAlign | 28.9% | 5.5% | 94.0% | 5.5% |
| GRPO | 15.0% | 2.3% | 61.2% | 0.7% |
| SecOPD | 1.3% | 0.2% | 9.0% | 4.7% |
| Defense | AlpacaEval2 | SEP | AgentDojo | MMLU Pro | GPQA Diam | GSM8K | Minrv. Math |
| Undefended | 81.4% | 88.0% | 92.8% | 84.1% | 79.8% | 97.7% | 92.7% |
| Meta-SecAlign | 82.3% | 89.3% | 92.8% | 83.8% | 78.3% | 97.8% | 95.1% |
| GRPO | 76.0% | 79.5% | 82.5% | 83.0% | 77.8% | 97.4% | 85.1% |
| SecOPD | 80.1% | 88.6% | 90.7% | 84.1% | 81.3% | 97.4% | 94.3% |
Appendix figures & tables6 assets
Supplementary material from the paper’s appendix.
Appendix
| Attack | Eval.+ | Human+ | FP | FN | Agree | |
| Straightforward | 50 | 21 | 21 | 0 | 0 | 100% |
| Straightforward-before | 50 | 6 | 6 | 0 | 0 | 100% |
| Ignore | 50 | 3 | 3 | 0 | 0 | 100% |
| Ignore-before | 50 | 3 | 3 | 0 | 0 | 100% |
| Completion | 50 | 0 | 0 | 0 | 0 | 100% |
| Completion-ignore | 50 | 0 | 0 | 0 | 0 | 100% |
| Official delimiter | Substitute description | Token ID |
| <|im_end|> | Cyrillic near-neighbor token | 214946 |
| <|im_start|> | eihna | 175459 |
| Failure pattern | Count | Fraction |
| Final-answer span switches to an unrelated problem | 20 | 43.5% |
| Correct answer, but extraction or formatting is marked incorrect | 12 | 26.1% |
| Incomplete answer finalization | 10 | 21.7% |
| Genuine reasoning error | 4 | 8.7% |
| Method | Banking | Slack | Travel | Workspace | All | ||||||||||
| Utility | AdvUtility | ASR | Utility | AdvUtility | ASR | Utility | AdvUtility | ASR | Utility | AdvUtility | ASR | Utility | AdvUtility | ASR | |
| Undefended | 100.0% | 77.8% | 39.6% | 95.2% | 72.4% | 67.6% | 80.0% | 55.7% | 42.1% | 95.0% | 77.9% | 11.8% | 92.8% | 74.0% | 26.7% |
| Meta-SecAlign | 87.5% | 81.3% | 13.2% | 95.2% | 69.5% | 31.4% | 90.0% | 88.6% | 0.0% | 95.0% | 97.7% | 0.0% | 92.8% | 90.7% | 5.5% |
| GRPO | 81.3% | 61.8% | 0.7% | 85.7% | 61.9% | 3.8% | 85.0% | 87.1% | 0.7% | 80.0% | 85.0% | 0.2% | 82.5% | 79.2% | 0.7% |
| SecOPD (ours) | 87.5% | 68.1% | 4.9% | 90.5% | 50.5% | 24.8% | 90.0% | 70.0% | 6.4% | 92.5% | 90.7% | 0.5% | 90.7% | 79.8% | 4.7% |
| Method | Straight. | Straight. Before | Ignore | Ignore Before | Completion | Completion Ignore | Combined |
| Undefended | 82.2% | 72.0% | 79.7% | 64.8% | 97.1% | 96.8% | 99.4% |
| Meta-SecAlign | 23.5% | 4.1% | 5.6% | 1.7% | 7.4% | 1.6% | 28.9% |
| GRPO | 2.9% | 4.7% | 0.3% | 1.1% | 9.7% | 0.1% | 15.0% |
| SecOPD (ours) | 0.3% | 0.0% | 0.5% | 0.5% | 0.0% | 0.0% | 1.3% |
| Configuration | Value |
| Initialization model | Qwen3.6-27B |
| Teacher model | Frozen initialization model |
| Trainable parameters | Student LoRA adapter |
| LoRA rank | 128 |
| Learning rate | |
| Sampling temperature | 1.0 |