LLM Self Defense: By Self Examination, LLMs Know They Are Being Tricked

Mansi Phute, Alec Helbling, Matthew Hull, ShengYun Peng, Sebastian Szyller +2 more
8/14/2023
356 citations
cs.CLcs.AI

Official code: poloclub/llm-self-defense (53 stars, Python, BSD-3-Clause, last commit 2024-05-21).

Abstract

Large language models (LLMs) are popular for high-quality text generation but can produce harmful content, even when aligned with human values through reinforcement learning. Adversarial prompts can bypass their safety measures.

Show full abstract

We propose LLM Self Defense, a simple approach to defend against these attacks by having an LLM screen the induced responses. Our method does not require any fine-tuning, input preprocessing, or iterative output generation. Instead, we incorporate the generated content into a pre-defined prompt and employ another instance of an LLM to analyze the text and predict whether it is harmful. We test LLM Self Defense on GPT 3.5 and Llama 2, two of the current most prominent LLMs against various types of attacks, such as forcefully inducing affirmative responses to prompts and prompt engineering attacks. Notably, LLM Self Defense succeeds in reducing the attack success rate to virtually 0 using both GPT 3.5 and Llama 2. The code is publicly available at https://github.com/poloclub/llm-self-defense

View on arXivView PDF

Code Implementations(1)

BSD-3-Clause

LLM Self Defense: By Self Examination, LLMs know they are being tricked

537PythonMar 8, 20242 years agoBSD-3-Clause

Similar Papers

Cite this paper

@article{phute2023self,
  title  = {LLM Self Defense: By Self Examination, LLMs Know They Are Being Tricked},
  author = {Mansi Phute and Alec Helbling and Matthew Hull and ShengYun Peng and Sebastian Szyller and Cory Cornelius and Duen Horng Chau},
  year   = {2023},
  eprint = {2308.07308},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2308.07308v4}
}

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/2308.07308.svg)](https://codeofpaper.com/paper/2308.07308)

Discussion