Inverting Trojans in LLMs

Zhengxing Li, Guangmingmei Yang, Jayaram Raghuram, David J. Miller, George KesidisarXiv 2025 · OpenReview

Abstract

While effective backdoor detection and inversion schemes have been developed for AIs used e.g. for images, there are challenges in "porting" these methods to LLMs. First, the LLM input space is discrete, which precludes gradient-based search over this space, central to many backdoor inversion methods. Second, there are ~30,000^k k-tuples to consider, k the token-length of a putative trigger. Third, for LLMs there is the need to blacklist tokens that have strong marginal associations with the putative target response (class) of an attack, as such tokens give false detection signals. However, good blacklists may not exist for some domains. We propose a LLM trigger inversion approach with three key components: i) discrete search, with putative triggers greedily accreted, starting from a select list of singletons; ii) implicit blacklisting, achieved by evaluating the average cosine similarity, in activation space, between a candidate trigger and a small clean set of samples from the putative target class; iii) detection when a candidate trigger elicits high misclassifications, and with unusually high decision confidence. Unlike many recent works, we demonstrate that our approach reliably detects and successfully inverts ground-truth backdoor trigger phrases.

Introduction

Backdoor attacks, or "Trojans," represent a critical security vulnerability for Large Language Models (LLMs). In these scenarios, an adversary poisons the training data such that the model behaves normally on standard inputs but produces a specific, malicious output when a "trigger" phrase is present. While robust inversion tools exist for image-based models, the discrete nature of text and the combinatorial explosion of potential token sequences make LLM trigger recovery significantly more difficult. Furthermore, LLMs often exhibit natural biases where certain tokens are strongly correlated with specific classes (e.g., "excellent" for positive sentiment), leading to false positives in naive detection schemes.

The BABI Framework

To address these challenges, we introduce BABI (Backdoor Attack Binary Inversion), a post-training defense that operates without access to the original poisoned training set. BABI relies on three core innovations:

  1. Greedy Discrete Search (Accretion): Rather than an exhaustive search, the algorithm starts with single tokens and iteratively builds longer phrases by keeping the top $N$ candidates that most effectively cause misclassification.
  2. Implicit Blacklisting: To avoid flagging naturally biased words, BABI uses a penalty term based on internal model activations. It measures the cosine similarity in activation space between a candidate trigger and a small set of clean samples from the target class. If a word's activation pattern naturally mirrors the target class, it is penalized.
  3. Penalized Score Function: Candidates are ranked using a penalized margin loss: $L_t(z) = M_t(z) + \lambda K_t(z)$, where $M_t$ measures misclassification effectiveness and $K_t$ is the activation-based penalty.

Experimental Results

Detection Performance

The BABI method demonstrates exceptional capability in distinguishing between clean and poisoned models. By analyzing two key statistics—average margin and misclassification proportion—we can visualize the separation in a detection plot. As shown in the results, poisoned models are perfectly separable from clean models, occupying a distinct "true cases" region in the feature space.

Detection plot showing clear separation between poisoned (true cases) and clean (positive/negative) models.

Trigger Inversion

The framework successfully recovers ground-truth triggers even when they are neutral phrases like "Tell me seriously." In our experiments with FLAN-T5 Small models poisoned using various attack types (dirty-label and clean-label), the BABI method consistently ranked the ground-truth trigger or its constituent fragments at the top of the candidate list.

Table showing the top-ranked 2-tuple trigger candidates recovered by BABI across different poisoned models.

Discussion and Limitations

Our findings suggest that internal activation spaces (specifically mid-encoder layers) provide a clearer signal for detecting malicious triggers than final output layers alone. While BABI is robust to hyperparameter choices like the penalty weight $\lambda$, current limitations include its focus on classification tasks and smaller model scales. Future work will investigate the computational feasibility of this approach on massive generative models and its effectiveness against unrestricted generative attacks.

Summary updated

BibTeX
@misc{li2025inverting,
  author = {Zhengxing Li and Guangmingmei Yang and Jayaram Raghuram and David J. Miller and George Kesidis},
  title = {{Inverting Trojans in LLMs}},
  year = {2025},
  eprint = {2509.16203},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.16203},
}
Figure