Build a tool-call safety guardrail from a model's activations

A live monitor that flags an unsafe tool call before it runs, powered by a linear probe that reads the model's own activations rather than its words

TopicsLanguage models · Linear probes · Safety & guardrails
ModelsQwen3-8B (subject) · Qwen3-4B · lexical baseline
ReferencesShoppingBench (arXiv 2508.04266)
Try it yourself. Open the finished run in your own workspace and pick up where it leaves off.

A single tool call can spend real money, leak a saved card number, or pay out an attacker's refund. A tool call is the small structured command an agent emits to act in the world, and software executes it with no chance to take it back. The dangerous ones rarely look dangerous. A budget-blowing add_to_cart or an injected refund emits almost the same command as the safe version, so a keyword scanner cannot tell them apart.

This recipe builds a guardrail for that moment: a monitor that scores each tool call the instant the model commits to it and raises an alarm before the action is handed off. The move it makes is to read the model's internal state instead of its text. A linear probe over the model's activations on the tool-call span catches what the surface command hides.

The guardrail is built on Qwen3-8B acting as a shopping assistant. The probe is the cheap part: a single linear rule over the residual-stream activations at one layer, trained on labeled safe and unsafe calls, that outputs one number between 0 and 1. It adds almost nothing to the cost of running the model, and it is what the live monitor loads and fires on.

On a held-out set of shopping tool calls the probe never saw in training, the guardrail separates safe from unsafe at 0.92 AUROC on Qwen3-8B, up from the 0.5 of a coin flip, and a smaller Qwen3-4B carries a weaker but real signal at 0.85. Wired into a live monitor that scores each call at completion, it runs at about 0.95 on matched agentic traffic.

Key takeaways

Linear probes for safety in a nutshell

When a language model produces a tool call, the call is the visible tip of a great deal of hidden computation. Every token the model processes leaves a trail of internal activations, vectors that encode what the model has taken in: what the user asked for, what the rules were, what the call is about to do. A linear probe is the simplest possible reader of that trail. It is a single linear rule, fit on labeled examples, that maps the activations over a chosen span to one score. Training it is cheap and running it alongside the model is nearly free, which is what makes it practical as an always-on guardrail rather than a second model in the loop.

The guardrail here is packaged as a probe pack: the trained probe weights plus a small metadata file naming the model, the layer, the hook site, the pooling, and the span the probe reads. A live monitor loads the pack, taps the model's residual stream at that layer while it generates, and scores the tool-call span at completion. Building the guardrail is therefore four concrete pieces fitting together.

Building a guardrail that holds up

The goal is a guardrail worth deploying: one that catches unsafe calls the surface text would hide, survives a move to a domain it was not tuned on, and runs as a live monitor without crying wolf. The thread behind this recipe pushed on each of those in turn, and the honest result is that the probe is the strong part while the firing threshold is the part that needs care.

The out-of-domain threshold behavior is the part worth feeling rather than reading. The explorer below recomputes recall and false alarms over the evaluation set as the threshold moves, with a toggle between the home and new domains.

Interpretability as a runtime guardrail

The tool-call guardrail is one instance of a more general pattern: read a model's activations while it runs and gate on what they carry. Nothing about the method is specific to unsafe shopping calls. The same residual-stream tap could feed a panel of linear probes trained on different failure modes, deception, data-exfiltration intent, or jailbreak compliance, so a single cheap read covers several risks at once rather than one. Because the signal lives in the model's internal state rather than its output text, this kind of monitor watches behaviors that never surface cleanly in what the model says, which is exactly where output-level filters are weakest.

The harder and more interesting direction is moving from watching to acting. The probe defines a direction in activation space that separates safe from unsafe, and that direction can in principle be used to intervene during generation, suppressing the unsafe action instead of alarming after the model has committed to it. That turns a read-only guardrail into active control, and it raises the question that decides whether any of this holds up under pressure: whether reading internal state is genuinely harder to fool than reading the output, or whether an adversary who knows a probe is watching can optimize the signal away. Settling that is the difference between a useful monitor and a real safety layer.