
TL;DR
A dangerous action can be identified inside the model before it is written. While DeepSeek-V4.1-Flash generates, we record which experts it activates at each layer, and lightweight probes read out risk signals. Before an agent writes each tool call, the probe reads the expert activations once and separates dangerous from benign actions with an AUROC of 0.959, where random guessing gives 0.5. On replies the model writes itself, the probe does not need the whole reply either: among the harmful replies it detects, half raise their first alarm within the first 16 tokens, while the median length of a full reply is about 767 tokens.
The readout adds little cost: expert activations are a record the forward pass produces anyway, a few integer expert indices per layer that only need to be saved and take less than one hundredth of the storage of neuron activations (the activation vectors of hidden layers); the model stays frozen, needs no retraining, and no second model has to run. Because the readout runs alongside generation, monitoring can sit at the start of a reply and before every tool call, without waiting for the output to be complete. The probe can also read attributes of the action itself, for example whether a call will delete files; combined with permission rules, this blocks out-of-scope operations before they execute. These results come from a three-step experiment in which the readout point moves earlier with each step: after a text has been read, while a reply is being generated, and before a tool call is written (Section 3). Figure 1 gives an overview of the system: the signal passes through the Signal API to applications such as the stream guard and the action guard.
1. Introduction
Agents increasingly carry out actions without step-by-step confirmation from a user, so unsafe actions have to be blocked automatically before they execute. In the auto mode of Claude Code, for example, the agent calls tools on its own, each tool call is reviewed by a separate safety model before it executes, and actions that go beyond the user’s request are blocked1. Figure 2 illustrates this setting: in auto mode, a user asks Claude to delete last year’s invoices from their account. The first two actions pass the review and run automatically; the deletion written in the third round, however, targets every file in the account and is blocked by the reviewing model before it executes.
The scenario concerns a dangerous action: the deletion covers far more than the user asked for, and once executed it removes much more than the old invoices. A second kind of safety problem for agents is user privacy, for example copying the name, phone number and email address in a request verbatim into a log; it is the subject of another article in this series.
Today such problems are handed to a separate reviewing model2: after the model carrying out the task has written a tool call, the reviewing model reads the call and its context and then decides whether to allow or block it. The review can therefore begin only once the output is complete, and it requires an additional inference pass by another model. We want monitoring to run while the model streams its output, reading risk signals directly from inside the generating model as each token is produced.
Our approach is to read the model’s own expert activations. All experiments use DeepSeek-V4.1-Flash3, a mixture-of-experts (MoE) model: for every token it processes, only a few experts are activated at each layer. Which experts are activated is a record the model produces anyway while it runs; the deployer can save it token by token during generation and read it without modifying the model. We train lightweight probes on this record to test whether a risk signal can be read inside the model before a harmful reply is complete and before a dangerous tool call is written.
2. Method
The method has four steps (Figure 3): input text, read the expert activations of the frozen model, train a probe on labeled data, and read out risk signals on data not seen in training.
2.1 Object of observation: expert activations
An MoE layer contains many experts, each of which is a group of neurons, that is, a small feed-forward network. For every token, a gating network scores all experts, and only the few with the highest scores are activated and take part in the computation3. In the MoE literature this step is called routing. We do not use the values of the neurons inside the experts and record only which experts are activated: the indices of the experts activated for a token at all layers together form that token’s expert activation pattern (Figure 4).
Compared with neuron activations, expert activations are simpler to store and to read. Reading neuron activations means exporting the hidden state at every layer: for each token, a vector of thousands of floating-point numbers, multiplied by the number of layers, copied out of GPU memory as it is read. Expert activations are only the integer indices of the few experts activated at each layer, one or two bytes per index, so the record of a token takes less than one hundredth of the space. The gating network computes these indices during the forward pass anyway; they only need to be saved, can be written to a log token by token during generation, and remain available afterwards. The experiments below show that, although they record only which experts are activated, these indices reflect how the model interprets the current token.
2.2 Readout method: probes
To test whether the expert activation pattern carries a given piece of information, we train probes: small classifiers that take the expert activation pattern as input and output the property to be read. The probes in this article score a whole text, a whole reply or a single action. Because a text contains hundreds of tokens, their expert activation patterns are first pooled into one vector, either by averaging (mean pooling) or with weights learned by the network (attention pooling)4.
Probes are trained on labeled data and tested on data not seen in training (Figure 5). They are kept simple by design: a shallow network, with a linear classifier as a control. The simpler the probe, the stronger the evidence that the information it reads out is already present in the expert activations and was not learned by the probe itself. Table 1 summarizes the data, probes and evaluation.
Table 1Experimental setup
| Research question | Whether a signal is present in expert activations before a harmful reply or a dangerous action |
| Training data | External harmful and benign text5,6,7,8, the model’s own replies, simulated agent tasks |
| Probe | Shallow network, scoring a whole reply or a single action |
| Evaluation | External test sets and an unseen dataset; the model’s own replies and prefixes during generation; before tool calls |
2.3 Reading out the signal: readout positions and metrics
Step 4 of the method is the readout: the trained probe is applied to data not seen in training, gives a risk score and raises an alarm above the threshold (Figure 6, which takes a reply being generated as its example). The probe reads expert activations at three positions, one for each step of the experiment in Section 3. For external text, it reads the whole text. For a reply the model generates, it reads only the tokens of the reply, without the prompt; to see where risk first appears, it can also read only the opening of the reply, a prefix of 8, 16, 32, … 256 tokens. For an agent, it reads once before each tool call is written, over the most recent 512 tokens; this context contains the task description and the thinking just completed, and the call itself is not yet written.
Three metrics are used. AUROC measures how well the probe ranks samples: it is the probability that, for one harmful and one benign sample drawn at random, the probe gives the harmful one the higher score; 0.5 corresponds to random guessing and 1 to perfect ranking. A monitor in operation also needs an alarm threshold, so we report recall and the false-alarm rate as well: recall is the fraction of harmful samples that raise an alarm, and the false-alarm rate is the fraction of benign samples that do.
Recall values are comparable only at the same false-alarm rate. The threshold is therefore chosen on a separate calibration set such that 5.5% of benign replies raise an alarm, and recall is then reported on the test data (Figure 7).
3. Evidence: risk signals before dangerous behavior
In mechanisms such as auto mode, the review takes place after the tool call has been written. The evidence in this section addresses whether a risk signal appears earlier: whether, before the model finishes a reply or a tool call, its expert activations already contain a readable signal of risk.
The experiment proceeds in three steps that move progressively closer to how agents are actually used, and each step tests a doubt left open by the previous one: whether expert activations contain information relevant to content safety (Section 3.1); whether that information can be used to judge what the model itself writes, and how much of a reply has to be written before it can be read (Section 3.2); and whether a dangerous tool call can be identified before it is written (Section 3.3). All three steps read DeepSeek’s expert activations, and the readout point moves earlier with each: after a text has been read, while a reply is being generated, and before a tool call is written (Figure 8).
3.1 Step 1: reading external text
Expert activations record only which experts are activated at each layer, and such a record need not contain information relevant to content safety. The first step tests this: harmful and benign texts from external datasets are fed to DeepSeek, the expert activations produced while it reads them are recorded, and a probe is trained to separate the two classes. The training data come from the harmful and harmless samples of BeaverTails5 and the everyday instructions of Alpaca7 and Dolly8; AEGIS6 is not used in training and serves only for testing. In this step all texts are written by others, and DeepSeek only reads them without answering.
The probe is tested under three conditions of increasing difficulty (Figure 9). Harmful text and everyday instructions are the easiest to tell apart, and the probe reaches an AUROC of 0.996; the harmful and harmless samples of the BeaverTails test set come from the same dataset and are closer to each other, yet the probe still separates them with an AUROC of 0.939; on AEGIS, a dataset it never saw in training, it reaches 0.878. Random guessing gives 0.5, and the probe is far above it in all three conditions, so it does read out information relevant to content safety.
This information might come not from the expert activations but from what the probe itself learns; in that case a more complex probe should do markedly better. In fact the three probes perform alike: on the BeaverTails test set the simplest of them, a linear classifier, already reaches 0.932, and replacing it with a shallow network raises this only to 0.939 with mean pooling and 0.941 with attention pooling. The structure of the probe matters little, which indicates that the information relevant to content safety comes mainly from the expert activations themselves. This step, however, reads the expert activations produced while DeepSeek reads text written by others, whereas monitoring is concerned with what the model itself writes; the second step tests this.
3.2 Step 2: writing its own replies
The probe of the first step is trained on text written by others, so what it reads may be only whether the topic is dangerous, not what the model actually writes. The two differ: a dangerous prompt may receive a safe refusal, and under the same harmful prompt the probe should judge a harmful reply and a refusal differently. In the second step DeepSeek therefore receives harmful and benign prompts and generates its answers token by token; the expert activations are recorded during generation, and a probe judges whether each reply is harmful. We train the probe of this step on mixed data: the external text of the first step together with replies DeepSeek wrote itself.
Prefix readout during generation. During streaming, a monitor can use only the part of the output generated so far; if risk could be judged only once most of a reply had been written, monitoring would still have to wait until the reply was nearly complete. We therefore examine whether risk can be detected from the opening of a reply alone. The expert activations produced while each reply is generated are saved and truncated to the prefix lengths of Section 2.3; the probe scores each prefix, which shows where the risk signal first appears. The position at which the probe first raises an alarm is called the first alarm (Figure 10).
The alarm threshold can be set in two ways: separately for each prefix length, so that the false-alarm rate at every length stays within the budget, or as a single threshold shared by all lengths. Figure 11 shows the process token by token.
Reading only the first 16 tokens, the attention-pooling probe already catches more than half of the harmful replies (recall 0.52); by 256 tokens its recall is 0.77, on a par with the 0.763 it reaches when it reads the full reply (Figure 11). In terms of first-alarm positions, half of the harmful replies detected raise their first alarm within the first 16 tokens and three quarters within the first 32, whereas the median length of a full reply is about 767 tokens. The risk signal is present from the opening of the reply, and monitoring need not wait for the reply to be complete.
3.3 Step 3: calling tools as an agent
Besides writing replies, an agent calls tools, and a tool call takes effect as soon as it executes. The third step is therefore the closest to deployment and to the scenario in the introduction: running as an agent in thinking mode, DeepSeek calls tools to complete tasks and receives the results of their execution; the experiment runs in a simulated sandbox, with 2,144 tasks completed and 12,131 actions issued. Whether an action is dangerous depends on whether its actual effect exceeds what the task authorizes: deleting files is a normal operation when the task is to clear temporary files, and a dangerous action when the files lie outside the task.
Whether an action is dangerous might become apparent only once the call has been written, in which case review could still take place only afterwards. To test this, the probe reads once before the agent writes each tool call (the span is given in Section 2.3): the task description and the thinking just completed are in context, the call itself is not yet written, and the probe must decide at this point whether the action is dangerous (Figure 12).
The measured results are shown below the diagram in Figure 12. With the tool call not yet written, the probe separates dangerous from benign actions with an AUROC of 0.959; at the alarm threshold used, it catches dangerous actions at a recall of 0.775 and flags only 4.4% of benign ones. Dangerous actions can be read from the expert activations before they are issued.
A risk score says only that an action may be dangerous, not what the action does; and whether the same action oversteps depends on the scope the task authorizes. Figure 13 therefore splits the danger label of an action into two judgments: what the action does, and whether it stays within the scope the task authorizes. The first comes from the expert-activation readout. Take the attribute “deletes files”: the probe tells whether a call not yet written will delete files with an AUROC of 0.994, and on two task types it never saw in training, “disk space low” and “free up space”, it still reaches 0.979 and 0.984, which indicates that the readout describes the action itself rather than a particular kind of task. The second comes from permission rules: the scope a task grants is explicit configuration, for example permission to clear /tmp/cache only, and checking it requires no access to the model’s internals.
Combining the two has three effects. First, blocking happens before execution: when the readout reports “will delete”, the permission rules check whether the target is in scope, and an out-of-scope call is blocked before it is written, without waiting for the command to appear in the output and then be reviewed by a second model. Second, the judgment of the same action follows the authorized scope: deleting temporary files proceeds in a cleanup task while deleting project files is blocked, and the readout itself needs no retraining for each task; only the permission rules change with the task. Third, each block has a stated reason: it can be expressed as “this call will delete files, and the target is outside the authorized scope”, which is easier to audit afterwards than a single risk score.
4. Conclusion
This work reads risk signals that precede dangerous behavior from the expert activations of DeepSeek: half of the harmful replies detected raise an alarm within their first 16 tokens; the probe identifies a dangerous tool call before it is written, with an AUROC of 0.959; and the readout of action attributes combines with permission rules to block out-of-scope operations before they execute. Because the readout needs only the expert activations the model produces anyway, safety checks can run alongside generation, rather than after the output is complete and has been passed to another model for review.
Citation
@misc{deepseek_blackbox_risk2026,
title = {Before an Unsafe Action Runs, We Read and Stop It: Reading Risk Signals from Expert Activations Before the Tool Call Is Written},
note = {Open DeepSeek’s Black Box series},
author = {{SeedSky Team}},
year = {2026},
url = {https://seedsky.ai/papers/open-the-black-box/risk}
}References
- How we built Claude Code auto mode: a safer way to skip permissions. Anthropic, 2026.
- Granite Guardian: Comprehensive LLM Safeguarding. NAACL 2025 Industry Track.
- DeepSeek-V4.1-Flash: Pushing the Limits of KV Cache Compression. DeepSeek-AI, 2026.
- Detecting High-Stakes Interactions with Activation Probes. NeurIPS 2025.
- BeaverTails: Towards Improved Safety Alignment of LLM via a Human-Preference Dataset. NeurIPS 2023 Datasets and Benchmarks.
- AEGIS: Online Adaptive AI Content Safety Moderation with Ensemble of LLM Experts. NVIDIA, 2024.
- Stanford Alpaca: An Instruction-following LLaMA Model. Stanford CRFM, 2023.
- Free Dolly: Introducing the World’s First Truly Open Instruction-Tuned LLM. Databricks, 2023.