TEMPLATEFUZZ: Fine-Grained Chat Template Fuzzing for Jailbreaking and Red Teaming LLMs
Organizations: School of Computer Software, Tianjin University, Tianjin, China · Monash University, Monash, Australia
Abstract
Large Language Models (LLMs) are increasingly deployed across diverse domains, yet their vulnerability to jailbreak attacks, where adversarial inputs bypass safety mechanisms to elicit harmful outputs, poses significant security risks. While prior work has primarily focused on prompt injection attacks, these approaches often require resource-intensive prompt engineering and overlook other critical components, such as chat templates. This paper introduces TEMPLATEFUZZ, a fine-grained fuzzing framework that systematically exposes vulnerabilities in chat templates, a critical yet underexplored attack surface in LLMs. Specifically, TEMPLATEFUZZ (1) designs a series of element-level mutation rules to generate diverse chat template variants, (2) proposes a heuristic search strategy to guide the chat template generation toward the direction of amplifying the attack success rate (ASR) while preserving model accuracy, and (3) integrates an active learning-based strategy to derive a lightweight rule-based oracle for accurate and efficient jailbreak evaluation. Evaluated on twelve open-source LLMs across multiple attack scenarios, TEMPLATEFUZZ achieves an average ASR of 98.2% with only 1.1% accuracy degradation, outperforming state-of-the-art methods by 9.1%-47.9% in ASR and 8.4% in accuracy degradation. Moreover, even on five industry-leading commercial LLMs where chat templates cannot be specified, TEMPLATEFUZZ attains a 90% average ASR via chat template-based prompt injection attacks.
Figures & tables
| Method | Budget=50 | Budget=100 | ||
| JQ | AQJ | JQ | AQJ | |
| GPTFuzzer | 8/50 | 9.38 | 15/50 | 38.70 |
| TurboFuzzLLM | 20/50 | 25.05 | 33/50 | 46.12 |
| TemplateFuzz | 45/50 | 9.31 | 47/50 | 12.89 |
| Model | TemplateFuzz | ChatBug | ||||||
| Top-1 Template | Mismatch- | Mismatch-V | Mismatch-C | |||||
| ASR | ACC | ASR | ACC | ASR | ACC | ASR | ACC | |
| Gemma3-4B | 99.04% | 1.01% | 21.54% | 6.99% | 19.42% | 9.10% | 27.12% | 6.53% |
| DeepSeek-7B | 98.84% | 1.41% | 73.08% | 6.62% | 12.88% | 3.72% | 26.73% | 13.04% |
| Llama2-7B | 95.58% | 0.21% | 28.85% | 1.18% | 0.96% | 1.71% | 4.04% | 17.20% |
| Qwen2.5-7B | 90.96% | 0.04% | 5.78% | 22.65% | 1.35% | 27.92% | 7.88% | 3.28% |
| Mutation Rules | ASR(ACC) | |
| Top-1 | Top-5 | |
| Direct Attack (without mutation) | 0.00% (0.00%) | 0.00%(0.00%) |
| System Message (M1) | 28.84% (1.46%↓) | 51.92% (1.72%↓) |
| User/Assistant Message (M2) | 60.38% (1.83%↓) | 78.65% (1.99%↓) |
| Role Marker (M3) | 27.30% (1.33%↓) | 41.92% (2.27%↓) |
| Delimiter (M4) | 55.19% (0.62%↓) | 75.19% (1.55%↓) |
| Variants | Top-1 ASR (ACC) | Top-5 ASR (ACC) |
| TemplateFuzz no_sample | 87.88% (1.04%↓) | 100% (1.60%↓) |
| TemplateFuzz random | 74.04% (3.44%↓) | 86.35% (2.01%↓) |
| TemplateFuzz genetic | 83.27% (4.01%↓) | 98.08% (2.53%↓) |
| TemplateFuzz | 95.58% (0.21%↑) | 100% (0.99%↓) |
| Strategy | Accuracy | TPR | FPR | Time |
| Rule Match origin | 83.46% | 78.08% | 11.15% | 1s |
| Judge Model | 89.42% | 97.50% | 2.53% | 1,425s |
| Rule Match enhance | 88.27% | 92.69% | 8.02% | 1s |
| Model | Top-1 ASR | Top-5 ASR |
| GPT-4 | 55% | 80% |
| Gemini-2.5-Flash | 69% | 89% |
| Qwen-Plus | 40% | 100% |
| DeepSeek-Chat | 51% | 81% |
| DeepSeek-Reasoner | 100% | 100% |
Adversarial Attacks on LLMs
Adversarial attacks on large language models probe how crafted inputs, internal changes, and agent interactions bypass safety or disrupt reliable behavior.
See all 355 papers