Attack Prompt Generation for Red Teaming and Defending Large Language Models

Boyi Deng, Wenjie Wang, Fuli Feng, Yang Deng, Qifan Wang +1 more
10/19/2023
cs.CLcs.CRcs.LG

Official code: Aatrox103/SAP (49 stars, Apache-2.0, last commit 2024-05-09).

Abstract

Large language models (LLMs) are susceptible to red teaming attacks, which can induce LLMs to generate harmful content. Previous research constructs attack prompts via manual or automatic methods, which have their own limitations on construction cost and quality. To address these issues, we propose an integrated approach that combines manual and automatic methods to economically generate high-quality attack prompts. Specifically, considering the impressive capabilities of newly emerged LLMs, we propose an attack framework to instruct LLMs to mimic human-generated prompts through in-context learning. Furthermore, we propose a defense framework that fine-tunes victim LLMs through iterative interactions with the attack framework to enhance their safety against red teaming attacks. Extensive experiments on different LLMs validate the effectiveness of our proposed attack and defense frameworks. Additionally, we release a series of attack prompts datasets named SAP with varying sizes, facilitating the safety evaluation and enhancement of more LLMs. Our code and dataset is available on https://github.com/Aatrox103/SAP .

View on arXivView PDF

Code Implementations(1)

Aatrox103/SAPOfficial100%
Apache-2.0
4911Shell, PythonOct 16, 20232 years agoApache-2.0

Similar Papers

Cite this paper

@article{deng2023attack,
  title  = {Attack Prompt Generation for Red Teaming and Defending Large Language Models},
  author = {Boyi Deng and Wenjie Wang and Fuli Feng and Yang Deng and Qifan Wang and Xiangnan He},
  year   = {2023},
  eprint = {2310.12505},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2310.12505v1}
}

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

Discussion