TACIT: detecting agent trajectory harm from LLM internal statesAgent Safety From Within: Detecting Harmful Trajectories from LLM Internal States
The authors propose TACIT, which detects agent trajectories based on reading frozen internal representations; across 6 benchmarks, Qwen3-4B Multi-layer achieved an average macro-F1 of 86.2% (Table 1).
The victim system is a tool-calling agent. Attacks and risk forms include two types of evidence: directly expressed harmful content and unsafe tool use (e.g., prompt injection, goal hijacking, authorization violation, privacy leakage, data exfiltration, destructive operations, etc.), and the judgment criterion is whether any step in the trajectory is unsafe.
- Agents may cause risks such as harmful content or unsafe tool use during tool calls. Existing open-source Guard models are mainly designed for single-turn text content moderation and perform poorly on tool-calling trajectories, especially when unsafe behavior depends on whether the action is consistent with the context/tool schema, where Guard models' output end struggles to discriminate (Section 1, 3.1).
- The authors first use comparative activation analysis to confirm that the two risk types are linearly readable and orthogonal in direction in the model's internal representations; they then propose TACIT, which fixes the pretrained backbone without updating parameters, pools intermediate-layer hidden states, and trains linear probes or multi-layer feature aggregation classifiers to directly output safety scores without generating any tokens (Section 4.1).
- Across 6 trajectory safety benchmarks, TACIT Multi-layer on Qwen3-4B achieved an average macro-F1 of 86.2%, higher than the highest evaluated Guard baseline value of 62.3% (Table 1); under leave-one-out benchmark evaluation, it averaged 65.7% (Table 2), with a per-trajectory detection latency of 40ms (Figure 4c).
- The authors note that the current evaluation targets whole trajectories rather than streaming action boundaries; when used directly for prefix judgment, it may trigger interception prematurely due to request content before the agent takes any action; the experiments cover 6 benchmarks and 2 model families, and do not report the impact of streaming intervention on task utility in closed-loop environments (Section 5.3, Appendix D).
- Evaluated models
- Qwen3Guard-4BLlamaGuard3-8BAgentDoG-4BQwen3-4B-InstructLlama-3.1-8B-Instruct
- Benchmarks
- R-JudgeTraceSafeATBenchASSEBenchOpenAgentSafetyAgentDojo
- Metrics
- macro-F1rank accuracyAUCprecisionrecall
Researchers at the University of Toronto propose TACIT, which uses linear probes on the internal states of a frozen LLM to judge whether tool-call trajectories are safe, without decoding any tokens. Analysis finds that existing open-source guardrail models perform only at chance level on unsafe tool use in their outputs, but this distinction is linearly readable in the model's internal states and is nearly orthogonal to the direction of harmful content; the two cannot substitute for each other. On six trajectory safety benchmarks, TACIT raises average macro-F1 from 62.3 for the strongest open-source guardrail to 86.2 (Qwen3-4B) and 85.4 (Llama-3.1-8B); with each benchmark completely held out during training, it still leads 65.7 versus 61.1. Under the same backbone, data, and test split, frozen readouts are comparable to full safety fine-tuning, and stacking them on a fine-tuned model further improves performance; the probe's trainable parameter count is about one millionth of full fine-tuning, training time about one sixth, and inference latency 40ms, lower than Qwen3Guard's 215ms.
Why it was selectedThe paper provides a method for trajectory safety interpretation using frozen model internal states, along with comparison data against guardrail models and full fine-tuning, which can serve as a reference for teams working on agent monitoring.
Paper analysis
What problem does this paper attempt to solve?
Addressing the problem that open-source Guard models struggle to effectively detect unsafe tool use and multi-step interaction risks on agent trajectories.
This paper attempts to address the problem of detecting safety risks in tool-calling trajectories of language model agents, particularly the failure of existing open-source Guard models at the output end in identifying "unsafe tool use."
- Problem scenario and importance: Large language models acting as agents can call external tools to perform operations such as search, messaging, and code execution, extending potential harm to real-world environment interactions; safety judgment no longer depends solely on the harmfulness of a single text, but also on whether the action is consistent with the interaction context (Section 1).
- Limitations of existing methods: The authors state that existing mainstream open-source Guard models (e.g., Llama Guard, Qwen3Guard) are primarily designed for dialogue content moderation; on tool-calling trajectories, even specialized agent Guards (e.g., AgentDoG) struggle to distinguish unsafe tool calls caused by tool schema changes, with discrimination ability at the output end close to random (Section 1, 3.1).
- Core observation and hypothesis: The authors observe that agent trajectory risk contains two types of evidence: "harmful content" and "unsafe tool use"; although the Guard model's generated output loses discriminative ability for unsafe tool calls, this signal remains linearly readable in the model's intermediate hidden states, and the internal representations of the two risk types are nearly orthogonal in direction (Section 3.1, 3.2).
- Proposed approach: The authors propose TACIT, which reads representations directly from the intermediate hidden states of a frozen LLM and trains lightweight classifiers, without updating LLM parameters or decoding any tokens, achieving low-latency and high-accuracy trajectory safety detection (Section 4.1).
- Threat model:
- Attacker goals: induce the agent to execute harmful requests, or cause environmental harm through indirect prompt injection, goal hijacking, unauthorized operations, privacy data leakage, or tool parameter misuse (Section 1, Appendix A.1).
- Attacker knowledge and capabilities: attackers can inject malicious instructions into tool return values or prompts, inducing the agent to pass mismatched parameters in tool calls, bypass authorization, or exfiltrate sensitive data to external addresses; the evaluation includes interaction trajectories in both white-box and black-box environments (Section 1, 4.2).
- Victim system: LLM-based tool-calling agent systems with multi-round interaction environments and external tool-calling capabilities (Section 1, 4.1.1).
- Safety judgment criterion: if any step in the complete trajectory is unsafe, the entire trajectory is judged unsafe, y = 1 (Section 4.1.1).
What related research exists?
This involves three lines of research: agent trajectory safety benchmarks, safety Guard models, and safety detection and intervention based on model internal representations.
The related work discussed in the paper is mainly distributed across three areas: agent trajectory safety benchmarks, Guard models, and internal representation safety applications:
- Agent Trajectory Safety Benchmarks:
- ToolEmu by Ruan et al. (2024), Agent-SafetyBench by Zhang et al. (2024), AgentHarm by Andriushchenko et al. (2025), and R-Judge by Yuan et al. (2024) evaluate agents' unsafe behavior and risk identification ability in tool interactions.
- TraceSafe by Chen et al. (2026) and ATBench by Li et al. (2026b) score complete tool-calling trajectories, covering safety risks that appear across steps.
- Guard Models:
- Llama Guard by Inan et al. (2023), WildGuard by Han et al. (2024), and Qwen3Guard by Zhao et al. (2025a) serve as auxiliary models generating safety judgments for prompts or responses, and are the mainstream open-source content moderation solutions.
- TraceSafe by Chen et al. (2026) evaluates existing Guards on tool-calling trajectories; AgentDoG by Liu et al. (2026) is a specialized Guard model fine-tuned specifically for evaluating and diagnosing complete agent trajectories.
- Internal Representations for Safety:
- Alain & Bengio (2017), Burns et al. (2023), Azaria & Mitchell (2023), among others, use linear probes to reveal latent knowledge in intermediate-layer representations, showing that some internal information is not reliably expressed at the generated output end.
- Zhou et al. (2024), Zhao et al. (2025b), Jiao et al. (2024, 2026) use internal activation analysis for alignment and jailbreak mechanisms, or read classification results from neurons of frozen LLMs to detect harmful inputs and outputs; the authors note that their work extends to tool-calling trajectories, handling scenarios where individual messages are harmless but the overall trajectory is unsafe.
- Baseline methods and benchmark datasets:
- The baselines compared in the paper include the open-source Guard models Qwen3Guard-4B and LlamaGuard3-8B, and the specialized agent Guard model AgentDoG-4B; the evaluation benchmarks used include R-Judge, TraceSafe, ATBench, ASSEBench, OpenAgentSafety, and AgentDojo, a total of 6 trajectory safety benchmarks (Section 4.2).
- Positioning difference from existing work: The authors note that TACIT maintains the modular isolation between the Guard model and the monitored agent, but abandons the practice of generating safety labels through decoding, instead reading safety scores directly from the internal states of the frozen backbone (Section 2.2, 2.3).
- Agent Trajectory Safety Benchmarks:
How does the paper address this problem?
Propose TACIT, which reads representations from intermediate layers of a frozen backbone network and outputs safety scores via linear probes, ensembles, or multi-layer aggregation.
The authors propose TACIT (Trajectory Assessment by Classifying Internal Transformer states), a framework that reads representations directly from the internal hidden states of a frozen language model, enabling trajectory safety judgment without decoding any tokens.
Problem Formulation and Representation Extraction
- Trajectory classification problem formalization: Given a complete trajectory tau containing multiple rounds of interaction, the Guard model predicts a binary label y in {0, 1}, where y = 1 if any step in tau is unsafe (Section 4.1.1).
- Single forward pass: The entire trajectory tau is rendered using the LLM backbone's native chat template (preserving the system prompt, tool schema, message roles, and interaction order), and a single forward pass is performed to obtain hidden states at each layer (Section 4.1.1).
- Representation pooling: At each candidate layer l, the sequence states are pooled into a single vector xl(tau); the pooling strategy is selected on the validation set among the last token state, the mean vector of all tokens, or their concatenation (last+mean) (Section 4.1.1, Appendix B.4).
Linear Probe Design
- Application of the linear representation hypothesis: Based on the assumption that semantic concepts are largely linearly represented in LLMs, TACIT trains a linear probe on the standardized feature vector at candidate layer l, outputting the unsafe probability:
sl(τ) = σ(ul⊤ x̃l(τ) + cl) This formula applies a linear transformation to the standardized hidden state via the Sigmoid function and computes the unsafe probability (Equation 1).
- Optimization and hyperparameters: L2-regularized logistic regression is used to fit weights ul and bias cl; training samples are inverse-frequency weighted by class within each benchmark so that each class has equal total weight per benchmark; the inverse regularization strength C and layer index l are selected on the validation fold, and the decision threshold is fixed at 0.5 (Section 4.1.2, Appendix B.4).
Lightweight Refined Readout Mechanisms
- Ensemble readout: Using forward selection with replacement, probes that maximize the average AUROC or macro-F1 across the 6 benchmarks are iteratively added and their predicted probabilities are averaged; the search budget is set to 5, 10, or 20 additions (Section 4.1.2, Appendix C.1).
- Multi-layer aggregation: First, L1-regularized auxiliary probes at each layer select significant dimension sets whose cumulative weight magnitude reaches eta; then the significant features from each layer are concatenated and an L2-regularized logistic regression or single-hidden-layer MLP classification head is fitted on the concatenated features (Section 4.1.2, Appendix C.2).
- Parameters and frozen nature: All probes and refined layers are fitted on offline activations of the frozen backbone; the backbone is not involved in backpropagation at all, and no autoregressive decoding is required at inference time (Section 4.1.1, 4.3.2).
What experiments did the paper conduct?
Detection performance, leave-one-out generalization, combination with SFT, and training and inference efficiency were evaluated on 6 benchmarks.
Experimental Setup
- Models under test: The open-source Guard baselines evaluated are Qwen3Guard-4B, LlamaGuard3-8B, and AgentDoG-4B; the backbone models used for TACIT and full SFT are Qwen3-4B and Llama-3.1-8B; mechanism analysis involves Qwen3-4B-Instruct and Llama-3.1-8B-Instruct; the OpenAgentSafety trajectory source includes GPT-4o and o3-mini, among others (Section 4.2, Appendix B.1, B.2).
- Datasets and scale: The evaluation includes 6 annotated agent trajectory safety benchmarks, totaling 9,487 trajectories (3,996 unsafe, 5,491 safe), with 1,900 held out for testing: R-Judge (571 trajectories, 116 test), TraceSafe (2,250 trajectories, 449 test), ATBench (1,000 trajectories, 200 test), ASSEBench (merged Safety and Security, 2,293 trajectories, 455 test), OpenAgentSafety (1,298 trajectories, 259 test), AgentDojo (2,075 collected, 421 test) (Table 4).
- Baseline methods: Dialogue content moderation Guard models Qwen3Guard-4B and LlamaGuard3-8B, and the specialized Guard model AgentDoG-4B trained specifically for agent trajectories (Section 4.2).
- Evaluation metrics: The primary evaluation metrics are macro-F1 per benchmark (to address class imbalance) and the average macro-F1 across the 6 benchmarks (Avg); mechanism analysis uses pairwise rank accuracy and area under the receiver operating characteristic curve (AUC) (Section 4.1.2, 4.2, Appendix A.2).
- Review method and thresholds: Guard baselines use the official release pipeline and greedy decoding, with Qwen3Guard mapping Controversial to unsafe; TACIT linear probes use a fixed threshold of 0.5; confidence intervals are computed as the 95% confidence interval half-width based on 2,000 trajectory bootstrap resamples within each benchmark (Section 4.2, Appendix B.1, B.2, B.3, B.4).
- Data split and protocol: A scenario-aware 80%/20% train-validation and test split is used, with trajectories sharing the same scenario and request assigned to the same side; within the 80% training set, 4-fold validation is used for hyperparameter and layer selection, after which the model is refit on all 80% of the data and evaluated on the test set only once (Appendix B.3).
Main Results
Swipe horizontally to read the table
Model/Method R-Judge TraceSafe ATBench ASSEBench OAS AgentDojo Average Qwen3Guard-4B 32.2 34.7 36.8 43.6 38.2 44.9 38.4 LlamaGuard3-8B 66.3 48.6 38.9 60.6 35.9 62.5 52.2 AgentDoG-4B 92.7 44.7 63.3 81.4 43.3 48.2 62.3 TACIT Probe (Qwen3-4B) 95.0 77.5 93.5 85.2 67.9 65.1 80.7 TACIT Ensemble (Qwen3-4B) 97.0 88.7 95.0 88.5 72.0 71.0 85.4 TACIT Multi-layer (Qwen3-4B) 97.0 86.5 94.5 89.8 72.7 76.9 86.2 TACIT Probe (Llama-3.1-8B) 98.0 79.7 89.5 88.1 67.5 66.6 81.6 TACIT Multi-layer (Llama-3.1-8B) 97.0 89.6 95.0 88.5 69.8 72.2 85.4 (Note: According to Table 1, the Ensemble row for Llama-3.1-8B is omitted; its average is 85.1%)
- Outperforms existing Guards on all benchmarks: The authors note that with the same backbone, using only a single-layer linear probe (Probe) achieves an average macro-F1 42.3 percentage points higher than Qwen3Guard-4B, 29.4 percentage points higher than LlamaGuard3-8B, and 18.4 percentage points higher than the specialized agent Guard model AgentDoG-4B (Section 4.3.1).
- Refined readouts further improve performance: Multi-layer feature aggregation (Multi-layer) further raises the average macro-F1 across the 6 benchmarks to 86.2% and 85.4% on Qwen3-4B and Llama-3.1-8B, respectively (Section 4.3.1).
- Performance in complex and black-box source scenarios: The authors state that on AgentDojo, where instruction injection sources are hidden, Multi-layer readout reaches 76.9%, higher than the highest Guard baseline value of 62.5%; on OpenAgentSafety, where trajectories come from black-box agents such as GPT-4o, probe readout exceeds the baselines by more than 24 percentage points without accessing the monitored model (Section 4.3.1).
Leave-One-Benchmark-Out Generalization Evaluation
- Evaluation setup: One of the 6 benchmarks is completely excluded from training, the reader is trained only on all trajectories from the remaining 5 benchmarks, and zero-shot transfer testing is performed on the full trajectories of the held-out benchmark (Section 4.3.1, Table 2).
- Test results: On Qwen3-4B, Probe, Ensemble, and Multi-layer achieve average macro-F1 of 62.6%, 63.3%, and 65.7%, respectively, all higher than AgentDoG-4B evaluated on all data from all 6 benchmarks (average 61.1%); on Llama-3.1-8B, Multi-layer reaches 63.5% (Table 2).
- Authors' interpretation: The authors note that TACIT uses only about 7,900 trajectories per fold for training, while AgentDoG synthesized more than 100,000 trajectories; on unseen benchmarks, internal readouts still maintain an advantage over the strong baseline (Section 4.3.1).
Comparison and Combination with Full Safety Fine-Tuning (Full SFT)
- Evaluation setup: With the same backbone and the same training pool (about 5,700 trajectories per fold on average), the frozen-representation readout is compared with full-parameter safety fine-tuning (SFT) and their combination (Section 4.3.1, Appendix B.2, Table 6).
- Test results: The frozen probe alone scores 3.5 and 4.2 percentage points lower than SFT, but Multi-layer brings Qwen3-4B to 86.2% (SFT: 84.2%) and Llama-3.1-8B to 85.4% (SFT: 85.8%); adding Multi-layer readout on top of the SFT model further raises the average macro-F1 of both to 86.5% and 87.0% (gains of +2.3 and +1.2 percentage points, respectively) (Table 1, Table 6).
- Authors' interpretation: The authors argue that internal state readout and safety fine-tuning are complementary, with frozen readout matching full fine-tuning in performance and achieving further gains on fine-tuned models (Section 4.3.1).
Training and Serving Efficiency Comparison
- Evaluation setup: On Qwen3-4B, the number of trainable parameters, training time, and end-to-end detection latency for single-trajectory forward generation are compared (Section 4.3.2, Figure 4).
- Test results: The single-layer Probe has 5,121 trainable parameters (Qwen3-4B) and 8,193 (Llama-3.1-8B), only about one-millionth of full SFT (4.0B parameters); training time drops from 2.11 hours for SFT to 0.36 hours for Probe; inference detection latency is 40ms for TACIT (0 tokens generated), 53ms for AgentDoG (2 tokens decoded), and 215ms for Qwen3Guard (13.2 tokens decoded) (Figure 4).
- Authors' interpretation: The authors state that TACIT requires no autoregressive decoding, reducing latency by 82% compared to Qwen3Guard, and that multi-layer aggregated readouts lie on the cost-precision Pareto frontier (Section 4.3.2).
Other Ablations and Analyses
- Threshold calibration: After calibrating thresholds per benchmark for the baselines, Qwen3Guard-4B rises to an average of 54.4%, LlamaGuard3-8B to 60.9%, and AgentDoG-4B to 65.5%, still trailing the Probe by more than 15 percentage points (Table 5).
- Internal layer selection: The Qwen3-4B probe validation macro-F1 rises with layer depth and peaks at layer 22 with 80.9%, slightly dropping to 79.0% at the final layer (Section 5.1, Figure 5).
- Early exit: When truncating at layer 22 and discarding the remaining 14 layers, Multi-layer readout maintains a macro-F1 of 85.3%, retaining about 99% of the 86.2% at full depth (Section 5.1).
- Feature sparsity: On Qwen3-4B and Llama-3.1-8B, retaining only 2.0% and 2.3% of dimensions reduces macro-F1 by only 1.3 and 1.4 percentage points relative to the optimal coefficients (Section C.2.1, Figure 11).
- Decision dimension separation: Feature dimension sets contributing half of the logit difference for TraceSafe and HAICOSYSTEM (23 and 16 dimensions, respectively) contribute only 10.9% and 0.7% to the other risk form, respectively (Section 5.2, Figure 6).
- Failure cases and prefix triggering: In an ASSEBench-Safety case, TACIT scores 0.81 when it has only received the user request and the agent has not yet taken any action, above the decision threshold (Appendix D, Table 9b).
What are some points that can be further explored?
The authors note that streaming detection requires action-level evaluation and closed-loop calibration, and that benchmarks covering both risk types need to be constructed; the experiments cover 6 offline benchmarks and 2 model families.
Limitations and future directions noted by the authors
- Training data construction for two types of risk: In Future Work, the authors note that unsafe tool use and harmful content are nearly orthogonal in internal representations, so covering one does not imply covering the other, and unsafe tool use performs relatively worse across all evaluated systems; future work needs to deliberately construct trajectory safety corpora that cover both forms of risk under consistent labels (Section 5.3).
- Red-teaming attack and defense exploration for agent trajectories: In Future Work, the authors note that agent trajectories provide attackers with a larger attack surface than single-turn text through injected tool results, long contexts, and tool call formats, so red-team attacks on agent trajectories and corresponding defenses are an independent future research direction (Section 5.3).
- Trade-off between streaming detection and prefix false rejection: In Appendix D, the authors note that fixed-threshold monitoring may cross the threshold prematurely when the agent has only received a user request and has not yet taken any action (e.g., the case in Table 9b), but similar representations also appear in trajectories that are ultimately rejected and labeled safe, so the challenge lies in avoiding prematurely intercepting agents that might have made a correct refusal (Appendix D).
- Prefix-level calibration and closed-loop evaluation: In Appendix D, the authors note that all 6 benchmarks evaluated in this study are labeled at the whole-trajectory level and do not support streaming calibration and closed-loop intervention evaluation at action boundaries; true streaming detection requires per-step labels, interfaces for intervening before candidate actions are executed, trigger rules, and quantitative evaluation of the impact of intervention on task utility, and the authors leave prefix calibration and closed-loop evaluation as future work (Appendix D).
Experimental coverage
- Benchmarks and trajectory types: The evaluation covers 6 public trajectory safety benchmarks (R-Judge, TraceSafe, ATBench, ASSEBench, OpenAgentSafety, AgentDojo), totaling 9,487 offline labeled trajectories (Table 4).
- Model family coverage: Backbone models cover two open-source model families, Qwen3-4B and Llama-3.1-8B, and the evaluated Guard baselines include Qwen3Guard-4B, LlamaGuard3-8B, and AgentDoG-4B (Section 4.2).
- Evaluation protocol and task forms: Experiments test offline pairwise comparison (pairwise ranking accuracy) and offline whole-trajectory classification (macro-F1), with a maximum truncation length of 16,384 tokens (Section 3.1, Appendix B.2, B.3).
- Excluded evaluation objects: The paper explicitly states that general-purpose LLM judges were not included as Guard baselines, because their prompts, scoring rules, and inference budgets significantly affect cost and performance, making them unable to constitute a controlled comparison against dedicated local Guard outputs (Appendix B.2).
- Unreported information: The paper does not report the impact of real-time online interception of actions on agents' normal task completion rate (task utility) in actual deployment environments, nor does it report human review consistency metrics for each benchmark.
Summarize the main content of the paper
Propose TACIT, an internal-representation-based safety detection method for agent trajectories, revealing the characteristics of tool risk representations and improving detection performance and efficiency across multiple benchmarks.
- Research positioning: This study addresses the challenge of trajectory safety detection for tool-calling agents. Starting from representation analysis, it systematically explores the internal mechanisms and output failure phenomena of Guard models in identifying "unsafe tool use," and accordingly designs TACIT, a safety detection method based on reading internal representations.
- Core problem: Existing open-source Guard models are mainly designed for single-turn text content moderation, whereas in multi-step agent trajectories, unsafe behavior often depends on mismatches between actions and context/tool patterns; such unsafe tool calls are difficult to distinguish effectively at the output end of existing Guard models (Section 1, 3.1).
- Method highlights: Through controlled experiments, it was found that unsafe tool use and harmful content are linearly readable in intermediate hidden layers and nearly orthogonal in geometric direction; TACIT uses a single forward pass of a frozen backbone network to extract and pool representations from each layer, and trains lightweight linear probes on intermediate layers, or uses ensemble or multi-layer salient feature aggregation classifiers to output safety scores, without updating backbone parameters and with no autoregressive decoding at all (Section 3, 4.1).
- Core experimental results:
- Across 6 mainstream trajectory safety benchmarks, TACIT Multi-layer on a Qwen3-4B backbone achieved an average macro-F1 of 86.2%, substantially surpassing the dedicated AgentDoG-4B (62.3%) and content Guard baselines (Table 1).
- In leave-one-out generalization tests that completely excluded the target benchmark, the Multi-layer variant on Qwen3-4B achieved an average macro-F1 of 65.7%, still leading the baselines (Table 2).
- Under the same data and backbone controls, frozen representation reading performed on par with full parameter fine-tuning (84.2%), and adding Multi-layer reading on top of the fine-tuned model further improved it to 86.5% (Table 6).
- TACIT's linear probe training involves only 5,121 parameters, and per-trajectory detection takes only 40ms, an 82% latency reduction compared to Qwen3Guard (215ms) (Figure 4).
- Implications and conclusions: The authors state that internal representations provide a practical foundation for detecting harm in agent trajectories; future work needs to build dedicated benchmarks that systematically cover the two orthogonal risk types of tool use and harmful content, and to explore streaming intervention mechanisms at action boundaries in depth (Section 5.3, 6).