TRACE: Temporal Risk Assessment and Concept Editing for Safer Language GenerationTRACE: Temporal Risk Assessment and Concept Editing for Safer Language Generation
TRACE performs streaming detection and selective steering with discrete concepts on three 8B generators; the authors report streaming F1 higher than Kelp in five of six settings.
The safeguard reads residual-stream activations of the frozen generator (the appendix states white-box access is needed), assigns tokens to concepts, predicts monotonically cumulative risk, and applies norm-preserving edits only to harmful concepts. The initial prompt is unchanged, and steering does not wait for the detection threshold. The target is responses from three 8B instruction models on WildGuard and S-Eval. The paper does not define an external attacker.
- When streaming output, waiting for the full response to review may already have released harmful details; overly strong restrictions can refuse legitimate requests that merely mention sensitive topics. The authors want to distinguish harmful assistance from safe discussion during generation and leave an inspectable record of internal patterns.
- TRACE learns a codebook on a frozen generator using cross-layer vector quantization. Each step assigns activations to the nearest concept, and a GRU combines activation and concept features to predict completed-response harmfulness and a cumulative risk that only rises. Only harmful concepts are rotated with norm preservation toward the mean of a neighboring benign concept. An external LLM names concepts after the fact, used only for reading records.
- On three 8B models and WildGuard, S-Eval, the authors state that in five of six groups streaming F1 is higher than layer-matched Kelp. Steering reduces HarmBench ASR, and safe response refusal rate is close to unsteered. On Qwen/WildGuard, 53.0% of sufficiently supported concepts get consistent names.
- The authors note that internal activations are required, evaluations are on three 8B models and two English benchmarks, concept names do not establish causality, steering may reduce fluency or increase repetition, and ASR reduction may not come from steering toward benign behavior. Experiments cover six generator–dataset combinations and the listed detection/steering baselines; concept auditing is on Qwen/WildGuard.
- Evaluated models
- Qwen3-8BLlama-3.1-8B-InstructInternLM3-8B-Instruct
- Benchmarks
- StreamGuardBenchWildGuardS-EvalHarmBench
- Metrics
- harmful-class F1FPRAUROCAPHarmBench ASRrefusal rate
The TRACE framework tracks harmful response risk during generation, selectively edits token activations, and preserves auditable records. It uses an activation pattern codebook and GRU to predict response harmfulness and streaming cumulative risk, redirecting harmful concept activations toward nearby benign targets when steering. Across three generation models and WildGuard and S-Eval, its streaming F1 outperforms Kelp in five of six comparisons, and it reduces HarmBench attack success rate with minimal change in safe response refusal rate.
Paper analysis
What problem does this paper attempt to solve?
TRACE uses shared discrete concepts to connect streaming detection, selective activation editing, and post-hoc audit.
The safeguard needs to identify harmful assistance during generation, modify safe responses minimally when intervening, and leave an auditable record of internal patterns.
- Scenario: the authors state that models may still write harmful instructions after refusal training; when responses are streamed directly to users, waiting for the full response to check may already have released harmful details. Overly strong restrictions can refuse legitimate requests for mentioning sensitive topics.
- Existing shortcomings: Llama Guard and WildGuard classify full prompts and responses; Kelp and others monitor hidden states during generation. The authors state that when safe responses are mistakenly blocked or accidentally rewritten, scores and outputs do not reveal which activation patterns were present or which patterns the edits targeted.
- Observation: the authors build on cross-layer codebooks, treating recurring activation patterns as concepts, with token assignments yielding sequences comparable across responses; after associating with harmful/safe training responses, they distinguish patterns that may need editing from benign concepts that can serve as targets.
- Approach: propose TRACE, using the same codebook to connect causal detection, concept-conditioned activation editing, and post-hoc recording. An external LLM names concepts only after training; naming does not participate in decisions.
- Threat model
- Goal: distinguish harmful assistance from safe discussion of sensitive topics during generation, and intervene in harmful generation while minimally changing refusal of originally safe responses.
- Knowledge: reads residual-stream activations at selected layers. Appendix F.1.4 states that cross-generator experiments still require white-box access to the target generator. The paper does not describe the safeguard as black-box or gray-box.
- Capability: assigns the current activation to a concept each step; only harmful concepts receive norm-preserving edits. The initial prompt is unchanged, and steering does not wait for the detector threshold.
- Target: generation on responses from Qwen3-8B, Llama-3.1-8B-Instruct, and InternLM3-8B-Instruct on WildGuard and S-Eval. The paper does not separately list an external attacker.
What related research exists?
Related work is divided into text moderation, streaming detection, activation intervention, and discrete concepts; the authors use the same codebook to connect detection, steering, and audit.
The paper divides related work into detection, in-generation intervention, discrete concepts, and auditing in the introduction and Section 5.
Harmfulness and Streaming Detection
- Llama Guard (Inan et al., 2023) and WildGuard (Han et al., 2024): text classification of safety risks in prompts and responses.
- Kelp (Li et al., 2025): models risk changes during generation using intermediate-layer hidden states; reads token-by-token, trains with response-level labels, and passes information along the sequence. The authors call this the closest comparison to the TRACE detector.
- AxBench's DiffMean (Wu et al., 2025), ShieldHead (Xuan et al., 2025), Shu et al. (2026), and NExT-Guard (Fang et al., 2026): use internal representations, token scores learned from sequence labels, or sparse autoencoder features without token-level supervision for detection. The authors state that AxBench marks difference-in-means as a strong baseline and adapts DiffMean for harmful response detection.
In-Generation Intervention
- Refusal direction (Arditi et al., 2024): adds a single direction to activations to elicit refusal.
- CAST (Lee et al., 2025) applies a behavior direction only when the prompt activation matches a condition vector; Self-Reminder (Xie et al., 2023) uses a prompt to remind responsible responding.
- SCAR (Härle et al., 2024) and Breaking Bad Tokens (Goyal et al., 2025): use sparse conditional autoencoder or sparse autoencoder decoded directions to detect and steer concepts like toxicity. The paper only describes these methods here without critiquing each one.
Discrete Concepts and Auditing
- VQ-VAE (Van Den Oord et al., 2017), VQLC (Yu et al., 2026), and CLVQ-VAE (Garg et al., 2026): learn discrete codes via vector quantization; CLVQ-VAE reconstructs higher-layer representations from lower-layer activations.
- Codebook Features (Tamkin et al., 2023): insert a VQ bottleneck into language models and fine-tune the transformer. The authors state that TRACE learns a codebook on a frozen generator, differing from this.
- Marks et al. (2025) use learned activation features for alignment auditing; Mousi et al. (2023) use language models to name clusters of context representations. The authors state they also label the codebook after training for semantic reading records.
Baselines and Benchmarks
- Detection baselines: WildGuard classifier, DiffMean adapted from AxBench, and Kelp; the latter two use the same model layer as TRACE.
- Steering baselines: Self-Reminder, refusal-direction activation addition, and CAST.
- Benchmarks: WildGuard and S-Eval subsets in StreamGuardBench; HarmBench ASR (Mazeika et al., 2024) for steering.
The authors position their work as: the detector reads hidden states token-by-token like Kelp, uses response-level labels, and passes information forward, but jointly predicts completed-response harmfulness and monotonically cumulative streaming risk, and associates each token with a discrete concept; the current concept determines whether to edit, and neighboring benign concepts define a harmful-to-benign direction; the same codebook supports detection, steering, and auditing.
How does the paper address this problem?
Learn a codebook on a frozen generator, GRU jointly predicts completed-response harmfulness and monotonically cumulative risk, and only edits harmful concept activations.
TRACE treats cross-layer discrete concepts as a shared representation for detection, steering, and auditing. The generator is frozen. Figure 1 is divided into representation learning, causal detection, and concept-conditioned editing.
Cross-Layer Discrete Concepts
Uses CLVQ-VAE: reconstructs activations of a later layer u from layer ℓ's residual-stream activations via a codebook. Encoder vectors are assigned to the nearest codeword,
ct=argminj|zt−ej|22
zt is a mixture of the original activation and its layer-normalized linear transformation, with mixture weight ρ restricted to (0, 0.5). ct is the concept for token t. The causal decoder reconstructs later-layer activations using only assigned codewords, so concepts retain information needed to predict later layers.
The loss includes reconstruction, commitment (β=0.1), utilization (η=0.01), and region terms (γ=5). The region loss encourages harmful and safe responses to use different concept groups, with regrouping recomputed after each epoch. K=800. Training runs 100 epochs, AdamW, learning rate 3×10−4, seed 42. The checkpoint minimizes the average relative loss of reconstruction and region separation on the validation set relative to before training. Appendix C.1 gives full definitions.
The readout layer is selected on WildGuard training responses using a linear probe by five-fold accuracy, shared across datasets; the target layer is four blocks later. Readout/target pairs are Qwen 20/24, Llama 14/18, InternLM 34/38.
Concept Statistics
Concept harmfulness is estimated only from VQ training responses where the concept appears: each response counts once. Hc/Nc is smoothed to the overall harmfulness rate r with strength a=10, then mapped to sc∈[-1,1]. sc>0 indicates a harmful concept, otherwise benign; the authors call this an association with response labels. Detector means come from the detector training split, steering means from the VQ training split.
Causal Detection
Each step concatenates the current activation projection, concept mean projection, sct, and normalized response count. A one-directional one-layer GRU processes tokens. The response head predicts the completed response from the final state; the streaming head gives conditional harmfulness qt, accumulated as
Rt=1−∏i=1t(1−qi)
Rt does not decrease with new tokens, and generation can be stopped when it exceeds a threshold. Both heads use only response labels with class weights; there is no token-level onset annotation, and the authors state that exceeding the threshold cannot determine which token harmful content starts from. The search objective is the mean of both heads' validation F1, and the checkpoint is selected by the mean of both heads' validation AP. In the main table, TRACE and Kelp thresholds are 0.5. Widths, learning rates, etc., for each combination are in Appendix Table 4.
Concept-Conditioned Intervention
Each harmful concept is paired with the benign concept whose mean is nearest and appears in at least 10 VQ training responses. The direction is benign mean minus harmful mean. Edit magnitude is scaled by the concept's harmfulness score relative to the maximum positive score, then multiplied by strength λ. When assigned to a harmful concept, activations are rotated toward that direction by that proportion of the angle while preserving norm; benign concepts are not edited.
The initial prompt forward pass is unchanged, so the first generated token is not steered. Thereafter, reassignment happens each step, and the edit affects the next token. Steering looks directly at the current concept without waiting for the detector threshold. Default λ=0.5; whether to use 0.75 or 1 is decided by validation HarmBench ASR and four text quality constraints. Appendix C.4 gives the spherical interpolation formula.
Recording and Naming
Detection saves concept sequences and Rt; each edit saves the harmful source concept and benign target. After training, an external LLM names concepts based only on the response context before the concept appears; descriptions do not participate in detection or steering. The Qwen/WildGuard example in Figure 1 is annotated with threshold=0.605; main experiment thresholds are in question 4. Appendix E.4 gives the full naming prompt.
What experiments did the paper conduct?
The authors state that in five of the six groups, streaming F1 is higher than layer-matched Kelp; steering reduces HarmBench ASR, and the refusal rate change on safe responses is small.
Experimental Setup
- Generators: Qwen3-8B, Llama-3.1-8B-Instruct, InternLM3-8B-Instruct. Six generator–dataset combinations are trained and evaluated separately.
- Data: WildGuard and S-Eval subsets of StreamGuardBench, with response-level labels. Official test sets are not resampled. Safe/harmful counts: Qwen has 1,441/284 and 467/533, Llama has 1,519/206 and 547/453, InternLM has 1,486/239 and 615/385 (Table 3). Steering validation uses 200 safe and 200 harmful per setting.
- Baselines: Detection uses WildGuard 7B classifier, same-layer DiffMean, same-layer Kelp. Steering uses Self-Reminder, refusal-direction addition, CAST. Appendix H states that the Kelp paper and released code are inconsistent; the authors reproduce per the paper, so results may differ from the original paper.
- Metrics: Harmful-class F1, FPR, AUROC, AP. In streaming evaluation, any point above threshold counts as detection; first position is the proportion of the retained response length. Steering reports HarmBench ASR on originally harmful responses and refusal rate change on originally safe responses.
- Decision and decoding: TRACE and Kelp main tables use threshold 0.5; DiffMean uses the threshold with maximum F1 on the validation set. ASR uses HarmBench's Llama-2-13B classifier, candidates truncated to 512 classifier tokens. Refusal is matched case-insensitively using the phrase list from Arditi et al. (2024). Greedy decoding, max 2,048 tokens, thinking disabled when supported.
- Layers and audit: Figure 6 shows selected layer five-fold precision as 0.834, 0.840, 0.862; text gives 0.8343±0.0059, 0.8397±0.0099, 0.8624±0.0101. Concept audit uses only Gemini-3.1-Flash-Lite to label Qwen/WildGuard codebook.
Main Results
The table below takes streaming F1/FPR from Table 1, ASR and safe refusal from TRACE rows in Table 2; unsteered ASR takes the Unsteered row from the same table. Appendix H.2 states that matching controls may differ slightly across low-precision runs; TRACE row's pre-steering refusal rate is the same as that Unsteered row.
| Setting | TRACE streaming F1/FPR | Kelp streaming F1/FPR | TRACE ASR | Unsteered ASR | TRACE safe refusal (%) | | Qwen3-8B / WildGuard | 0.837/0.045 | 0.803/0.075 | 0.306 | 0.873 | 24.8→25.4 | | Qwen3-8B / S-Eval | 0.935/0.079 | 0.896/0.109 | 0.062 | 0.634 | 55.7→55.5 | | Llama-3.1-8B / WildGuard | 0.789/0.036 | 0.693/0.084 | 0.592 | 0.854 | 30.7→31.3 | | Llama-3.1-8B / S-Eval | 0.961/0.027 | 0.919/0.122 | 0.110 | 0.766 | 84.8→85.6 | | InternLM3-8B / WildGuard | 0.734/0.081 | 0.735/0.067 | 0.435 | 0.841 | 23.3→23.4 | | InternLM3-8B / S-Eval | 0.918/0.042 | 0.904/0.078 | 0.249 | 0.795 | 50.2→51.4 |
- The authors state that TRACE's streaming F1 is highest in five of six groups, and response F1 is highest in four groups. Exceptions are InternLM/WildGuard streaming F1, and Qwen/WildGuard and InternLM/WildGuard response F1 (Table 1: Kelp 0.839 vs 0.835, 0.749 vs 0.720). The authors state that TRACE's both F1s are higher than DiffMean. WildGuard classifier has no streaming output; its S-Eval response F1 is 0.093, 0.328, 0.136, and FPR is 0.000.
- The authors state that lowest ASR is not necessarily most selective. Refusal-direction addition has ASR 0.000 in all six settings, with post-steering safe refusal rates 92.7, 96.5, 97.3, 99.6, 99.9, 100.0 (Table 2). On S-Eval, TRACE's ASR is lower than Self-Reminder and CAST; on WildGuard it is not always lower, e.g., Qwen 0.306 vs Self-Reminder 0.289 and CAST 0.278, InternLM CAST 0.297.
- The authors state that TRACE reduces ASR in all six settings, and refusal rate on originally safe responses is close to unsteered. The authors also state that TRACE maintains comparable performance on completed-response detection.
Detection Position, Length, and Ranking Metrics
- Table 1 thresholds: The authors state that TRACE's FPR is lower than Kelp in five of six groups, but Kelp sometimes detects earlier. On InternLM/WildGuard, TRACE detects 87.0% of harmful responses vs Kelp's 82.4%; FPR is 8.1% vs 6.7%; median position is 17.0% vs 10.8% of the response. Figure 2 axes are median detection position (percentage of response) and FPR (%); text does not give curve endpoint values for other panels.
- Validation FPR at most 5%: In Figure 9, the authors state that TRACE has higher final recall in all six panels; median is earlier in three S-Eval and Llama/WildGuard. InternLM/WildGuard recall is similar, Kelp median 3.7%, TRACE 27.9%. On InternLM/S-Eval, TRACE recall 89.1% vs Kelp 84.9%, median 8.3% vs 13.7%.
- Length and AUROC: In Figure 10's 30 generator–dataset–length group comparisons, TRACE harmful recall is higher in 24 groups, tied in 2; safe FPR is equal or lower in 22 groups. The authors state that on both sides, S-Eval false positives mostly fall in the longest group. In Table 7, the authors state that TRACE has higher AUROC and AP than Kelp on two Llama datasets, Qwen/S-Eval, and InternLM/S-Eval; Qwen/WildGuard and InternLM/WildGuard have mixed leads.
Cross-Generator Corpus and Steering Quality
- Corpus transfer: Appendix Table 8 on S-Eval feeds other generators' response texts into frozen target model to extract activations, then retrains target-specific codebook and detector. The authors state that in six directions, TRACE's response and streaming F1 differ by at most 0.055 from same-generator training. In five directions, both are higher than Kelp; when training InternLM with Llama responses, Kelp's response F1 is higher by 0.006, TRACE's streaming F1 higher by 0.003.
- Quality constraints: Appendix Table 11. Two Qwen datasets and Llama/S-Eval pass all four validation constraints at selected strength; Llama/WildGuard, InternLM/WildGuard, InternLM/S-Eval each fail one: non-repetition 0.39, safe response quality failure 26/200, non-repetition 0.48 respectively. Selected λ is 0.75 for Qwen/WildGuard and Llama/S-Eval, 0.5 for others.
- Other steering variants: Table 12 on Qwen validation set shows selected norm-preserving update has lower ASR than listed direct addition strengths. Table 13 at λ=0.5 without harm weighting gives lower ASR (WildGuard 0.170 vs 0.410, S-Eval 0.020 vs 0.100), but non-repetition below 0.5, safe response failures 30/200 and 49/200. The authors therefore keep harm weighting.
Concept Audit
- Coverage: At least 25 training responses required for audit; three independent samples, each 25 responses, at most 512 preceding response tokens. Of 796 qualifying entries, 422 (53.0%) get at least two consistent names, 392 have majority safety labels: 32 harmful, 126 benign, 234 neutral, 30 with unclear safety meaning. Named concepts cover 46.4% of test set assignments.
- Detection trajectories: Threshold 0.5. In Table 5, true positives (n=251, traced to first detection) have harmful concepts average 5.95%, benign 1.01%; true negatives (n=1,376, full trace) have 0.23% and 26.60%. Proportion without consistent names is 75.75% in true positives, 41.65% in true negatives. The authors state that false positives often contain guidance, educational, or confabulation frameworks also present in harmful responses; false negatives have more benign and neutral concept segments than true positives.
- Edit records: In Qwen/WildGuard run with λ=0.75, 283 of 284 harmful responses are edited at least once; 1,081 of 1,441 safe responses are also edited, and 1,364 of 1,725 (79.1%) have at least one edit. Figure 4 by response count, most common named source is 165/283, most common named target is 233/283. 79 responses contain consistent harmful source plus consistent benign target, total five pairs (Table 6), most frequent pair appears in 30 responses. Figure 5 average edited token proportions across four intervals: 62.8%, 62.4%, 63.2%, 62.2%; Figure 8 for safe responses: 10.9%, 11.5%, 10.9%, 10.8%. The authors state that after intervention, refusal and redirection concepts appear from the first segment, but harmful concepts like cyberattack simulation remain common.
Other Ablations and Analyses
- Table 9 (Qwen3-8B, threshold 0.5): activation only vs activation+concept F1 differs by at most 0.007; concept only is lower. On WildGuard, region loss raises concept-only response/streaming F1 from 0.703/0.686 to 0.817/0.795.
- Table 9: codebook 800 has highest four F1s on WildGuard, 1,200 on S-Eval; mean activation is higher than learned codewords in all four comparisons.
- Table 10: with seeds 42–44 and reusing seed-42 VQ, Llama/WildGuard streaming F1 is 0.7777±0.0286, variance larger than other outputs in the table; that table does not estimate variance for independently trained VQ.
- Appendix F.1.4: when Kelp targets Llama, response F1 drops from 0.916 with same-generator responses to 0.605 when trained with InternLM responses.
- Appendix G: online detection 0.552±0.002 ms/token (H100, batch size 1); generation time with steering increases 3.02% over unsteered. The authors state that Kelp reports about 0.4 ms/token (H20), hardware differs, so speed comparison is not direct.
- Detector gradient parameters 19.00–19.48M, authors' Kelp implementation 19.93M; VQ training with decoder totals 604.03M parameters, decoder discarded at inference.
What are some points that can be further explored?
The authors note that internal activations are required, evaluations are on three 8B models and two English benchmarks, and concept names do not establish causation.
Limitations and Future Directions Noted by the Authors
- Requires reading model internal activations, making it difficult to use on closed models available only via API (Section 7).
- Evaluations are on three 8B instruction-tuned models and two English safety benchmarks; the authors believe performance may differ on larger models, other languages, and other forms of harmful content (Section 7).
- Concept names are assigned by an external LLM after training, describing recurring patterns; the authors state they cannot establish that a concept caused a particular prediction or edit (Section 7).
- Steering may reduce fluency or increase repetition; the authors believe some of the observed ASR reduction may come from degraded generation rather than steering toward benign behavior (Section 7).
The paper's Limitations section does not list additional experimental plans. The ethics statement describes TRACE as a component in a larger safety system and states that interventions could also be used for harmful purposes; this section does not frame these as experiments to be done.
Experimental Coverage
- Detection and steering are trained separately on six combinations of Qwen3-8B, Llama-3.1-8B-Instruct, InternLM3-8B-Instruct with WildGuard and S-Eval; main results are in Table 1 and Table 2.
- Detection baselines are WildGuard classifier, same-layer DiffMean, and Kelp; steering baselines are Self-Reminder, refusal-direction addition, and CAST (Section 3).
- Concept naming and trajectory auditing target the final Qwen/WildGuard codebook, with the labeling model being Gemini-3.1-Flash-Lite (Section 3, Appendix E).
- HarmBench ASR is judged by a Llama-2-13B classifier, with candidate generations truncated to 512 classifier tokens; decoding is greedy with a maximum of 2,048 tokens (Appendix D.2).
- Detector repetitions are seeds 42–44 and reuse the seed-42 VQ checkpoint; cross-generator corpus transfer is done only on S-Eval, and components are retrained for the target model (Appendix F.1.4, F.1.6).
Summarize the main content of the paper
TRACE uses the same codebook for streaming detection and selective steering, and leaves a concept record readable after the fact.
TRACE is a safeguard on a frozen generator: it uses the same set of discrete concepts for streaming risk detection, selective activation editing, and leaves a record readable after the fact.
- Problem: reviewing the full response may come after harmful details have already leaked; overly strong restrictions can refuse safe discussions of sensitive topics. The authors want to judge during generation, modify safe responses minimally when intervening, and preserve inspectable internal patterns.
- Method: cross-layer vector quantization learns 800 concepts from residual-stream activations. A GRU simultaneously predicts whether the completed response is harmful and a cumulative risk that only rises. Only activations assigned to harmful concepts are rotated with norm preservation toward the mean of a neighboring benign concept; steering does not wait for the detector threshold. An external LLM names concepts after the fact, not participating in decisions.
- Detection: in Table 1, the authors state streaming F1 is higher than same-layer Kelp in five of six groups. On InternLM/WildGuard, Kelp is 0.735 and TRACE is 0.734. On Qwen/WildGuard and InternLM/WildGuard, response F1 is also higher for Kelp. The authors state that threshold-independent metrics favor TRACE more on Llama and S-Eval, while the two WildGuard comparisons show mixed leads.
- Steering: in Table 2, TRACE's HarmBench ASR is 0.306 and 0.062 on Qwen, 0.592 and 0.110 on Llama, and 0.435 and 0.249 on InternLM. The authors state that refusal rates for originally safe responses are close to no intervention. Refusal-direction addition has ASR 0.000, but safe refusal rates rise to 92.7% to 100.0%. TRACE's ASR is not lower than Self-Reminder or CAST in every cell.
- Auditing and author conclusions: on Qwen/WildGuard, 422/796 sufficiently supported concepts receive consistent names (53.0%). The authors state that harmful detection, safe generation, and edit records show different semantic patterns, and keeping these records facilitates review when consequences are severe. The authors also believe concept names do not establish causality, and ASR reduction may also come from reduced fluency or increased repetition.