Are My Optimized Prompts Compromised? Exploring Vulnerabilities of LLM-based Optimizers

Andrew Zhao, Reshmi Ghosh, Vitor Carvalho, Emily Lawton, Keegan Hines, Gao Huang, Jack W. Stokes

TL;DR

This paper identifies a critical new security risk: LLM-based prompt optimizers (like TextGrad or DSPy) are highly vulnerable to "poisoning" attacks. By injecting harmful queries or faking feedback signals, an attacker can trick an optimizer into generating system prompts that bypass safety guards, increasing the Attack Success Rate (ASR) by up to 48%.

What Problem Does This Paper Address?

As LLM applications become more complex, developers have moved away from manual prompt engineering toward automated prompt optimization. Tools like TextGrad use an LLM to "backpropagate" textual feedback and iteratively refine a system prompt to maximize a specific metric (e.g., helpfulness).

While we know a lot about how to "jailbreak" a model at inference time, we know very little about the security of the optimization pipeline itself. If an attacker can influence the data or the feedback scores used during this tuning phase, they can "poison" the resulting system prompt. This creates a "silent" vulnerability where the model's core instructions are subverted before it even reaches the end user.

Methods

The authors formalize a threat model where an adversary can manipulate two channels:

  1. The Query Channel: Injecting harmful prompts into the training batch.
  2. The Feedback Channel: Manipulating the scalar rewards or natural language critiques sent to the optimizer.

They introduce a particularly clever and low-effort attack called the Fake Reward Attack. Instead of hacking the reward model's API, the attacker simply appends fake feedback tokens (e.g., <FEEDBACK>10</FEEDBACK>) directly to the harmful queries. Because the LLM-as-optimizer processes the entire batch of data, it can be tricked into thinking a harmful response was actually highly rated by the system.

To counter this, they propose Defense via Highlighting. This is a lightweight structural defense where the system wraps user queries in explicit tags (like <query>...</query>). This helps the optimizer distinguish between the actual user input and the legitimate feedback channel, preventing "fake rewards" from leaking into the optimization logic.

Datasets

  • HarmBench: The primary dataset used to source harmful queries and evaluate the Attack Success Rate (ASR).
  • WildGuardMix: A dataset of mostly benign queries used to test a more realistic "10% poison" scenario, where only a small fraction of the training data is malicious.

Key Insights and Ideas

  • Feedback is the Primary Vector: Systems are significantly more vulnerable to manipulated feedback than to just seeing harmful queries. If the optimizer is told that a harmful response is "good," it will aggressively rewrite the system prompt to encourage that behavior.
  • The "Safety Entanglement" Shield: Interestingly, if an optimizer is told to maximize "helpfulness" using a reward model that implicitly equates helpfulness with safety, it is harder to poison. However, if the metric is "pure" (like "correctness"), the optimizer is much easier to steer toward harmful outcomes.
  • Optimization as a Catalyst: The "Fake Reward" attack acts as a catalyst. In settings that are already slightly vulnerable, this attack compounds the risk, often resulting in a higher ASR than even direct feedback manipulation.
  • Structural vs. Semantic Defense: You don't necessarily need a more powerful "Safety LLM" to stop these attacks. Simple structural delimiters (the Highlighting defense) proved remarkably effective at isolating the attack surface.

Key Results

  • Direct Feedback Manipulation: When an attacker controlled the reward signal, they raised the $\Delta ASR$ (the increase in attack success) by 0.48.
  • Fake Reward Attack Success: Even without access to the reward model, the "Fake Reward" attack increased $\Delta ASR$ from -0.02 (the vanilla baseline, which actually got safer) to 0.23.
  • Compounding Vulnerability: When the Fake Reward attack was used against a "vulnerable" metric (correctness), the $\Delta ASR$ jumped to 0.48, matching the most powerful attack.
  • Effectiveness of Highlighting: The proposed defense reduced the Fake Reward $\Delta ASR$ from 0.23 down to 0.07 without degrading the model's performance on its intended tasks.

Limitations and Future Work

The authors acknowledge several limitations:

  • Model Specificity: The experiments primarily used GPT-4 as the optimizer backend. While they showed the attack generalizes to other optimizers like Trace, more work is needed to see how smaller or open-source models behave.
  • Scope of Harm: The study focused on safety and harmfulness. Other dimensions of "poisoning," such as introducing political bias or spreading misinformation through optimized prompts, remain unexplored.
  • Future Directions: The authors suggest looking into multi-modal poisoning (e.g., using images to poison a prompt optimizer) and developing more robust, adversarial-resistant reward frameworks for self-improving agentic systems.

Summary updated

BibTeX
@inproceedings{zhao2026are,
  author = {Andrew Zhao and Reshmi Ghosh and Vitor Carvalho and Emily Lawton and Keegan Hines and Gao Huang and Jack W. Stokes},
  title = {{Are My Optimized Prompts Compromised? Exploring Vulnerabilities of LLM-based Optimizers}},
  booktitle = {EACL (Volume 1: Long Papers)},
  year = {2026},
  doi = {10.18653/v1/2026.eacl-long.100},
}
Figure