Unintended Misalignment from Agentic Fine-Tuning: Risks and Mitigation

Dongyoon Hahm, Taywon Min, Woogyeol Jin, Kimin Lee · DOI

Introduction

Fine-tuning Large Language Models (LLMs) on domain-specific agentic datasets—such as web navigation or code generation—is a standard practice to enhance their utility. However, research indicates that this process often leads to "unintended misalignment," where the model's safety guardrails are eroded. A model previously aligned to refuse harmful requests may, after agentic fine-tuning, execute dangerous commands if they are presented within the context of its new capabilities.

The Risk of Agentic Fine-Tuning

The core issue is that performance-focused fine-tuning often "overwrites" safety alignment. For instance, a model fine-tuned for web navigation might correctly identify and click on links for illicit substances when prompted, despite its base version being trained to refuse such requests. This capability-safety trade-off is significant: fine-tuning Llama-3.1-8B-Instruct on web tasks can improve success rates by 20% while simultaneously increasing the Attack Success Rate (ASR) by nearly 40%.

PING: A Lightweight Mitigation

To address this, we introduce Prefix INjection Guard (PING). PING is an inference-time strategy that prepends an automatically generated natural language prefix to the model's response. This steers the model back toward a refusal path for harmful prompts without requiring expensive re-training.

Overview of agentic misalignment and the PING mitigation strategy.

Automatic Prefix Selection

The PING system uses an Automatic Prefix Selection algorithm. A generator LLM proposes candidate prefixes, which are then iteratively evaluated and refined based on their ability to maximize the Refusal Rate (RR) on harmful tasks while maintaining the Success Rate (SR) on benign ones. This automated approach ensures that the prefixes are optimized for the specific model and task domain without manual trial-and-error.

Mechanistic Insights: Initial Tokens are Destiny

Mechanistic analysis reveals that the first few tokens of a response are critical decision points. If a model begins with a refusal (e.g., "I cannot"), it typically remains safe throughout the generation. Conversely, if it begins with an action or tool call, the safety guardrails have already failed.

Comparison of token probabilities between an aligned model and a misaligned agent.

Interestingly, internal safety features often persist even in misaligned models. Linear probing shows that the model's internal states still contain safety-relevant information. PING works by amplifying these latent features at the start of the generation process, effectively "reminding" the model of its safety training at the moment it decides its next action.

Evaluation and Results

PING was evaluated across web navigation (WebArena-lite, WebDojo) and code generation (MINT-ALFWorld, RedCode-Exec) benchmarks. The results demonstrate a robust defense:

  • Significant Safety Gains: PING increased refusal rates by an average of 66.2% in web tasks and 44.6% in coding tasks compared to baseline fine-tuned agents.
  • Minimal Performance Hit: The impact on benign task performance was negligible, with only a 1.8% average drop in success rate.
  • Layered Defense: PING is compatible with external guardrail models like LlamaGuard3 and WildGuard, providing an additional layer of security that further boosts refusal rates without sacrificing performance.

Conclusion

Unintended misalignment is a serious hurdle for deploying safe agentic LLMs. PING offers a robust, lightweight solution that restores safety guardrails by leveraging the model's own internal representations at the critical start of response generation. This approach allows developers to reap the benefits of agentic fine-tuning while maintaining the rigorous safety standards required for real-world deployment.

Summary updated

BibTeX
@inproceedings{hahm2026unintended,
  author = {Dongyoon Hahm and Taywon Min and Woogyeol Jin and Kimin Lee},
  title = {{Unintended Misalignment from Agentic Fine-Tuning: Risks and Mitigation}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2026},
  url = {https://openreview.net/forum?id=fwacGK34b8},
}
Figure