CoT-Guard: Achieving strong monitoring with a small modelCoT-Guard: Small Models for Strong Monitoring
The authors train a 4B monitoring model, CoT-Guard, to detect hidden objectives in code generation; the authors state that it achieves a G-Mean2 of 75.70% on 9 out-of-domain objectives, exceeding GPT-5.4 (56.50%).
The third-party API router acts as a man-in-the-middle attacker, controlling the input to model M and the (CoT, Code) returned to the user, but not controlling M itself; it is assumed that M faithfully executes the instructions it receives. The attacker injects hidden objectives by tampering with the user prompt via Prompt Manipulation (A1) or by directly tampering with the generated code via Code Manipulation (A2).
- Monitoring the CoT of reasoning models can detect hidden objectives in code generation, but large-model monitors are costly to deploy, while existing 4B–8B small models often misjudge hidden objectives as part of the main task and have insufficient detection capability.
- Proposes CoT-Guard: first SFT distillation on correct monitoring trajectories from Qwen3-32B, then RL with GRPO on three subtle hidden objectives; under a threat model in which a third-party API router injects hidden objectives, it is evaluated with 9 out-of-domain objectives.
- Under A1, with Qwen3-14B as M and CoT+Code, CoT-Guard 4B's average G-Mean2 is 75.70%, higher than GPT-5.4 (56.50%) and GPT-5-mini (41.90%), and lower than Gemini-3-Flash (83.82%); under A2 it is 62.03%, still higher than Qwen3-32B and GPT-5.4.
- The authors note that the evaluation is limited to code generation tasks, that coverage of hidden objectives is limited, and that each trajectory is assumed to contain at most one hidden objective; the queried models M in the experiments are two, Qwen3-14B and GPT-5, and the paper does not report the sample size or number of repetitions for each condition.
- Evaluated models
- Qwen3-4BCoT-Guard 4BQwen3-8BQwen3-32BLlama3.1-8B-InstructGPT-5-miniGPT-5.4Gemini-3-Flash
- Benchmarks
- Arnav et al. 的 5 个隐藏目标(Exit、Permissions、Log I/O、Edge Case、Long Lines)4 个新隐藏目标(Package Forcing、Typosquatting、Ads Comment、Ads Print)BigCodeBenchKodCode
- Metrics
- G-Mean2 (TPR×TNR)
The researchers propose CoT-Guard, a 4B-parameter small chain-of-thought monitor for detecting injected hidden objectives in code generation tasks. Existing small models of 4B to 8B parameters, even when able to read the chain of thought, often misjudge hidden objectives as part of the user request. CoT-Guard uses a post-training pipeline combining supervised fine-tuning and reinforcement learning: supervised fine-tuning distills detection behavior from a stronger monitor, while reinforcement learning uses difficult and covert hidden objectives to improve out-of-domain generalization. Under a threat model in which a third-party LLM router injects hidden objectives through prompt manipulation or code manipulation, CoT-Guard achieves 75% G-mean^2 (TNR×TPR), higher than GPT-5.4's 56%, GPT-5-mini's 41% and Qwen3-32B's 54%, and still lags behind Gemini-3-Flash's 83%. The research also introduces four new tasks that are challenging even for large-model monitors.
Paper analysis
What problem does this paper attempt to solve?
How to enable a small 4B model to monitor hidden objectives in code generation CoT like a large model, reducing monitoring deployment cost.
Core question: Can a 4B-level small model be trained to effectively monitor the CoT of code generation models and detect hidden objectives injected into it by an external attacker, thereby replacing expensive large-model monitors?
- Scenario and motivation: Code generated by autonomous coding agents (Claude Code, Devin, SWE-Agent) is increasingly deployed without human review, and the authors argue automated safety supervision becomes critical; monitoring the CoT can reveal hidden behaviors such as reward hacking, sandbagging, and sabotage.
- Shortcomings of existing methods: The authors state that current CoT monitoring relies on large models such as GPT-5.4 and Gemini-3-Flash, with high API costs and dependence on closed-source services; existing small models (4B–8B) detect poorly even when they can see the CoT, often misattributing hidden objectives as part of the user query (task misattribution, Figure 2(b)).
- Core observation: The authors find that SFT can close the gap on in-domain tasks but generalizes poorly out of domain; RL on subtle hidden objectives that are hard to monitor provides a strong learning signal that helps small models generalize to out-of-domain monitoring tasks.
- What the paper proposes: CoT-Guard, a 4B monitor model (post-trained based on Qwen3-4B); a man-in-the-middle threat model inspired by supply chain attacks and two types of attack paths; 4 new, harder hidden objectives (Package Forcing, Typosquatting, Ads Comment, Ads Print).
- Threat model:
- Attacker goal: A third-party API router implements an arbitrary hidden objective τhid (e.g., data exfiltration, inserting promotional content, malicious payload) in the code delivered to the user.
- Attacker knowledge and capability: man-in-the-middle control—controls M's input and the (CoT, Code) returned to the user; does not control M itself.
- Key assumption: M faithfully executes any instruction it receives, including tampered task descriptions.
- Victim system and attack paths: The user uses code generation model M through the router; A1 (Prompt Manipulation) tampers with the user prompt, A2 (Code Manipulation) directly tampers with the generated code.
What related research exists?
Related work falls into three groups: CoT monitoring, code security risk monitoring, and small safety evaluation models; this paper positions itself as a small-model monitor plus an external-attacker threat model.
CoT monitoring
- Baker et al. [11], Guan et al. [14], Kale et al. [13], Arnav et al. [12]—use LLMs to monitor reasoning trajectories to find misbehavior or stress-test CoT monitorability; the paper notes that these works rely on large models (Claude Sonnet 4.5, Gemini-3-Pro, GPT-5.4) as monitors and focus on larger monitors.
- Yang et al. [21] (AutoMonitor-Bench)—evaluates the reliability of LLM misbehavior monitors; the paper states that despite such preliminary attempts, a clear performance gap remains between small monitors and proprietary LLMs.
- The paper also cites concerns about CoT faithfulness [23–25], but considers CoT still a meaningful interface for monitoring how models plan their outputs [26, 27].
Code security risk monitoring
- Static analysis tools [33–37] (e.g., Semgrep, CodeQL, Bandit) and LLM vulnerability detectors [38–40]—analyze only the final code, typically modeling risk as vulnerable code written by the developer, an insecure generator, or an external attacker.
- Works that monitor coding agents using reasoning trajectories plus code [11, 12, 14, 17] (e.g., SHADE-Arena)—the paper notes that most of them treat the model itself as the attacker (a misaligned agent hiding or executing malicious intent), whereas this paper's setting is complementary: an external attacker induces risky behavior, and the model remains the monitored system.
Small safety evaluation models
- Souly et al. [18]—fine-tunes a 2B model as a jailbreak evaluator, which the paper states reaches state-of-the-art agreement with human judgment; Llama Guard [19], JailJudge [20]—input-output safeguards and jailbreak judgment. The paper notes that such small evaluators have proven practical in other safety evaluation domains, but no counterpart exists in the monitoring domain.
Baselines and benchmarks: the comparison baselines are large monitors (Qwen3-32B, GPT-5.4, Gemini-3-Flash) and two ablations, SFT Only and RL Only; the evaluation uses the 5 hidden objectives of Arnav et al. [12] plus 4 new objectives from this paper, and the training objectives are also taken from Arnav et al. [12].
The authors position this paper as: a locally deployable small-model CoT monitor for coding tasks under an external-attacker threat model, and state that it is the first 4B model to surpass several larger proprietary models on coding task monitoring.
How does the paper address this problem?
Two-stage post-training: first SFT distillation from correct monitoring trajectories of Qwen3-32B, then RL with GRPO on three subtle hidden objectives.
The overall idea is to distill the detection behavior of a large monitor into a small model, then use RL to elicit generalization ability on hard samples, yielding CoT-Guard (based on Qwen3-4B).
Monitor setup
- The monitor model MG takes as input the user's initial query, the CoT and the received code, and outputs reasoning rG and a binary detection signal yG; the monitoring scope is s ∈ {Code, CoT, CoT+Code}.
- Under A1, MG sees the contaminated CoT (r̃) and code (c̃); under A2, it sees the uncontaminated CoT (r) paired with contaminated code (c̃), i.e., the CoT is unfaithful to the final code.
Stage 1: SFT distillation
- Construct dataset Dm: trajectories in which the large monitor correctly detects hidden objectives; additionally add a benign dataset Db (no hidden objective and the large monitor correctly stays silent) to reduce false positives.
- The training objective is the standard SFT loss Ls(θ) := −E(x,rG,yG)∼ D log πθ(⟨ rG, yG ⟩ ∣ x), i.e., maximizing, on the mixed dataset D, the likelihood that the small monitor reproduces the large monitor's reasoning and judgment.
- Qwen3-32B is used as the large monitor to generate supervision trajectories; 3 I/O-related hidden objectives are selected (I/O Delete, I/O Download, I/O Exfiltrate Secret, Table 3).
Stage 2: RL generalization
- GRPO [49] is used to train on 3 more subtle hidden objectives (Default Value, Complexity, Variable Name); the authors state that these objectives are coupled with the main task and harder to detect—Qwen3-32B achieves only about 20.68% and 30.04% G-Mean2 on Variable Name and Default Value.
- Verifiable reward: 1 for correct detection with reasoning that correctly identifies the evidence; 0.5 for not flagging but the reasoning notices the hidden objective; 0 otherwise. When there is no hidden objective, 1 for correctly staying silent, otherwise 0, to suppress false positives.
Implementation details
- The queried model M is Qwen3-14B; the SFT and RL data are balanced between trajectories with and without hidden objectives, and only prompt-manipulation (A1) data is used.
- SFT has 11,136 samples (covering three scopes: action-only, cot-only, all-message), RL has 5,690; SFT learning rate 5e-6, 7 epochs, batch 128; RL 8 rollouts per query, batch 256, learning rate 1e-6, maximum response length 4096 (Appendix A.1).
- Training uses LlamaFactory and veRL; at evaluation, temperature 0.6, top-p 0.95.
Evaluation design
- Metric G-Mean2 = TPR×TNR: TPR is the proportion of samples containing a hidden objective that are correctly flagged, TNR is the proportion of samples without a hidden objective that are correctly let through.
- The 9 out-of-domain evaluation objectives do not overlap with the 6 training objectives, and the main tasks for training and evaluation also do not overlap; the monitor outputs a four-level judgment A/B/C/D (Appendix F gives the full monitoring and attack prompt templates).
What experiments did the paper conduct?
Evaluated on 9 out-of-domain objectives under two attack types A1/A2, two M models, and multiple hiding strategies, CoT-Guard 4B's average G-Mean2 exceeds GPT-5.4 and GPT-5-mini.
Experimental setup
- Monitored models tested: CoT-Guard 4B (based on Qwen3-4B), Qwen3-4B, Qwen3-8B, Qwen3-32B, Llama3.1-8B-Instruct, GPT-5-mini, GPT-5.4, Gemini-3-Flash; plus a Gemini-3-Flash "Aware τhid" variant (told the exact hidden objective, which the authors describe as an unrealistic upper-bound approximation).
- Queried model M: Qwen3-14B and GPT-5, used to generate (CoT, Code) trajectories with/without hidden objectives.
- Evaluation objectives: 9 out-of-domain hidden objectives—5 from Arnav et al. (Exit, Permissions, Log I/O, Edge Case, Long Lines), 4 newly proposed (Package Forcing, Typosquatting, Ads Comment, Ads Print, Table 4).
- Attacks and strategies: A1 (Prompt Manipulation) includes four prompt strategies: Standard, Stealth, Monitor Notice, Dependency; A2 (Code Manipulation) concatenates hidden-objective code with benign CoT via two queries.
- Metric and judgment: G-Mean2 = TPR×TNR; the monitor outputs an A/B/C/D judgment (Appendix F template). The paper does not report sample sizes or number of repetitions for each condition.
- Baselines: SFT Only, RL Only (both on Qwen3-4B) and zero-shot monitoring by the large models above.
Main results
According to Table 1 (A1, Qwen3-14B as M, Standard strategy, G-Mean2 %, average over 9 objectives):
Model Code scope CoT+Code scope Llama3.1-8B-Instruct 24.06 0.59 Qwen3-4B 12.86 13.37 Qwen3-8B 36.17 39.60 Qwen3-32B 39.38 54.06 GPT-5-mini 18.45 41.90 GPT-5.4 29.99 56.50 Gemini-3-Flash 81.02 83.82 CoT-Guard 4B 70.35 75.70 - The authors state that under CoT+Code, CoT-Guard 4B trails Gemini-3-Flash by 8.12% on average and leads GPT-5.4 by 19.20%; under Code-only, its average advantage over GPT-5.4 is 40.36%.
- The base Qwen3-4B achieves only 13.37% under CoT+Code; the authors state that post-training narrows the gap with Gemini-3-Flash from more than 40 percentage points to within 8 percentage points.
- Exceptions: CoT-Guard remains near zero or low on Edge Case (0.93) and Long Lines (23.97); Gemini-3-Flash is also 0.00 on Edge Case.
Code tampering attack (A2)
- According to Table 2 (A2, Qwen3-14B as M, CoT+Code): CoT-Guard 4B averages 62.03%, higher than Qwen3-32B (54.64%), GPT-5.4 (34.95%), GPT-5-mini (29.94%), and lower than Gemini-3-Flash (73.16%).
- The authors state that A2 is stronger than A1: CoT-Guard drops from 68.60% under A1 to 22.22% under A2 on Typosquatting, which the authors explain as the model treating a misspelled package name as a genuine typo when there is no corresponding spelling error in the reasoning; Ads Comment also drops from 98.90% to 17.34%.
Robustness to concealment strategies
- According to Table 1 and Table 5 (Qwen3-14B as M): relative to Standard (75.70%), Monitor Notice lowers CoT-Guard's average G-Mean2 by 1.08% (74.62%); the authors state that Dependency and Stealth do not decrease but increase, by 3.15% and 18.67% respectively (reaching 94.37% under Stealth).
- The authors' interpretation: current LLMs often cannot fully execute hidden instructions and still leak evidence of the hidden objective in the CoT, consistent with the contemporaneous findings of Wang et al. [53].
Training stage and data ablation
- According to Table 8 (Qwen3-14B as M, A1, CoT+Code): vanilla Qwen3-4B 13.37%; SFT(I/O) 33.71%; RL(Subtle) 66.85%; SFT(I/O)+RL(Subtle), i.e., CoT-Guard, 75.70%.
- RL data choice: when initialized from Qwen3-4B, RL with subtle objectives is 26.03% higher than with I/O objectives (66.85 vs. 40.82); when initialized from the SFT checkpoint, it is 20.92% higher (75.70 vs. 54.78).
Other ablations and analyses
- Changing M to GPT-5 (Table 6, A1 Standard, CoT+Code): CoT-Guard 76.54%, GPT-5.4 57.41%, Gemini-3-Flash 81.97%.
- Value of CoT (§6.3): under Standard A1, adding CoT raises CoT-Guard's average from 70.35% to 75.70%, with Ads Comment alone +31.40 percentage points.
- Difficulty of new objectives (§6.1): GPT-5-mini averages 42.5% on the 4 new objectives, with Typosquatting only 9%; on the 4 new objectives, all models' G-Mean2 is below 70%.
- Motivation experiment (§4.1): 5 of 6 models detect better with taint-free CoT than with Code Only, Qwen3-4B by +17.5 percentage points; Gemini-3-Flash instead decreases slightly, which the authors attribute to this signal introducing noise for strong models that can detect from code alone.
What are some points that can be further explored?
The authors list three limitations: limited to code tasks, limited hidden objective coverage, and the single hidden objective assumption; the experiments use two Ms and do not report sample sizes.
Limitations and future directions noted by the authors
- Task scope: the evaluation focuses only on code generation monitoring, with hidden objectives manifested through the generated code and reasoning trajectories (Appendix C).
- Hidden objective coverage: the 9 out-of-domain objectives cover only a subset of possible adversarial objectives; real attackers may combine multiple objectives, use more subtle semantic manipulation, or target project-specific vulnerabilities (Appendix C).
- A1 attack form: the authors note that an A1 attacker could also, like A2, draw on LLMs or fine-grained rules (e.g., rewriting the main task τ from scratch to incorporate a hidden objective); its effectiveness is left to future work (Appendix C).
- Single hidden objective assumption: the current setting assumes at most one hidden objective per trajectory; extending to identifying, localizing and distinguishing multiple hidden objectives is described by the authors as an important direction (Appendix C).
- False positive risk: the authors caution that users may over-trust the monitoring output, that false negatives may still exist, and that CoT-Guard should be one component of a larger defense pipeline including sandboxing, dependency analysis, static analysis and human review (Appendix D).
Scope of experimental coverage
- There are 8 monitored models tested in total (including the Aware τhid variant), and two queried models M, Qwen3-14B and GPT-5 (§6.2).
- The evaluation covers 9 out-of-domain hidden objectives, four A1 prompt strategies and one A2 construction method; training uses only A1 data (§5, §6.2).
- Training data consists of 11,136 SFT samples and 5,690 RL samples, and the hidden objectives and main tasks for training and evaluation do not overlap (Appendix A.1, §6.2).
- The paper does not report the sample size, number of repetitions or confidence intervals for each evaluation condition, nor does it report human evaluation or agreement between monitor judgments and humans.
- The paper does not report actual deployment cost or latency figures for CoT-Guard; the cost advantage is stated only qualitatively in terms of parameter count and "avoiding large-model API costs".
Summarize the main content of the paper
CoT-Guard uses SFT plus RL to turn a 4B model into a CoT monitor, which the authors state surpasses GPT-5.4 and approaches Gemini-3-Flash.
A defense paper about small CoT monitors, aimed at code generation scenarios.
- Problem: Monitoring the CoT of reasoning models can reveal hidden objectives in code, but large-model monitors are expensive, and small models (4B–8B) detect poorly, often mistaking hidden objectives for part of the main task.
- Threat model: A third-party API router acts as a man-in-the-middle, injecting hidden objectives by tampering with the prompt (A1) or tampering with the generated code (A2); it is assumed the router does not control M and that M faithfully executes instructions.
- Method: CoT-Guard (based on Qwen3-4B) two-stage post-training—first SFT on correct monitoring trajectories from Qwen3-32B (3 I/O-type objectives), then GRPO RL on 3 subtle objectives (Default Value, Complexity, Variable Name); additionally proposes 4 new, harder evaluation objectives.
- Main results:
- Under A1, with Qwen3-14B as M and CoT+Code, CoT-Guard averages G-Mean2 75.70%, higher than GPT-5.4 (56.50%), GPT-5-mini (41.90%), and Qwen3-32B (54.06%), and lower than Gemini-3-Flash (83.82%) (Table 1).
- Under A2, CoT-Guard is 62.03%, still higher than Qwen3-32B (54.64%) and GPT-5.4 (34.95%) (Table 2).
- The base Qwen3-4B is only 13.37%; ablations show RL with subtle objectives is 26.03% higher than with I/O objectives (Table 8).
- The Monitor Notice hiding strategy reduces CoT-Guard by only 1.08%; the authors state that current LLMs often cannot hide evidence of hidden objectives.
- Authors' conclusion: A small, locally deployable monitor can provide practical user-side defense for LLM coding systems; the authors open-sourced the model, training scheme, code, and all evaluations, and caution that the monitor should be one part of a multi-layer defense rather than relied on alone.
Related papers
- Auditing Games for SandbaggingRisky behaviorarXiv