The Trojan Example: Jailbreaking LLMs through Template Filling and Unsafety Reasoning

Mingrui Liu, Sixiao Zhang, Cheng Long, Kwok-Yan LamarXiv 2025 · DOI

Introduction

Large Language Models (LLMs) rely on safety alignment techniques, such as Reinforcement Learning from Human Feedback (RLHF), to prevent the generation of harmful or malicious content. However, these safeguards often suffer from a fundamental logic flaw. This paper introduces TrojFill, a highly effective black-box jailbreak framework that exploits the decoupling of "unsafety reasoning" from content generation. By reframing a malicious request as a "demonstrative example" required for a safety analysis, TrojFill achieves near-universal success rates on state-of-the-art models like GPT-4o and Gemini-2.5.

The Reasoning-Generation Duality

The core of the TrojFill attack lies in the "reasoning-generation duality." While models are trained to refuse direct harmful commands (e.g., "write a bomb tutorial"), they are also optimized to be helpful in analytical contexts. If a user asks a model to "analyze why a bomb tutorial is dangerous," the model often feels compelled to generate the tutorial first as a necessary data point to perform the requested critique. TrojFill automates the exploitation of this cognitive dissonance.

Comparison of naive jailbreak attempts, unsafety reasoning prompts, and the structured TrojFill attack.

The TrojFill Framework

TrojFill utilizes a structured, automated pipeline to bypass safety filters through four key stages:

  1. Unsafe Term Extraction: An auxiliary "Attacker LLM" identifies sensitive keywords in a malicious instruction and replaces them with neutral placeholders (e.g., replacing "bomb" with <an object 1>).
  2. Template Filling: The request is embedded into a "Trojan" template. Instead of asking for harmful content directly, it asks the model to provide a detailed example of a specific text type so that it can then perform a "sentence-by-sentence safety critique."
  3. Adaptive Obfuscation: To evade keyword-based filters, the framework applies strategies such as Caesar ciphers, Base64 encoding, and text splitting (e.g., "b-o-m-b").
  4. Iterative Optimization: The system uses an Attacker LLM to refine the prompt over 5-10 rounds based on whether the target model refuses or complies.

Experimental Results

The researchers evaluated TrojFill using the JBB-Behaviors benchmark, which consists of 100 unsafe instructions spanning 10 harm categories. The attack was tested against frontier APIs (GPT-4o, Gemini-2.5-Pro, DeepSeek-3.1) and efficient models (Llama3-8B, GPT-4.1-mini).

Key Performance Metrics

  • Attack Success Rate (ASR): TrojFill achieved a 100% ASR on Gemini-2.5-Flash and DeepSeek-3.1, and a 97% ASR on GPT-4o.
  • Economic Efficiency: The attack is remarkably inexpensive, costing less than $0.02 per successful jailbreak on commercial APIs.
  • Resilience: The framework remained highly effective even when target models were reinforced with secondary defenses like Llama Guard 3 or OpenAI’s Moderation Endpoint, with performance dropping by less than 5%.

Discussion and Insights

The success of TrojFill reveals a "Capability Paradox": more capable models like GPT-4o are often easier to jailbreak with this method. Because they are better at following complex instructions and performing nuanced reasoning, they are more likely to fall for the structural trap of the "safety analysis" template. Furthermore, prompts optimized for one model showed high transferability (e.g., 91% success from GPT-4.1-mini to GPT-4o), suggesting a systemic vulnerability in current alignment paradigms.

Limitations and Conclusion

TrojFill is slightly less effective in the "Disinformation" category, where a model's internal factual grounding provides a secondary barrier. Additionally, smaller models sometimes struggle with the complex multi-step instructions, leading to hallucinated content.

The authors argue that simple "patch-based" fixes are insufficient. To prevent this type of cognitive reframing, the AI community must develop alignment techniques that more tightly couple the reasoning process with the content generation process.

Summary updated

BibTeX
@misc{liu2025trojan,
  author = {Mingrui Liu and Sixiao Zhang and Cheng Long and Kwok-Yan Lam},
  title = {{The Trojan Example: Jailbreaking LLMs through Template Filling and Unsafety Reasoning}},
  year = {2025},
  eprint = {2510.21190},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.21190},
}
Figure