Jailbreaking ChatGPT via Prompt Engineering: An Empirical Study

Yi Liu, Gelei Deng, Zhengzi Xu, Yuekang Li, Yaowen Zheng, Ying Zhang, Lida Zhao, Tianwei Zhang, Yang Liu

Abstract

This study presents the first comprehensive empirical analysis of "jailbreaking" ChatGPT—the use of prompt engineering to bypass safety filters. By analyzing 78 real-world exploits, the authors categorize jailbreak strategies into a formal taxonomy and demonstrate that while GPT-4 is more resilient than its predecessors, it remains significantly vulnerable to sophisticated linguistic manipulation.

Introduction

Large Language Models (LLMs) like ChatGPT are equipped with safety guardrails designed to prevent the generation of harmful, illegal, or biased content. However, a community of "jailbreakers" has emerged, crafting complex prompts to circumvent these restrictions. Until this study, most knowledge about jailbreaking was anecdotal or limited to specific examples like the "DAN" (Do Anything Now) prompt. The authors address this gap by providing a systematic, large-scale evaluation of how these prompts work, why they succeed, and how the resilience of models has evolved from GPT-3.5 to GPT-4.

An example of a 'Jailbreak Mode' prompt using a role-play scenario (Dr. AI) to solicit instructions on creating malware.

Methodology and Taxonomy

The researchers employed a multi-step empirical approach to understand the landscape of jailbreaking. They collected 78 verified jailbreak prompts from community platforms like jailbreakchat.com and used an iterative "open coding" process to classify them. This resulted in a taxonomy of 10 distinct patterns grouped into three broad categories:

  1. Pretending: Forcing the model into a persona or role-play (e.g., a "character" who doesn't have rules).
  2. Attention Shifting: Diverting the model’s focus toward a different task, like translation or code completion, to hide the malicious intent.
  3. Privilege Escalation: Commanding the model to enter a "developer" or "sudo" mode to override its base programming.
The proposed taxonomy of jailbreak strategies, showing the prevalence and success rates of different patterns.

To evaluate these strategies, the authors created a test suite of 40 questions across eight prohibited categories (e.g., illegal activities, hate speech, privacy violations) based on OpenAI’s usage policies. They then conducted 31,200 queries across both GPT-3.5-Turbo and GPT-4 to measure success rates and consistency.

Key Insights and Analysis

  • The Power of Persona: "Pretending" is the most prevalent strategy, used in over 97% of collected prompts. It is highly effective because it changes the conversational context without necessarily alerting simple keyword filters.
  • Complexity as a Double-Edged Sword: While complex prompts (like those involving program execution) can be potent, they also risk confusing the model. If a prompt is too convoluted, the LLM might focus on explaining the prompt's logic rather than answering the prohibited question.
  • Semantic Defense in GPT-4: The study suggests that GPT-4’s improved resistance isn't just due to better "banned word" lists, but a superior semantic understanding. GPT-4 is better at "seeing through" a role-play to identify the underlying harmful request.
  • The "Sudo" Fallacy: Prompts that attempt to use computer science metaphors (like "entering developer mode") are surprisingly effective, likely because the models are trained on vast amounts of technical documentation where "sudo" implies the removal of restrictions.

Results

The empirical results highlight a significant vulnerability in current LLMs. Jailbreak prompts achieved an average success rate of 74.6% on GPT-4, a massive jump from the 29% success rate of "vanilla" prohibited questions without jailbreak wrappers.

However, model evolution is evident. GPT-4 is significantly more robust than GPT-3.5-Turbo. Specifically, in the "Harmful Content" category, GPT-4's success rate for jailbreaks dropped by 38.4% compared to its predecessor. Across both models, "Illegal Activities" and "Fraudulent Activities" were identified as the easiest categories to break.

Conclusion and Future Work

The authors conclude that jailbreak prompts should be treated like malware. Future research could involve building automated "antivirus" systems for LLMs that use the patterns identified in this study to detect and block malicious prompts before they reach the model. They also suggest that open-source models (like LLaMA) need urgent attention, as pilot tests showed these models often have almost no defense against these scenarios.

Summary updated

Abstract

Large Language Models (LLMs), like ChatGPT, have demonstrated vast potential but also introduce challenges related to content constraints and potential misuse. Our study investigates three key research questions: (1) the number of different prompt types that can jailbreak LLMs, (2) the effectiveness of jailbreak prompts in circumventing LLM constraints, and (3) the resilience of ChatGPT against these jailbreak prompts. Initially, we develop a classification model to analyze the distribution of existing prompts, identifying ten distinct patterns and three categories of jailbreak prompts. Subsequently, we assess the jailbreak capability of prompts with ChatGPT versions 3.5 and 4.0, utilizing a dataset of 3,120 jailbreak questions across eight prohibited scenarios. Finally, we evaluate the resistance of ChatGPT against jailbreak prompts, finding that the prompts can consistently evade the restrictions in 40 use-case scenarios. The study underscores the importance of prompt structures in jailbreaking LLMs and discusses the challenges of robust jailbreak prompt generation and prevention.
BibTeX
@misc{liu2023jailbreaking,
  author = {Yi Liu and Gelei Deng and Zhengzi Xu and Yuekang Li and Yaowen Zheng and Ying Zhang and Lida Zhao and Tianwei Zhang and Yang Liu},
  title = {{Jailbreaking ChatGPT via Prompt Engineering: An Empirical Study}},
  year = {2023},
  eprint = {2305.13860},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.13860},
}
Figure