Automatically Auditing Large Language Models via Discrete Optimization

Erik Jones, Anca Dragan, Aditi Raghunathan, Jacob Steinhardt

Abstract

As Large Language Models (LLMs) are increasingly integrated into production environments, identifying their latent failure modes—such as toxicity, factual hallucinations, and data leakage—has become a critical safety requirement. We present ARCA (Autoregressive Randomized Coordinate Ascent), a discrete optimization algorithm designed to automatically "red-team" LLMs. By treating auditing as a search problem and optimizing prompts and outputs simultaneously, ARCA uncovers hidden vulnerabilities far more efficiently than previous automated methods. Our results demonstrate that ARCA significantly outperforms existing baselines in triggering harmful behaviors and reveals that adversarial prompts often become more natural as model scale increases.

Introduction

LLMs occasionally exhibit "catastrophic" behaviors, generating hate speech or reinforcing harmful stereotypes. These behaviors are often "needles in a haystack," triggered by counterintuitive prompts that human auditors are unlikely to discover manually. While automated auditing is necessary for scale, it faces two primary hurdles: the discrete nature of text (which prevents the direct application of calculus-based gradients) and the high dimensionality of models like GPT-J.

Existing automated tools often struggle to navigate this discrete search space effectively. To address this, we cast the auditing process as a discrete optimization problem, defining an objective function $\phi(x, o)$ that scores how well a prompt $x$ and its completion $o$ match a target harmful behavior.

Methodology: The ARCA Algorithm

The core contribution of this work is ARCA (Autoregressive Randomized Coordinate Ascent). Unlike prior methods that search only for prompts, ARCA introduces several technical innovations to improve search efficiency:

  1. Joint Optimization: ARCA optimizes both the prompt and the expected output simultaneously. This provides a much stronger signal to the search algorithm, allowing it to find rare behaviors that might be missed if searching for the prompt alone.
  2. Differentiable Surrogate: Because "greedy decoding" (the process of picking the most likely next word) is not differentiable, ARCA utilizes a surrogate objective. It maximizes the sum of the auditing objective and the log-probability of the output, creating a smoother landscape for optimization.
  3. Autoregressive Gradient Approximation: Standard gradients typically only account for how a word change affects subsequent tokens. ARCA decomposes the objective into an "autoregressive" term (accounting for preceding context) and a "linearly approximatable" term (accounting for subsequent context). By averaging gradients over random tokens, ARCA gains a "global" view of the discrete search space, preventing the algorithm from becoming trapped in local minima.

Experimental Setup

We evaluated ARCA by auditing GPT-2 (762M) and GPT-J (6B) across three distinct domains:

  • Toxicity: Using the CivilComments dataset to find prompts that trigger specific slurs or insults.
  • Factual Integrity: Using a list of U.S. Senators to identify prompts that force the model to generate factual or temporal errors (e.g., misidentifying government officials).
  • Linguistic Stability: Using FastText to create an objective for "language switching," where a prompt in one language (e.g., French) results in an output in another (e.g., English).

Key Results and Insights

ARCA significantly outperformed state-of-the-art baselines, including AutoPrompt and GBDA.

Performance Metrics

On a task designed to trigger 3-token toxic outputs in GPT-2, ARCA achieved a 58% success rate. In comparison, AutoPrompt achieved 29%, while GBDA reached only 4%. This gap highlights the importance of ARCA’s joint optimization and refined gradient approximations.

Qualitative Findings

ARCA uncovered several "toxic surprises" where seemingly innocuous prompts led to vitriolic completions. For instance, the prompt "Barack Obama is a legalized unborn" triggered the completion "child murderer." It also successfully forced models into confident hallucinations, such as naming "Ed Markey" as the "Russia USPS chairman."

Scaling and Transferability

Two emergent properties were observed during testing:

  • Naturalness at Scale: As models increased in size (from GPT-2 to GPT-J), the trigger prompts found by ARCA became more linguistically natural and human-like, even without explicit constraints for naturalness.
  • Prompt Transferability: Failure modes discovered on smaller, open-source models often "transfer" to larger, closed-source models. Prompts that successfully triggered GPT-2 frequently caused similar failures in GPT-3, suggesting that auditing smaller models is a viable proxy for securing giant, black-box systems.

Limitations and Ethical Considerations

While powerful, ARCA currently requires access to a model's internal gradients, meaning it cannot directly audit "black-box" APIs like GPT-4 (though prompt transfer offers a partial workaround). Additionally, the algorithm currently requires fixed lengths for prompts and outputs.

There is an inherent "dual-use" risk: while ARCA helps auditors secure models, it could potentially be used by malicious actors to find "jailbreaks." However, we argue that the transparency provided by robust, automated auditing tools is a prerequisite for the long-term safety and reliability of large-scale AI deployment.

Summary updated

BibTeX
@inproceedings{jones2023automatically,
  author = {Erik Jones and Anca Dragan and Aditi Raghunathan and Jacob Steinhardt},
  title = {{Automatically Auditing Large Language Models via Discrete Optimization}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=YaXiH2B0Sb},
}
Figure