Data Poisoning for In-context Learning

Pengfei He, Han Xu, Yue Xing, Hui Liu, Makoto Yamada, Jiliang Tang

Introduction

In-context learning (ICL) has emerged as a transformative capability of Large Language Models (LLMs), allowing them to adapt to novel tasks through a few demonstrations provided within the prompt. Unlike traditional fine-tuning, ICL requires no parameter updates, occurring entirely during the inference phase. However, this flexibility introduces a new attack vector. Researchers have introduced ICLPoison, a framework demonstrating that malicious actors can significantly degrade model performance by subtly perturbing the examples in a prompt, even on state-of-the-art models like GPT-4.

Methodology: The ICLPoison Framework

The core vulnerability exploited by ICLPoison lies in the internal mechanics of ICL. Recent studies suggest that LLMs process in-context examples by generating "task vectors" within their hidden layers. ICLPoison targets these internal representations by identifying discrete text perturbations that maximize the distortion of these hidden states.

The framework utilizes three primary perturbation strategies:

  1. Synonym Replacement: Swapping words for synonyms to alter semantics subtly.
  2. Character Replacement: Introducing precise typos that disrupt tokenization while remaining largely imperceptible to human readers.
  3. Adversarial Suffix: Appending short, optimized token strings to the end of demonstration examples.

Because high-performance models like GPT-4 are proprietary "black boxes," the researchers employed a surrogate model approach. Attacks were optimized using the hidden states of an open-source model (e.g., Llama2-7B) and then tested for transferability to the target models.

Experimental Results

The effectiveness of ICLPoison was evaluated across five classification tasks, including sentiment analysis (SST2, Poem), linguistic acceptability (Cola), emotion detection (Emo), and topic classification (AG’s News).

Cross-Model Impact and Transferability

The attacks proved highly effective across a wide range of architectures. As shown in Figure 1, ICL accuracy dropped precipitously for both open-source and closed-source models when subjected to poisoned prompts. Notably, attacks crafted on a Llama2 surrogate successfully degraded GPT-4's performance, indicating a high degree of transferability.

Figure 1: ICL Accuracy across various models under different poisoning attacks.

Sensitivity to Poisoning Rate

A critical finding is that the model does not require a fully poisoned prompt to fail. The attack remains potent even when only a small fraction of the available examples are manipulated. Figure 2 illustrates the relationship between the poisoning rate and accuracy, showing significant degradation even at a 10-20% poisoning level.

Figure 2: Impact of varying poisoning rates on ICL accuracy.

Key Insights

  • Feature-Level Fragility: Sabotaging the features of the input text is more effective than simply flipping labels. By confusing the model's internal logic, attackers can bypass simple label-consistency checks.
  • Stealth vs. Disruption: Synonym replacement offers the highest stealth, often bypassing automated grammar filters, whereas adversarial suffixes provide the most significant disruption at the cost of higher detectability.
  • Defense Challenges: Preliminary defense attempts, such as using LLMs to paraphrase prompts, only partially mitigated the performance loss. This suggests that the internal state distortions caused by ICLPoison are robust.

Conclusion and Future Work

ICLPoison highlights a significant security gap in the deployment of LLMs for in-context tasks. The ability to sabotage "frontier" models using surrogate-based attacks poses a real threat to applications relying on untrusted data sources for prompting. Future research must focus on developing robust ICL mechanisms and more effective filtering techniques to detect these subtle internal distortions before they compromise model output.

Summary updated

BibTeX
@inproceedings{he2025data,
  author = {Pengfei He and Han Xu and Yue Xing and Hui Liu and Makoto Yamada and Jiliang Tang},
  title = {{Data Poisoning for In-context Learning}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.findings-naacl.91},
}
Figure