Defense against Prompt Injection Attacks via Mixture of Encodings

Ruiyi Zhang, David Sullivan, Kyle Jackson, Pengtao Xie, Mei Chen
4/10/2025
cs.CL

No official code found. Best implementation: ruz048/MoEMEnT (4 stars, last commit 2025-04-10).

Abstract

Large Language Models (LLMs) have emerged as a dominant approach for a wide range of NLP tasks, with their access to external information further enhancing their capabilities. However, this introduces new vulnerabilities, known as prompt injection attacks, where external content embeds malicious instructions that manipulate the LLM's output. Recently, the Base64 defense has been recognized as one of the most effective methods for reducing success rate of prompt injection attacks. Despite its efficacy, this method can degrade LLM performance on certain NLP tasks. To address this challenge, we propose a novel defense mechanism: mixture of encodings, which utilizes multiple character encodings, including Base64. Extensive experimental results show that our method achieves one of the lowest attack success rates under prompt injection attacks, while maintaining high performance across all NLP tasks, outperforming existing character encoding-based defense methods. This underscores the effectiveness of our mixture of encodings strategy for both safety and task performance metrics.

View on arXivView PDF

Code Implementations(1)

ruz048/MoEMEnTCommunity100%
41PythonApr 10, 20251 years ago

Cite this paper

@article{zhang2025defense,
  title  = {Defense against Prompt Injection Attacks via Mixture of Encodings},
  author = {Ruiyi Zhang and David Sullivan and Kyle Jackson and Pengtao Xie and Mei Chen},
  year   = {2025},
  eprint = {2504.07467},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2504.07467v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2504.07467.svg)](https://codeofpaper.com/paper/2504.07467)

Discussion