SecOPD uses on-policy distillation to reduce adaptive prompt injection attack success rate to 9.0%SecOPD: Mitigating Adaptive Prompt Injections by On-Policy Distillation
For adaptive prompt injection, the paper proposes SecOPD, a defense fine-tuning method based on same-policy distillation, reducing PISmith ASR to 9.0% on Qwen3.6-27B (Table 1).
Focus on indirect prompt injection: the user prompt is trusted, external environment data is untrusted, and the attacker controls only that untrusted data and inserts an attack goal g; assuming the system can clearly distinguish trusted from untrusted inputs, the victim model must follow the trusted user instruction I and treat external data only as context, without executing instructions embedded in it.
- Prompt injection is an important security threat to AI agents. Attackers inject malicious instructions into external untrusted data to manipulate model execution. Existing defense fine-tuning based on sequence-level feedback (such as DPO, GRPO) assigns a single score to the entire response, failing to identify which output tokens are unsafe, and remains vulnerable under adaptive attacks.
- We propose SecOPD, a defensive fine-tuning method that introduces on-policy distillation into prompt injection defense. The model generates responses on attacked inputs, and the unattacked clean input is fed to the base model to evaluate the log probabilities of the corresponding tokens, providing token-level advantage signals that encourage the model to output responses as if the injected instructions had not appeared.
- In experiments based on Qwen3.6-27B, SecOPD reduces the PISmith adaptive attack ASR on SEP to 9.0% (Meta-SecAlign is 94.0%, Table 1); on the unseen AgentDojo tool-calling benchmark, it achieves 4.7% ASR while maintaining an average utility of 88.1% (Table 2).
- Only targets indirect prompt injection and assumes the system can clearly distinguish trusted from untrusted inputs; does not apply to jailbreaks or direct prompt injection. The model's reasoning chain does not include awareness of injection, which may affect reasoning-chain-based detection defenses. Experiments are conducted only on the single model Qwen3.6-27B, and thinking mode is disabled during evaluation.
- Evaluated models
- Qwen3.6-27B-SecOPD
- Benchmarks
- SEPAgentDojoAlpacaEval2SEP UtilityMMLU-ProGPQA-DiamondGSM8KMinerva-Math
- Metrics
- ASRpass@10 ASRUtilityAdvUtilitylength-controlled win rate
Researchers at UC Berkeley propose SecOPD, which uses on-policy distillation to provide token-level feedback for defensive fine-tuning, replacing sequence-level signals such as DPO and GRPO. During training, the student model generates rollouts on inputs containing injections, and the frozen initial model scores the same batch of tokens on clean inputs with injections removed; tokens consistent with the trusted task are encouraged, while tokens following the injection are suppressed. On Qwen3.6-27B, against the SoTA adaptive attack PISmith, SecOPD achieves an attack success rate of 9.0%, compared to 94.0% for the previous SoTA Meta-SecAlign and 61.2% for GRPO; under the static SEP attack, SecOPD achieves 1.3%. In the unseen AgentDojo tool-calling scenario, SecOPD achieves 4.7%, Meta-SecAlign 5.5%, and GRPO 0.7% but with utility dropping to 82.5%. Code and models are open-sourced.
Why it was selectedThe paper provides a recipe for defensive fine-tuning with token-level feedback and reports ASR comparisons under adaptive attacks and tool-calling scenarios, which can serve as a reference for selecting defense approaches.
Related events and news
1 events · 1 news mentions
News that mentions this paper
PIPETTE:红队策略覆盖决定注入防御效果
- CSA Labs Researchnames the paperCSA 研究笔记:提示注入红队数据对加固智能体的价值取决于策略覆盖而非数量
Qwen3.6-27B, adaptive TAP / Genetic ASR SecOPD 15.0% / 30.0% 2.5% / 5.0%
Paper analysis
What problem does this paper attempt to solve?
The paper addresses the problem that existing sequence-level defenses struggle against adaptive prompt injection, proposing the SecOPD defense that achieves fine-grained credit assignment through token-level same-policy distillation.
The paper attempts to solve the problem that defensive fine-tuning of large language models and AI agents easily fails against strong adaptive prompt injection attacks.
- Problem scenario and real-world risks: AI agents need to interact with external environments (such as web pages, documents, emails), and untrusted data may hide prompt injection instructions; the authors state that prompt injection is a major threat to AI agents, having already caused deployment delays and risks such as data leaks or malicious tool calls.
- Shortcomings of existing defenses: Existing model-level defenses (such as DPO, GRPO) rely on sequence-level feedback, scoring the entire response as a single unit; the authors point out that this approach struggles to handle mixed responses that simultaneously answer benign tasks and follow injected instructions, and cannot provide token-level precise supervision signals.
- Core observation of the paper: The authors believe that on-policy distillation (OPD) can provide fine-grained token-level reverse KL supervision; during training, a naturally safe teacher distribution can be constructed by providing the base model with clean inputs from which injected instructions have been removed.
- Proposed solution: The paper proposes SecOPD (Secure On-Policy Distillation), a defensive fine-tuning method that uses paired benign and attacked samples to generate token-level advantage signals for fine-tuning the model.
- Threat model:
- Attack goal: induce the victim model to ignore benign user instructions and instead execute the malicious attack goal g inserted into external untrusted data.
- Attacker capabilities: the attacker cannot modify the system or benign user instructions, and can only control external untrusted data and insert specifically phrased injection text into it.
- Attacker knowledge: adaptive attacks are conducted against the target model's prompt structure and defense mechanisms, optimizing attack payloads through reinforcement learning (such as PISmith) or heuristic replacement.
- Victim system: text generation and agent tool-calling systems built on large language models (such as Qwen3.6-27B).
What related research exists?
The paper reviews system-level defenses, model-level sequence feedback defenses, adaptive attacks, and same-policy distillation research, introducing the OPD mechanism into the field of prompt injection security defense.
- System-level defenses:
- External protection and filtering (ProtectAI, 2024; Zarfati, 2024; Chennabasappa et al., 2025, etc.)—deploying prompt shields, input filters, or security isolation mechanisms around the model to defend against injection. The authors note these methods apply to black-box models but cannot directly change the model's own instruction-following behavior.
- Model-level defense fine-tuning:
- Message-type wrapping and injection fine-tuning (Wallace et al., 2024; Chen et al., 2025a,c, etc.)—adding new message roles to wrap untrusted data and including simulated injection instructions in fine-tuning to train the model to treat external data only as context.
- Sequence-level preference and reinforcement learning (Chen et al., 2025c; Guo et al., 2026)—Meta-SecAlign uses DPO to optimize pairwise preferences, while Guo et al. use GRPO with a language model judge providing whole-sentence scalar rewards. The authors note that DPO and GRPO provide only whole-sentence-level feedback and cannot specifically reward or penalize individual tokens in mixed responses.
- Context distillation (Snell et al., 2022)—training the model to reproduce behavior induced by an auxiliary system prompt. The authors state this work is related, but the goal is to train the model's output under attacked inputs to approximate its behavior under clean inputs.
- Adaptive prompt injection attacks:
- Static templates and search- or gradient-based adaptive attacks (Zverev et al., 2025; Zou et al., 2023; Chao et al., 2025, etc.)—static template attacks do not include optimization against the target model; adaptive attacks optimize the injection text against the defended model's prompt structure, including gradient optimization and branch search methods.
- Reinforcement learning adaptive attacks (Wen et al., 2025; Yin et al., 2026)—PISmith uses reinforcement learning to train an attacker model specifically against the target victim model, iteratively generating high-success-rate injection text through black-box feedback.
- Same-policy distillation:
- Practical same-policy distillation (Gu et al., 2024; Lu and Lab, 2025)—provides token-level reverse KL supervision signals on output trajectories sampled by the student model. The authors state that, to their knowledge, same-policy distillation has previously only been used to improve general task capabilities.
- Baseline methods and evaluation benchmarks:
- Baselines include the undefended Qwen3.6-27B native model, DPO-based preference-optimized Meta-SecAlign, and a GRPO approach based on sequence-level reinforcement learning; evaluation benchmarks include the text prompt injection benchmark SEP, the agent tool-calling benchmark AgentDojo, and six general utility benchmarks including AlpacaEval2 and MMLU-Pro.
- Positioning relative to existing work:
- The authors position this work as introducing same-policy distillation into prompt injection defense, using paired inputs to construct an injection-free safe teacher distribution, providing fine-grained token-level supervision to address the credit assignment problem of sequence-level feedback in mixed responses.
- System-level defenses:
How does the paper address this problem?
SecOPD uses the base model under benign inputs as a safety teacher, computes advantage values through cross-context token scoring, and applies fine-grained supervised updates to attacked outputs.
The paper proposes SecOPD (Secure On-Policy Distillation), a defensive fine-tuning method that uses paired benign and attacked inputs, with the base model unaffected by injection serving as a naturally safe teacher, computing token-level advantage values on trajectories generated by the student model itself and applying fine-tuning updates.
Problem setup and formalization
- Benign user instruction is denoted as I, benign external data as c, and clean input is organized into structured messages by a rendering function R.
- The attacker can only control external data; the attacked input is represented as pa = R(I, A(c, g)), where g is the injection goal and A is the injection constructor that inserts g into benign data c.
- The defense goal is to make the model fully follow I when facing pa while ignoring the g embedded in external data, and to maintain the original benign task completion capability on clean inputs.
Paired training data construction
- Paired sample generation: For each benign instruction-following sample (I, c), benign input pc and attacked input pa are constructed, sharing the same trusted instruction and benign context, differing only in whether malicious instructions are injected into the external data.
- Injection style coverage: Following the Meta-SecAlign setup, most training samples use direct insertion (placed at the beginning or end of external data), while a minority use completion-style delimiter spoofing, exposing the model to both direct instruction coverage and role-boundary-crossing attacks.
- Dataset source: From the Cleaned-Alpaca dataset, samples containing non-empty input fields are filtered to build a training set of 19K samples.
Cross-context token-level scoring
- On-policy generation and dual-context evaluation: The student model self-samples trajectories z under attacked input pa, including all previously generated tokens; then the student model computes log probabilities for each token under the attacked input context, while the frozen base model computes log probabilities for the same set of tokens under the clean input context.
- Advantage signal computation: Based on reverse KL divergence estimation, the advantage function for the t-th token is defined as At = sg[ℓteacher,t − ℓθ,t], where the difference in log probabilities between teacher and student reflects the relative plausibility of that token in the clean context, and sg denotes stop gradient.
- Fine-grained credit assignment: If a generated token follows the trusted instruction, the teacher also assigns high probability under the clean input, producing a positive advantage; if a token is generated in response to the injected instruction, the teacher assigns low probability under the clean input, producing a negative advantage to suppress it.
Training configuration and parameter settings
- Decentralized supervision: The fine-tuning process does not require an external safety judge model or task-specific reward model; all supervision information is provided by the same-initialized model's performance under clean inputs.
- Adapter parameter fine-tuning: Both student and teacher models are initialized from Qwen3.6-27B, with teacher weights frozen throughout, and only the student's LoRA adapter parameters are updated, with LoRA rank set to 128 (Table 8).
- Training hyperparameters: Learning rate is set to 1 × 10^-4, sampling temperature to 1.0, maximum generation length to 16K, and the prompt uses clearly distinguished user and input roles (Table 8).
What experiments did the paper conduct?
Experiments cover two safety benchmarks, SEP and AgentDojo, and six utility tests, demonstrating that SecOPD defends against adaptive attacks while largely preserving the model's original capabilities.
Experimental Setup
- Models under test: Four model variants based on Qwen3.6-27B are evaluated: the undefended model Undefended, Meta-SecAlign, GRPO, and SecOPD (each fine-tuned model uses LoRA rank 128).
- Evaluation benchmarks: Safety evaluation uses the text instruction benchmark SEP with 9.1K samples, and the agent tool-calling benchmark AgentDojo v1.2.1 with 949 task pairs (covering Banking, Slack, Travel, and Workspace domains); utility evaluation uses AlpacaEval2, SEP Utility, MMLU-Pro, GPQA-Diamond, GSM8K, and Minerva-Math.
- Attack methods: On SEP, six categories of unoptimized static attack combinations, a Qwen-customized basic adaptive attack based on nearest-neighbor embedding token replacement (Basic Adaptive), and the PISmith adaptive attack with a custom RL-trained attacker are tested; on AgentDojo, the important_instructions static attack is tested.
- Main metrics: Safety evaluation uses attack success rate (ASR), where PISmith reports pass@10 ASR with 10 samples; utility evaluation uses AlpacaEval2 length-controlled win rate, AgentDojo benign task success rate (Utility), and accuracy on each QA reasoning benchmark.
- Review and judgment protocol: SEP uses a two-stage judgment: first, extracted model responses are screened by witness keyword matching; hits are then judged by gemini-3.1-flash-lite and gemini-3-flash-preview with a 4,096 thinking budget, each called 3 times (6 total), and the attack is counted as successful only if all judge YES. AgentDojo determines attack success by whether the attacker-specified malicious tool call is triggered.
- Evaluation scale and decoding configuration: The PISmith adaptive attack runs on 1,024 SEP test samples, with the target model decoding in no-thinking mode and a maximum length of 1,024 (Appendix F); AgentDojo uses thinking mode, with SecOPD and GRPO having a maximum context of 32,768 (Appendix H).
Main Results
Per Table 1 (safety evaluation ASR, lower is better):
Swipe horizontally to read the table
Defense method 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% - Static robustness drops significantly under optimized attacks: The authors note that although Meta-SecAlign reduces SEP static ASR to 28.9% and basic adaptive ASR to 5.5%, under the strong PISmith adaptive attack the ASR reaches 94.0%, close to the undefended model's 97.9%, indicating that static attack results can easily overestimate defense effectiveness under adaptive optimization.
- SecOPD substantially reduces ASR under strong adaptive attacks: In the PISmith evaluation with an attacker trained specifically against the model under test, SecOPD's ASR drops to 9.0%, an order of magnitude lower than the previous baseline Meta-SecAlign, while achieving low ASRs of 1.3% and 0.2% under static and basic adaptive settings, respectively.
- Defense generalizes to unseen agent tool calling: On the AgentDojo tool-calling benchmark not covered in training, SecOPD reduces ASR to 4.7% (lower than Meta-SecAlign's 5.5%), which the authors believe reflects that the learned prompt-data decoupling ability is not limited to specific text markers.
Balancing General Utility and Defense Capability
- Test setup: Benign task performance without attacks is evaluated on seven benchmarks: AlpacaEval2, SEP Utility, AgentDojo, MMLU Pro, GPQA Diam, GSM8K, and Minerva-Math (Table 2).
- Evaluation results: Meta-SecAlign has an average utility of 88.5% (undefended model is 88.1%) but weak adaptive security; GRPO's average utility drops to 83.1% (79.5% on SEP, 82.5% on AgentDojo, 85.1% on Minerva-Math); SecOPD maintains an average utility of 88.1%, reaching 88.6%, 90.7%, and 94.3% on SEP, AgentDojo, and Minerva-Math, respectively (Table 2).
- Authors' interpretation: The authors note that SecOPD is the only defense that broadly maintains original task capability while achieving a low 9.0% PISmith ASR, better resolving the capability degradation caused by GRPO.
Per-Domain Transfer Performance on AgentDojo
- Test setup: Benign task success rate (Utility), task success rate under injection (AdvUtility), and attack success rate (ASR) are evaluated separately in the Banking, Slack, Travel, and Workspace subdomains of AgentDojo (Table 6).
- Evaluation results: In Banking, SecOPD's ASR is 4.9% (Meta-SecAlign is 13.2%); in Slack, ASR is 24.8% (Meta-SecAlign is 31.4%); in Travel, ASR is 6.4% (Meta-SecAlign is 0.0%); in Workspace, ASR is 0.5% (Meta-SecAlign is 0.0%); the all-domain average AdvUtility reaches 79.8% (Table 6).
- Authors' interpretation: The authors believe the defense mechanism learned from pure text training transfers well to tool-calling interactions, but relatively high attack success rates remain in interactive scenarios such as Slack.
Attribution Analysis of Minerva-Math Error Samples
- Test setup: All 46 Minerva-Math problems where the undefended model answers correctly but SecOPD answers incorrectly are manually classified and reviewed (Table 5 and Section J.1).
- Evaluation results: Only 4 cases (8.7%) are genuine mathematical reasoning errors; 20 cases (43.5%) involve the final answer switching to an unrelated question or corrupted answer, 12 cases (26.1%) have correct solutions but are judged wrong due to extraction or formatting, and 10 cases (21.7%) do not output a final answer but all contain the </think> marker, indicating early termination rather than length truncation.
- Authors' interpretation: The authors state this indicates that performance loss from fine-tuning mainly stems from answer organization and format extraction issues, not a systematic decline in mathematical reasoning capability.
Other Ablations and Analyses
- SEP six static attack breakdown: SecOPD's ASR is no higher than 0.5% on each variant: Straightforward (0.3%), Straightforward-Before (0.0%), Ignore (0.5%), Ignore-Before (0.5%), Completion (0.0%), and Completion-Ignore (0.0%) (Table 7).
- Manual review of static SEP evaluation labels: Manual verification of 300 samples (33 model-positive, 267 negative) shows 100% agreement between human judgment and the automated evaluation system (Table 3).
- Qwen adaptive delimiter stability search: Nearest-neighbor embedding replacement tokens are found for the official delimiter, e.g.,
<|im_end|>corresponds to Cyrillic neighbor token 214946, and<|im_start|>corresponds to eihna token 175459 (Table 4).
What are some points that can be further explored?
The authors point out limitations such as applicability only to indirect injection, reliance on trusted-boundary inputs, and reasoning chains lacking injection awareness, and indicate directions for future work.
Limitations and future directions noted by the authors
- Applicable only to indirect prompt injection: The paper explicitly states that this work focuses on indirect prompt injection where user prompts are benign and environment data is malicious, and is not applicable to jailbreaks, direct prompt injection, or scenarios where the user is the malicious attacker (Limitations section).
- Dependence on clear signals of trusted boundaries: The paper notes that the method relies on the assumption that the system can clearly distinguish which parts of the input are trusted, and cannot protect agents that must determine from context which inputs are trusted instructions (Limitations section).
- Reasoning chain lacks injection awareness: SecOPD encourages the model to behave in reasoning and responses as if no injection occurred, and the reasoning chain does not include recognition of or hesitation about the presence of injection. Although this does not reduce output utility, it may affect downstream detection defenses that rely on reasoning chain analysis; the authors list developing robust LLMs with injection-aware reasoning chains as future work (Limitations section).
- Potential vulnerability to stronger future attacks: The paper notes that although ASR was reduced to 9.0% against PISmith attacks, future advances in frontier LLM capabilities may produce more sophisticated attacks that break current defenses. Therefore, the authors do not claim to have completely solved prompt injection, but position this as a stage toward that goal (Limitations section).
Experimental coverage
- Models tested: Experiments were conducted only on the single base model Qwen3.6-27B and its derived fine-tuned versions (Section 5.1).
- Reasoning mode configuration: In PISmith adaptive attack evaluations, victim models were tested with thinking mode disabled (non-thinking mode) (Appendix F); AgentDojo evaluations had thinking mode enabled (Appendix H).
- Attacker training setup: The PISmith adaptive attacker model is initialized from QWEN3-4B-INSTRUCT-2507, trained on 100 samples from PIArena, and evaluations are reported as pass@10 ASR (Appendix F).
- Single training data source: The defensive fine-tuning dataset is constructed entirely from 19K samples filtered from Cleaned-Alpaca, with no training data from other domains mixed in (Section 5.1).
- Unreported information: The paper does not report defense performance under full-parameter fine-tuning or other LoRA ranks, nor does it report experimental data at larger or smaller model parameter scales.
Summarize the main content of the paper
SecOPD, through clean-context token-level on-policy distillation, reduces the adaptive attack ASR to 9.0% on Qwen3.6-27B while preserving the model's general capabilities.
- Positioning and core problem: The paper addresses the issue that existing defensive fine-tuning based on sequence-level feedback such as DPO and GRPO struggles to resist adaptive prompt injection, and proposes the SecOPD defense framework that achieves fine-grained credit assignment through token-level on-policy distillation.
- Core mechanism: During training, SecOPD constructs paired injected and clean inputs for each sample, has the model generate response trajectories under injected inputs, and uses the frozen base model under benign inputs to compute probability differences for corresponding tokens. Through an advantage function, it suppresses malicious injection behavior and reinforces normal task following, without relying on an external safety judge model.
- Adaptive attack defense effectiveness: In evaluations on Qwen3.6-27B, against the strong adaptive attack PISmith, SecOPD reduces pass@10 ASR to 9.0%, a substantial reduction compared to previous baselines Meta-SecAlign (94.0%) and GRPO (61.2%) (Table 1).
- Static attacks and scenario generalization: Under the SEP six-category static attack suite, SecOPD achieves an ASR of 1.3%; on the unseen AgentDojo agent tool-calling benchmark, SecOPD achieves 4.7% ASR, validating the transfer of instruction-data decoupling capability to tool-calling scenarios (Table 1).
- General capability preservation: Across seven general benchmarks covering mathematical reasoning, question answering, and instruction following, SecOPD maintains an average utility of 88.1%, comparable to the undefended base model's 88.1%, avoiding the notable general capability degradation caused by GRPO (Table 2).
- Authors' conclusions and implications: The authors believe the safety potential of frontier LLMs themselves has not been fully exploited; even defensive fine-tuning with simple samples can establish a generalizable safety boundary. While the current defense does not completely solve prompt injection, it provides a new path toward building robust agent foundations.