surmenage · · budding · ml · nlp · interpretability · safety

the cot signal: probing a reasoning model's thoughts for jailbreaks

This is a group project for the NLP4Society course at TU Delft. The proposal is titled “The CoT Signal: Comparative Efficacy of Input vs. Chain-of-Thought Classifiers in Jailbreak Detection”. My part was mostly the extraction pipeline on the university cluster, plus the data analysis that came out of it. I am writing this down while the downstream training is still unfinished, so the interesting result so far is a negative one about the data, not a headline AUROC.

The question

Anthropic’s constitutional classifiers paper (arXiv 2501.18837) guards a model with classifiers on its input and output. Our proposal asks about a third place to look. Reasoning models write a chain of thought before they answer, and in most deployments the user never sees it. If a prompt is disguised, so that the surface text looks harmless, the reasoning needed to answer it may still be about something the policy forbids. So: is the internal chain of thought more detectable than the adversarial input, and do activations at the end of the CoT make a better feature set for a linear probe than activations at the end of the input?

The proposal names its own failure mode: if the model self-censors in its CoT, the signal may be gone. And it expected the CoT to win mainly on “sneaky” jailbreaks where the input is linguistically masked.

Four detectors

We train four models and compare AUROC and F1.

ModelFeature source
LM classifier 1raw input text
LM classifier 2CoT text
Linear probe 1activations at the final input token
Linear probe 2activations at the final CoT token

Following the constitutional classifiers baseline, the LM classifiers are plain supervised sequence classifiers, with no next-token-prediction term in the loss, so that the only thing that differs between 1 and 2 is the data source. The probes take the residual stream from every layer concatenated, which is a large feature vector: 28 layers times 3584 dimensions. The proposal itself flags that as the memory cost.

The repo for the training side (CoT_guardrails) has these as four small scripts: a Hugging Face sequence-classification fine-tune with a separate learning rate for the encoder and the head, a single nn.Linear(d, 1) probe trained with BCE and Adam, and matching evaluation scripts that report AUROC, F1, precision and accuracy. It also has a 20-sample example set so the schema can be inspected without the cluster.

Data and the extraction pipeline

The model is DeepSeek-R1-Distill-Qwen-7B in bf16, which is its native precision and what an A100 handles directly. The prompts come from allenai/wildjailbreak: 10,000 vanilla_benign prompts and 10,000 adversarial_harmful prompts, sampled with seed 42, 20,000 in total, balanced 50/50. They are cut into eight chunks of 2,500 rows (three of harmful training data, three of benign training data, and one benign and one harmful validation chunk), which later merge into 15,000 train and 5,000 validation rows.

For each prompt a single call to generate with output_hidden_states=True yields both things we need:

  • the input activation is the hidden state at the last input token, read from the prefill pass;
  • the CoT activation is the hidden state from the decode step that emitted </think>. That state sits at the last content token of the CoT, one position before </think>.

Generation is greedy, so every run is reproducible, and it stops at </think> by passing it as an extra eos_token_id. We never need the final answer, which saves roughly half the generated tokens. Each chunk took about seven to eight hours on an A100 80GB with batch size 32, with a checkpoint every 100 samples so that a job that hits its walltime can be resubmitted and resumes. Output per chunk is row-aligned: a parquet with prompt, label, CoT text, CoT length and an ended_on_think flag, two (N, 28, 3584) bf16 tensors, labels, and a boolean extraction mask.

Truncation

This is where the pipeline needed more than a loop. With max_new_tokens=4096, 658 samples (3.8%) never produced </think>. Their activations are not “the end of the thought”, so the mask marks them invalid. I bundled the 658 into a rerun with max_new_tokens=8192 and a 6 hour walltime, and wrote a patch step that merges results back by source chunk and row, replacing activations only where the rerun actually ended on </think>.

Some samples still did not. After the reruns about 1.5% remained unterminated, and when I looked at them they were all loops, the known degenerate failure of distilled reasoning models, where the CoT repeats itself until the budget runs out. More tokens do not fix a loop. So the third step, 03_resample_loops, replaces them with fresh prompts of the same label drawn from WildJailbreak (excluding the original picks, seed 43), and the patch step puts those into the original slots. The merge script’s contract is that the mask is all true after these recovery passes.

The cost of that choice is worth stating: the prompts that loop are probably not random, so replacing them quietly changes the sample slightly toward prompts that the model can finish thinking about. For a detector meant to run in production that is a real bias, and we have not measured it.

The surprise: the labels are a length detector

Before training anything I looked at how long the prompts are, and the picture was bad.

In WildJailbreak the adversarial_harmful prompts are long, elaborately framed stories and role-play setups. The vanilla_benign prompts are one-line requests. In my 20,000-sample draw, the mean harmful prompt is 963 characters. Cohen’s d on log-length is 7.15. A one-feature logistic regression on log character length gives an AUROC of about 1.0, and a hard threshold at 200 characters classifies 99.97% of the samples correctly. The two ranges barely overlap: the zone between the shortest harmful prompt and the longest benign one is only 102 to 221 characters, and the histogram below shows how little of either class lives there.

(An earlier draft of our write-up had d=5.33, 739 characters and AUROC 0.9993. I could not reproduce those from the seed, and the numbers above come from discussion_analysis.py. The correct ones are more extreme, which makes the confound worse, not better.)

Histogram of prompt length in characters for benign and harmful prompts, with the 200-character threshold and the small overlap zone marked

Prompt length in characters, 0 to 500 shown. Benign prompts cluster under 150; the harmful ones start around 380 and keep going.

This hits the input probe directly. A probe reads the hidden state at the last input token, and position is baked into that state by rotary embeddings. With the chat template, the last input token sits at a mean position of 21 for benign prompts and 191 for harmful ones. A probe can read that off without knowing anything about harm.

Histogram of the last input token position for benign and harmful prompts: benign mean 21, harmful mean 191

Where the final input token sits in the sequence. The two classes occupy different regions, and RoPE encodes that into the activation.

So “input probe beats everything” would not be a finding. It would be an artifact. And it muddies the comparison we set out to make: a high input AUROC cannot be taken as evidence that the input contains a harm signal, and a CoT probe that scores lower is not necessarily worse. The CoT end token has its own position, though it is a function of how long the model thought and not of the prompt length, which is a more interesting thing to confound with.

What I can and cannot claim

Extraction is essentially done: 20,000 samples with both activation sets and a CoT for each, with truncation handled and the remaining loops replaced. The 05_verify script checks shape and alignment, finite values, mask coverage, and a quick probe AUROC for input versus CoT activations. I do not have trustworthy numbers from the four trained detectors to report, and I do not want to quote the quick sanity AUROCs as results, because of the confound above.

I should also say the proposal’s headline claim, that CoT detection beats input detection on sneaky jailbreaks, is not supported or refuted by anything I have. WildJailbreak’s adversarial prompts are “sneaky” in the sense of long fictional framing, but the benign class is not an adversarial-looking benign class, so the data cannot separate a harm signal from a style signal.

What is next

  • Control for length. The obvious step is to match benign and harmful prompts on token length (WildJailbreak, as I understand it, also contains adversarial-style benign prompts, which would break the confound directly, but I have not sampled them) and re-run all four detectors.
  • Train and evaluate the four models, with per-layer probes next to the concatenated one, so we can see where in the stack the signal lives.
  • Measure the CoT side of the confound: how much does CoT length alone predict the label?
  • Latency versus accuracy, as the proposal says: a CoT detector needs a generation pass first, and that cost is only worth paying if it buys something.