SoK: a Comprehensive Causality Analysis Framework for Large Language Model Security

Wei Zhao, Zhe Li, Jun SunarXiv 2025 · DOI

Abstract

Large Language Models (LLMs) are susceptible to jailbreak attacks that bypass safety filters. This paper introduces a unified causality analysis framework based on Pearl’s structural causal models to investigate the mechanistic reasons behind these failures. By performing interventions at the token, neuron, layer, and representation levels, we demonstrate that safety mechanisms are highly localized—concentrated in approximately 1–2% of neurons within early-to-middle layers. Furthermore, features derived from these causal signals enable the detection of malicious prompts, hallucinations, and backdoors with over 95% accuracy.

Introduction

Despite the rapid advancement of LLMs, "jailbreaking"—the use of adversarial prompts to elicit harmful content—remains a persistent threat. Most existing research focuses on cataloging these attacks rather than explaining their internal mechanics. This work addresses this gap by proposing a systematic framework to study causality within LLMs, moving beyond black-box observations to understand how specific internal components cause a model to either refuse or comply with harmful requests.

Methodology: Hierarchical Causal Interventions

The framework utilizes a "do-operator" to perform interventions across four hierarchical levels to trace the causal chain of model behavior:

  1. Token-level: Systematically replacing input tokens with padding to identify specific words that trigger a jailbreak.
  2. Neuron-level: Identifying "safety neurons" through statistical analysis and deactivating them to observe behavioral shifts.
  3. Layer-level: Ablating entire transformer layers to trace where safety decisions are finalized.
  4. Representation-level: Analyzing hidden state embeddings to identify an "acceptance direction" that governs compliance.
Token-level intervention: replacing a causal token (e.g., 'unicode') with padding can flip the model's output from compliance to refusal, revealing the token's causal influence.

Key Insights: The Localization of Safety

A primary discovery of this causality analysis is that safety mechanisms are not distributed uniformly throughout the model. Instead, they are highly localized in the early-to-middle layers (typically layers 2–12). Furthermore, only a small fraction (1–2%) of neurons are causally responsible for maintaining safety boundaries. Jailbreaks effectively work by geometrically shifting the model's internal representation of a prompt toward a specific "acceptance" region in the embedding space.

Neuron-level intervention: identifying and deactivating specific "safety neurons" in the middle layers reveals their causal role in model behavior.

Results: Detection and Efficiency

The framework's causal features were used to train simple MLP classifiers for misbehavior detection. These classifiers achieved over 95% F1 scores across various tasks, including jailbreak and backdoor detection. Notably, representation and neuron-level detection are computationally efficient, requiring less than 0.15 seconds per input, making them suitable for real-time deployment in production environments.

Conclusion

This causality-guided approach provides a deeper understanding of LLM vulnerabilities and offers a path toward more robust, interpretable defenses. Future work will focus on automated mitigation strategies that use these causal insights to "edit" models and permanently fix vulnerabilities without the need for expensive retraining or external guardrails.

Summary updated

BibTeX
@misc{zhao2025sok,
  author = {Wei Zhao and Zhe Li and Jun Sun},
  title = {{SoK: a Comprehensive Causality Analysis Framework for Large Language Model Security}},
  year = {2025},
  eprint = {2512.04841},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2512.04841},
}
Figure