To Protect the LLM Agent Against the Prompt Injection Attack with Polymorphic Prompt

Zhilong Wang, Neha Nagaraja, Lan Zhang, Hayretdin Bahsi, Pawan Patil, Peng Liu · DOI

Abstract

Prompt injection remains a critical vulnerability for Large Language Model (LLM) agents, where malicious inputs override system instructions. This paper presents Polymorphic Prompt Assembling (PPA), a novel "moving target defense" that mitigates these attacks by dynamically randomizing delimiters and prompt structures for every request. By breaking the predictability of prompt templates, PPA achieves a Defense Success Rate (DSR) exceeding 98% on top-tier models like GPT-4, with near-zero performance overhead (0.06ms). Our results show that PPA outperforms leading commercial solutions on standard benchmarks without requiring GPU resources or model retraining.

Introduction

As LLM agents are integrated into complex workflows, they become targets for prompt injection attacks. Attackers exploit the predictable nature of prompt templates—such as placing user input within fixed delimiters like {}—to craft "jailbreak" payloads. By including a closing delimiter in their input, attackers can "escape" the data zone and issue unauthorized commands. Existing defenses, including input filtering and model fine-tuning, are often computationally expensive or easily bypassed by adaptive adversaries.

Methodology: Polymorphic Prompt Assembling (PPA)

PPA addresses the root cause of prompt injection: structural predictability. Instead of a static template, PPA treats the prompt structure as a moving target.

The Polymorphic Prompt Assembling (PPA) architecture uses randomized separators and instruction enforcement to isolate user input.

The PPA workflow consists of four key components:

  1. Randomized Separators: For each request, the system selects a unique pair of separators (e.g., ####begin#### and ####end####) from a large, pre-defined list.
  2. Genetic Algorithm Refinement: Separators are evolved using a genetic algorithm to ensure they are distinct from natural language and hard for LLMs to confuse with commands. Research indicates that long ASCII-based patterns (10+ characters) are most effective.
  3. Instruction Enforcement: The system prompt is dynamically updated to specify the exact separators used for the current request, reinforcing the boundary between instructions and data.
  4. Lightweight Integration: PPA is implemented as a model-agnostic SDK, adding only 0.06ms of latency and requiring no GPU resources.

Experimental Evaluation

The authors evaluated PPA using 1,200 adversarial payloads across 12 categories, including role-playing and obfuscation. Testing was conducted on GPT-3.5-Turbo, GPT-4-Turbo, LLaMA-3.3-70B, and DeepSeek-V3 using the Pint-Benchmark and GenTel-Bench.

Key Results

PPA demonstrated exceptional defensive capabilities across all tested models. It achieved a DSR of 98.17% on GPT-3.5 and 98.08% on GPT-4. Notably, PPA ranked 1st on the GenTel-Bench and 2nd on the Pint-Benchmark.

Comparison of PPA against existing commercial and open-source prompt injection defenses on the Pint-Benchmark.

As shown in the comparison table, PPA achieves competitive accuracy (97.68%) while being the only high-performing method that does not require GPU resources or have a significant parameter footprint. This makes it highly accessible for developers operating at various scales.

Discussion and Conclusion

The success of PPA highlights that prompt injection is largely an architectural failure to isolate data from instructions. By introducing randomness, PPA disrupts the attacker's ability to predict the prompt structure. While some models like LLaMA-3 remain more susceptible to persuasive "role-playing" attacks, PPA significantly hardens the structural integrity of the agent. Future work will explore PPA's effectiveness in multi-agent environments and more complex tool-use scenarios.

Summary updated

BibTeX
@inproceedings{wang2025protect,
  author = {Zhilong Wang and Neha Nagaraja and Lan Zhang and Hayretdin Bahsi and Pawan Patil and Peng Liu},
  title = {{To Protect the LLM Agent Against the Prompt Injection Attack with Polymorphic Prompt}},
  booktitle = {DSN-S},
  year = {2025},
  doi = {10.1109/dsn-s65789.2025.00037},
}
Figure