SecOPD: Mitigating Adaptive Prompt Injections by On-Policy Distillation
If you're building LLM-powered agents that touch external data — emails, web pages, files — prompt injection is your biggest security headache, and existing defenses have been embarrassingly easy to break. This paper identifies *why*: current defensive fine-tuning methods treat an entire model output as uniformly good or bad, so the model never learns exactly which tokens represent a security failure. SecOPD fixes this with token-level feedback during fine-tuning, scoring each output token against what the model would have produced on clean (non-injected) input. The result is dramatic: their defended Qwen3.6-27B drops attack success rates from 94% down to 9% against state-of-the-art adaptive injections, and the security generalizes to agentic tool-calling scenarios the model was never trained on.
Takeaways3
- Token-level feedback during fine-tuning is far more effective than sequence-level signals (DPO/GRPO) for teaching a model to resist prompt injection.
- Security learned from one domain (e.g., document-based injection) generalizes surprisingly well to unseen agentic tool-calling scenarios.
- The model and code are open-source, making this a practical starting point for teams that need to harden their own agents.





