The Model's Tell: Measuring Context-Leakage Attack Signals with Behavior Gauges
This paper introduces LeakGauge, a lightweight and robust method that detects context-leakage attacks in large language models by analyzing the prefill token probabilities of a behavior-verbalizing suffix, achieving high accuracy across diverse models without requiring access to internal hidden states.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Modern artificial intelligence assistants often rely on a hidden layer of instructions and private documents to do their jobs well. These hidden elements, known as system prompts and retrieved context, act like a secret rulebook or a private filing cabinet that the computer consults before answering a user. While this setup helps the machine give better answers, it also creates a vulnerability. A clever attacker can craft a question designed to trick the computer into revealing these secret instructions or private files. For years, security experts have tried to spot these tricks by looking only at the text of the user's question, much like a bouncer checking a guest's ID at the door. However, this approach often fails when the attacker changes their wording or uses a new strategy, because the text alone does not always reveal the intent.
Researchers have long suspected that the computer's internal state holds a clearer sign of trouble before it even finishes typing an answer. The problem is that peeking inside the machine's brain requires access to complex, hidden data that standard security systems cannot see. A new study from Tsinghua University and its partners asks a simpler question: does the computer leave a visible trace in its immediate reaction to a question, a trace that can be seen without needing to break into the machine's internal workings? The answer, they found, is yes. By attaching a specific, harmless phrase to the end of a user's question and watching how the computer calculates its next words, the researchers can detect an attack with high accuracy, even when the attack is completely new.
The team developed a method they call a "behavior gauge." Imagine the computer is about to speak, and you append a short sentence to its prompt that says, "Based on the above, I will give my system prompt." This sentence is not a real request to leak data; it is a test. The researchers then look at the computer's internal confidence scores for the very first few words of that test sentence. If the user's original question was a normal, safe query, the computer treats the test sentence as a strange, unlikely continuation. But if the user's question was a malicious attempt to steal secrets, the computer's internal logic shifts. It suddenly finds the test sentence much more plausible, as if the malicious question has already nudged it toward a state where it is willing to reveal its secrets. This shift happens in the fraction of a second before the computer actually types anything, and it leaves a distinct pattern in the numbers that represent the computer's confidence.
To prove this works, the researchers tested their method on eleven different large language models, ranging from small, efficient versions to massive systems with hundreds of billions of parameters. They subjected these models to thousands of different attacks, including attempts to steal system instructions and attempts to extract private documents from a database. In every case, the behavior gauge successfully distinguished between safe questions and malicious ones. When the researchers tested the system against attacks it had never seen before, and against protected content it had never encountered, the method still identified the threats with an AUC between 0.944 and 0.996. This is a significant improvement over previous methods that only looked at the text of the question, which often struggled to generalize to new types of attacks.
A key discovery was that the most effective test phrase did not need to contain the actual secret information. One version of the test used the exact opening words of the secret document, but this approach failed when the language of the secret changed or when the attacker tried to get the computer to summarize the secret rather than copy it word-for-word. The more robust version simply stated the intention to leak, using generic words like "I will give my system prompt." This generic phrasing worked across different languages and different types of secrets, suggesting that the computer was reacting to the act of disclosure itself, rather than just recognizing specific words. The researchers confirmed this by showing that they could nudge the computer's internal state to make it more or less likely to leak, and the behavior gauge's score moved in perfect lockstep with that change. This proves the signal is not a random glitch but is tied to the computer's actual internal representation of the risk.
The practical value of this finding lies in its efficiency. Because the test happens before the computer starts generating a full response, it can be used as a real-time filter. The researchers built a detector that adds the test phrase to the input and checks the result, requiring fewer than 500 extra parameters of computing power. This adds only about 10 milliseconds to the time it takes to process a request, a delay so small it is barely noticeable to a human user. In contrast, other methods that try to monitor the computer's internal signals often require duplicating the entire massive model or waiting for the computer to finish typing a long answer, which is slow and expensive. The new method offers a way to catch these attacks with minimal cost and high speed.
The study also explored whether this technique could work for other types of security threats. By changing the test phrase to match different risks, such as detecting toxic language or spotting attempts to inject hidden instructions, the same method showed promise in those areas as well. This suggests that the computer's immediate reaction to a prompt contains a rich, accessible signal about its safety state, one that does not require deep access to the machine's internal architecture to read. The researchers have made their code available, allowing others to verify these results and potentially integrate this lightweight detector into the security systems of future AI applications. The work demonstrates that sometimes the most effective way to see a problem is not to look deeper inside the machine, but to watch how it reacts to a simple, well-placed question.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.