DataShield: identifying high-risk data in LLM fine-tuning through consensus subspace alignmentDataShield: Uncovering Risky Fine-Tuning Data Across LLMs Through Consensus Subspace Alignment
DataShield evaluates fine-tuning data risk using multi-model consensus safe/unsafe subspaces; sample filtering and segment masking have average ASR 14.6% and 32.3% lower than SOTA baselines, respectively.
Safety-preserving filtering at the data center: estimate the safety degradation risk of training samples or response segments before fine-tuning. The filter has access to the task dataset Dtask and a safety-aligned source model; the target model does not participate in risk estimation. The risk measure must transfer across model families, scales, and tokenizers.
- Even fine-tuning on benign task data can weaken the safety capabilities of aligned LLMs. Existing filtering mostly relies on a single model's mean vector or a specific tokenizer, making risk estimates difficult to transfer across models.
- DataShield obtains consensus safe and unsafe subspaces from safety-critical representations of multiple safety-aligned source models via semantic spectral decomposition, measures sample and segment risk with relative alignment, and then performs sample deletion or tokenizer-independent segment loss masking.
- When fine-tuning four unseen target models on Alpaca and Dolly, the authors report that sample filtering and segment masking reduce average ASR by 14.6% and 32.3% respectively relative to SOTA baselines, with SLIMORCA utility close to standard SFT.
- The authors note that the experiments are limited to supervised fine-tuning, representative instruction-tuned models, two downstream datasets, and common safety benchmarks; future work could examine more model families, multilingual data, specialized downstream tasks, and domains such as law, medicine, and finance.
- Evaluated models
- Phi3-medium-4k-itQwen3-4B-itGemma2-27B-itGemma3-12B-it
- Benchmarks
- AlpacaDollyHEx-PHIHarmBenchSLIMORCA
- Metrics
- ASRPHIHARMSLMPeak Total Mem.Time
DataShield is a data evaluation framework that identifies risky fine-tuning samples and response segments through consensus subspace alignment in a joint safety-critical semantic space built from multiple safety-aligned LLMs. The framework extracts consensus safe and unsafe subspaces via semantic spectral decomposition within these spaces, then estimates risk by measuring the relative alignment of samples or segments with the unsafe and safe subspaces, enabling sample-level filtering and fine-grained segment-level masking. Compared with existing filtering and masking baselines, DataShield reduces ASR by 14.6% under sample filtering and 32.3% under segment masking, while maintaining downstream utility and avoiding risk computation for specific target models.
Paper analysis
What problem does this paper attempt to solve?
Benign fine-tuning can weaken safety alignment, and existing risk estimates do not transfer well across models and tokenizers.
How to identify and handle fine-tuning data that can weaken safety capabilities while improving the downstream utility of aligned LLMs.
- Scenario: The authors state that domain-data fine-tuning is now a routine practice for adapting LLMs, but safety alignment is fragile and may degrade or even completely fail after downstream task adaptation (Wei et al., 2023; Qi et al., 2024; Huang et al., 2024, 2025a). Even fine-tuning on normal task data can increase a model's compliance with harmful requests (Qi et al., 2024; He et al., 2024; Guan et al., 2025; Hsiung et al., 2025).
- Limitations of existing methods: The authors point to three types of limitations. First, risk estimation is usually tied to a single model: the same cybersecurity sample may be judged low-risk on Llama, yet after fine-tuning increase compliance with harmful requests in models such as Qwen. Second, most methods use a single mean vector of a model's hidden states or gradients to represent the safety direction, whereas safety semantics may span multiple hidden directions or subspaces. Third, token-level methods tie unsafe regions to the reference model's tokenizer; the same semantic span has different token boundaries across models, so masks are hard to reuse (Li et al., 2026).
- Core observation: The authors argue that constructing consensus safe and unsafe subspaces from multiple safety-aligned LLMs with different architectures characterizes fine-tuning data risk better than a single prototype vector and improves cross-model transferability; splitting responses into tokenizer-independent text segments and then performing autoregressive risk disentanglement can localize high-risk spans.
- Proposed in this paper: DataShield, a data evaluation framework. It performs semantic spectral decomposition in the joint safety-critical semantic space of multiple safety-aligned LLMs, extracts consensus safe and unsafe subspaces, estimates sample or segment risk using relative alignment, supports sample-level filtering (DataShield-Sp) and fine-grained segment-level masking (DataShield-Sm), and the risk computation does not use the target model.
- Threat model:
- Goal: Estimate the safety degradation risk of training units (whole samples zi or response segments ci,j) before fine-tuning, removing or masking parts that may weaken safety while preserving useful supervision needed for downstream adaptation.
- Knowledge and input: The filter has access to the task dataset Dtask and a set of safety-aligned source models Msrc; the target model Mtgt is not involved in risk estimation.
- Capability: After ranking by risk, delete high-risk samples under an intervention budget ρ, or mask target-model tokens overlapping with high-risk original-text segments in the SFT loss; the text sequence itself remains unchanged.
- Victim system: Instruction-tuned LLMs that will be supervised fine-tuned on downstream data such as Alpaca and Dolly. The authors require the risk measure to be reusable across different architectures, scales, safety behaviors, and tokenizers, rather than only reflecting the checking model's own representation geometry or tokenization boundaries.
What related research exists?
Related work focuses on safety degradation from benign fine-tuning and on sample-level and token-level data filtering.
Safety degradation and data-centric mitigation
- Alignment fragility: Ouyang et al. (2022), Bai et al. (2022), and Bianchi et al. (2024) discuss safety alignment of recent LLMs; Wei et al. (2023), Qi et al. (2024), and Huang et al. (2024, 2025a) discuss alignment degradation or failure after downstream adaptation. Qi et al. (2024), He et al. (2024), Guan et al. (2025), and Hsiung et al. (2025) report that fine-tuning on normal or benign task data can also increase compliance with harmful requests. Guan et al. (2025) and Hsiung et al. (2025) argue that a small portion of fine-tuning data can cause severe safety degradation.
- Training-time mitigation: Hsu et al. (2024), Li et al. (2025b), and Choi et al. (2024) mitigate safety degradation through safety-aware fine-tuning; Choi et al. (2024), He et al. (2024), Li et al. (2025a), Shen et al. (2025), and Wang et al. (2026) adopt data-centric filtering.
Sample-level risk estimation
- Bi-Anchoring (He et al., 2024): Uses representations and gradients to identify risky data.
- LARF (Li et al., 2025a): Scores training data using hidden states of safety-related layers; its layer sensitivity method is also used in this paper to select safety-critical layers.
- SEAL (Shen et al., 2025): Trains a safety classifier to estimate degradation risk, but requires target-model logits, which the authors argue adds cost and depends on the target model. SOT (Wang et al., 2026): Learns sample weights by aligning downstream data with safety references and separating them from harmful data. The authors argue these methods rely on model-specific signals or scoring models, limiting cross-architecture transfer.
Fine-grained masking and representation differences
- TOSS (Li et al., 2026): Masks unsafe content at the token level, improving granularity, but its masks depend on the reference model's tokenizer. The authors argue that different tokenizers segment the same text differently (citing Erdogan et al., 2026; Haslett, 2025; Phan et al., 2025; Dao et al., 2026), so masks may not transfer reliably.
- Representations are not directly comparable: Kornblith et al. (2019) and Bostrom and Durrett (2020) are used to show that a single model's hidden states, gradients, losses, logits, or token boundaries only reflect the checking model itself, and do not equal the safety risk carried by the data. Chung et al. (2024) and Longpre et al. (2023) are used to show that fine-tuning datasets are often reused across LLMs with different architectures and tokenizers.
Baseline methods and benchmarks
- Baselines: Standard SFT; sample-level Random-Sp, Bi-Anchor, SEAL, LARF, SOT; fine-grained Random-Sm, TOSS. Default intervention budget ρ=0.2.
- Data: Alpaca (Taori et al., 2023) and Dolly (Conover et al., 2023) for downstream fine-tuning; HEx-PHI (Qi et al., 2024) and HarmBench (Mazeika et al., 2024) for safety evaluation; SLIMORCA (Lian et al., 2023) test-subset win rate for utility. Probing of safety-critical subspaces follows the pairwise probing setup of Li et al. (2025a).
The authors position DataShield as: estimating risk using safety-related subspaces of multiple safety-aligned models and masking unsafe content at transferable segment level, to address both model-specific estimation and tokenizer binding limitations.
How does the paper address this problem?
Multi-source model consensus subspace alignment, estimating sample and segment risk before filtering or masking.
DataShield builds safe and unsafe subspaces from multiple safety-aligned source models, compares the alignment of data with the two types of subspaces using cross-model consensus, and then deletes high-risk samples or masks high-risk response segments according to a budget.
Problem setup
- Training units: Sample z=(x, y), where x is the instruction and y is the response; Dtask is the downstream fine-tuning set. A training unit can be a whole zi or a response segment ci,j within yi.
- Transferability: Source models Msrc are used to estimate risk; the target model Mtgt is not involved in risk estimation. The filtered data should remain safe across different model versions and model families.
- Two types of intervention: Sample deletion yields a remaining set for fine-tuning; segment loss masking keeps the text unchanged and only excludes target-model tokens overlapping with selected original-text segments from the SFT loss.
Consensus safe and unsafe subspaces
- Safety-critical layers: For each source model, use the weight perturbation method of Li et al. (2025a,c): symmetrically scale each layer's weights, measure changes in refusal tendency on a common probe set, rank by perturbation sensitivity, and take the top Ncrit layers as Lcrit. Main experiments use Ncrit=3; details are in Appendix A.1.
- Compact representation: Combine the representations of selected layers into h̃^(k)(z)∈R^{Dk}. The source model spaces are not forced to align to the same embedding space; consensus comes from computing alignment scores within each space and then aggregating across models. Construction details are in Appendix A.3.
- Spectral decomposition: Following pairwise probing (Li et al., 2025a): each harmful instruction is paired with an unsafe completion and a safe response, yielding Dunsafe and Dsafe. For behavior a∈{safe, unsafe}, take the compact representation set Ha^(k) of the last token and construct
Sa(k)=1/(|Ha|)∑ h̃h̃⊤ then perform semantic spectral decomposition, with eigenvalues sorted in descending order, keeping one safe basis and one unsafe basis per source model. Main experiments keep d=16 principal components per subspace.
Subspace alignment risk
- Alignment measure: For a nonzero representation, ϕ(h̃, U)=‖UU^⊤ h̃‖₂² / ‖h̃‖₂², taking values in [0,1], representing the normalized squared length of the projection onto the subspace spanned by U.
- Sample risk: Use the last-token compact hidden state as the sequence representation. For each source model, the sample alignment gap is the ϕ with the unsafe subspace minus the ϕ with the safe subspace, taking values in [−1,1]. The consensus risk is the average of the gaps over the K source models; larger values indicate higher safety degradation risk.
- Segment risk: The instruction remains unchanged; before tokenization, the response is split into character spans by sentence boundaries, punctuation, newlines, and whitespace, independent of any specific tokenizer. Each source model maps the same span to its own set of token indices. The alignment gap at position t is q_t; because autoregressive hidden states contain preceding context, direct pooling would carry early risk into later benign positions. The increment is defined as Δq_t = (1/2)(q_t − q_{t−1}), with q_0=0; the coefficient 1/2 keeps the increment in [−1,1]. The segment score takes the maximum increment within the segment, then averages over the K source models; the maximum is used because short risky spans are diluted by neighboring benign text. Segment construction and token mapping are in Appendix A.5.
Safety-preserving fine-tuning and success criteria
- Budget: Default ρ=0.2, i.e., delete the global top 20% of samples by risk, or apply loss masking of the same proportion to response segments.
- Loss: Lsm computes the next-token negative log-likelihood only at unmasked token positions Ki. The target model is fine-tuned with LoRA.
- Two variants: DataShield-Sp deletes high-risk samples; DataShield-Sm masks high-risk response segments. Source models are Llama3-8B-Instruct, Qwen2.5-7B-Instruct, and Mistral-7B-Instruct-v0.3.
- Success criteria: Safety is measured by ASR on HEx-PHI and HarmBench, scored by GPT-4o following Zeng et al. (2024); utility is measured by SLIMORCA win rate (SLM). In Table 1, lower PHI and HARM are better, and higher SLM is better.
What experiments did the paper conduct?
On four unseen target models, filtering and masking reduce ASR, with utility close to full SFT.
Experimental setup
- Source models: Llama3-8B-Instruct, Qwen2.5-7B-Instruct, Mistral-7B-Instruct-v0.3. The consensus ablation additionally includes Gemma2-9B-it. Risk estimation does not use the target model.
- Target models: Phi3-medium-4k-it, Qwen3-4B-it, Gemma2-27B-it, Gemma3-12B-it, all unseen instruction-tuned models, fine-tuned with LoRA.
- Data: Alpaca and Dolly for domain adaptation; HEx-PHI and HarmBench for safety evaluation; SLIMORCA test-subset win rate for utility. The paper does not give the number of samples in these sets in the main text; the preprocessing cost experiment states about 14K Dolly samples.
- Baselines: Sample-level Random-Sp, SEAL, Bi-Anchor, LARF, SOT; segment/token-level Random-Sm, TOSS; plus Standard SFT. Default ρ=0.2, Ncrit=3, d=16.
- Metrics and evaluation: PHI and HARM are ASR on the two safety benchmarks (lower is better), scored by GPT-4o; Appendix D.1 additionally uses Gemini-3.1-Pro as an alternative judge. SLM is the SLIMORCA win rate (higher is better). The paper states results are averaged over multiple random seeds, without giving the number of repetitions.
- Table 2 setup: Baselines are allowed to use target-model information to compute risk, while DataShield still uses only source models; the data is Dolly, with the same budget and fine-tuning protocol. Table 1 is cross-architecture transfer, with baselines filtering under their existing works' default settings.
Main results
Table 1 (Alpaca and Dolly, four unseen target models; ↓ after is the change relative to Standard SFT):
Swipe horizontally to read the table
Method (Alpaca) Phi3 PHI/HARM/SLM Qwen3 PHI/HARM/SLM Gemma2 PHI/HARM/SLM Gemma3 PHI/HARM/SLM Standard SFT 62.0 / 76.0 / 68.2 32.1 / 39.0 / 65.4 44.1 / 51.3 / 72.5 24.2 / 31.1 / 69.8 SOT 25.1 / 32.8 / 66.0 17.5 / 24.8 / 63.3 21.6 / 29.2 / 70.3 12.5 / 18.1 / 67.8 DataShield-Sp 17.2 / 23.5 / 67.8 11.4 / 14.7 / 64.9 16.1 / 23.8 / 72.1 8.8 / 11.5 / 69.4 TOSS 39.5 / 47.1 / 65.5 38.2 / 46.1 / 62.5 44.2 / 52.1 / 69.5 33.6 / 40.8 / 66.8 DataShield-Sm 11.2 / 17.1 / 67.3 10.1 / 16.2 / 64.4 14.1 / 23.1 / 71.6 8.4 / 12.6 / 68.9 On Dolly, DataShield-Sp PHI/HARM/SLM: Phi3 19.1/25.2/66.1, Qwen3 7.6/16.1/63.4, Gemma2 10.2/18.6/70.4, Gemma3 5.5/11.6/67.7. DataShield-Sm: Phi3 12.1/18.6/65.5, Qwen3 6.5/22.6/62.8, Gemma2 13.1/27.6/69.8, Gemma3 6.4/18.1/67.1. The remaining baselines in the table are in Table 1.
- Authors' interpretation: Standard SFT shows safety degradation on both datasets. The authors state the average ASR of DataShield-Sp and DataShield-Sm is 15.1% and 14.9%, respectively, SOT 23.7%, and TOSS 43.8%. The abstract and contributions list state that, relative to SOTA filtering and masking baselines, sample filtering reduces ASR by 14.6% and segment masking by 32.3%.
- Utility: The authors state average SLM drops from 68.1% for Standard SFT to 67.7% for DataShield-Sp and 67.2% for DataShield-Sm. The Table 1 note states Standard SFT utility is slightly better because it uses the full training set. On Alpaca, TOSS for Qwen3 (PHI 38.2%, HARM 46.1%) is higher than that model's Standard SFT (32.1%, 39.0%); on Dolly, TOSS for Qwen3 is also higher than Standard SFT.
- Target-model information comparison (Table 2, Dolly): Baselines can use the target model to compute risk. DataShield-Sp HARM: Qwen3 16.1%, Phi3 25.2%, Gemma2-27B-it 18.6%, Gemma3-12B-it 11.6%; SOT in the same column is 23.5%, 25.7%, 28.0%, 20.4%. DataShield-Sm reduces HARM on Phi3 from TOSS's 29.8% to 18.6%. On Qwen3, DataShield-Sm HARM is 22.6%, lower than TOSS's 30.2%, but higher than DataShield-Sp's 16.1% for the same model.
Preprocessing cost
- What was measured: Peak total memory and time on about 14K Dolly samples, before fine-tuning Gemma2-27B-it, on an NVIDIA RTX PRO 6000 96GB GPU (Table 3).
- Results: DataShield-Sp is 47.9 GB, 64 min; DataShield-Sm is 58.1 GB, 118 min. For comparison: Bi-Anchor 168 GB / 503 min, SEAL 291 GB / 835 min, LARF 65 GB / 133 min, TOSS 242 GB / 675 min.
- Authors' interpretation: The authors attribute the lower cost to using only forward passes of source-model representations and subspace alignment scoring, without computing gradients, logits, or losses on the 27B target model.
Autoregressive risk disentanglement
- Figure 2(a): The authors state they compare cumulative risk and disentangled increments on one response. The cumulative score remains high after the harmful token "bomb"; the increment score peaks near that token and gives lower scores to subsequent benign tokens. The y-axis is Risk score, roughly from −0.2 to 1.0, the legend includes absolute st and relative Δst, and the x-axis labels include "A", "pipe bomb", "is", "a", "weapon".
- Figure 2(b)(c): The authors state that disentangled masking, relative to cumulative-score masking, reduces HarmBench ASR from 14.1% to 9.4% and HEx-PHI ASR from 11.9% to 7.7%. The x-axis is Phi3, Gemma2, Qwen3, Gemma3, the y-axis is ASR (%), and the legend includes Random, Absolute, AR decoupling. The paper does not list the values of these three bar groups per model.
Other ablations and analyses
- Number of source models K (Figure 3): Gemma2-9B-it is added as a fourth source model; each K averages over multiple source-model combinations. The authors state more source models generally reduce ASR, with diminishing returns after K=3; on HEx-PHI, increasing K from 3 to 4 reduces average ASR from 13.38% to 13.08%, so the main experiments use K=3.
- Subspace dimension d (Figure 4): With fixed source models, ρ, and scoring rule, the x-axis is 1, 8, 16, 64, 128, 512, split into Alpaca and Dolly. The authors state ASR first decreases then increases, with d=16 giving the best trade-off among the tested values; the figure does not give exact ASR for each point.
- Subspace construction (Table 4): Unsafe-only, Safe-only, Mean-gap, Subspace-gap. Sample-level HEx-PHI: Subspace-gap is 7.6% on Qwen3-4B-it (Mean-gap 19.3%), 19.1% on Phi3 (Mean-gap 28.1%), and 5.5% on Gemma-3-12B-it (Mean-gap 18.1%). Segment-level Subspace-gap PHI/HARM: Qwen3 6.5/22.6, Phi3 12.1/18.6, Gemma-3 6.4/18.1. Unsafe-only and Safe-only are both higher than Subspace-gap in the table.
- Appendices: E.2 gives additional source-model transfer and selection bias analysis; E.4 gives task-specific utility; D.1 gives the GPT-4o scoring rubric and the Gemini-3.1-Pro alternative judge. The main text does not list specific numbers from these appendices. E.12 and E.13 give sample-level and segment-level qualitative examples, with content selected as high-risk marked in red.
What are some points that can be further explored?
The authors plan to extend to more model families, multilingual data, specialized tasks, and domain-specific safety scenarios.
Limitations and Future Directions Noted by the Authors
- Evaluation scope (Section 7 Limitations): This paper studies safety preservation in supervised fine-tuning, using representative instruction-tuned LLMs, two downstream fine-tuning datasets, and common safety benchmarks. The authors state that these settings cover the main transfer scenario considered in this paper, namely reusing processed data across different target models.
- Broader conditions (Section 7): Future work could examine DataShield under broader conditions, including more model families, multilingual data, and specialized downstream tasks.
- Domain safety (Section 7): Evaluation could also be conducted in domain-specific safety settings, such as legal, medical, and financial applications; the authors state that unsafe behavior patterns in these scenarios may differ from those covered by general harmful-request benchmarks.
Experimental Coverage
- Models: Safety subspaces come from three source models: Llama3-8B-Instruct, Qwen2.5-7B-Instruct, and Mistral-7B-Instruct-v0.3; transfer targets are Phi3-medium-4k-it, Qwen3-4B-it, Gemma2-27B-it, and Gemma3-12B-it. The consensus ablation additionally uses Gemma2-9B-it as a fourth source model, with K from 1 to 4 (Figure 3, Section 5.3).
- Data and interventions: Downstream fine-tuning data are Alpaca and Dolly; safety metrics are ASR on HEx-PHI and HarmBench, and utility is SLIMORCA win rate. Default ρ=0.2, Ncrit=3, d=16; the scan for d uses values 1, 8, 16, 64, 128, 512 (Figure 4).
- Comparisons: In Table 1, baselines are filtered with their existing default settings; Table 2 allows Bi-Anchor, SEAL, LARF, SOT, and TOSS to use target model information, with data from Dolly. Costs are measured on about 14K Dolly samples before fine-tuning Gemma2-27B-it (Table 3).
- Evaluation and repetition: Main ASR is scored by GPT-4o; D.1 additionally reports Gemini-3.1-Pro. The main text states results are averaged over multiple random seeds, but does not report the number of repetitions or agreement with human judgment.
- Appendix analyses: E.2 covers source model transfer and selection bias, E.4 covers task-specific utility, and E.12 and E.13 provide qualitative examples at the sample and segment levels. The paper does not report numerical values for these appendix experiments in the main text.
Summarize the main content of the paper
DataShield uses multi-model subspace consensus to filter or mask risky fine-tuning data and reduces ASR on unseen models.
DataShield is a data-centric framework for supervised fine-tuning that estimates the safety degradation risk of fine-tuning data without using the target model.
- Problem: Aligned LLMs fine-tuned on task data such as Alpaca and Dolly may become more compliant with harmful requests. Existing filtering often relies on mean vectors, gradients, logits from a single model, or token boundaries from a single tokenizer, making estimates difficult to reuse across architectures.
- Method: On three safety-aligned source models (Llama3-8B-Instruct, Qwen2.5-7B-Instruct, Mistral-7B-Instruct-v0.3), weight perturbation selects the top 3 safety-critical layers, spectral decomposition is applied to paired safe/unsafe probe representations, and 16 principal directions are retained per behavior. Sample risk is the alignment with the unsafe subspace minus alignment with the safe subspace, averaged over source models. Responses are split into character segments before tokenization, and the maximum within-segment autoregressive increment localizes added risk. By default, the top 20% highest-risk samples are removed or masked.
- Main results: On four unseen target models, the authors report that relative to SOTA baselines, sample filtering reduces average ASR by 14.6% and segment masking by 32.3%. The authors report average ASR for DataShield-Sp and DataShield-Sm as 15.1% and 14.9%, compared to 23.7% for SOT and 43.8% for TOSS. After fine-tuning on Alpaca, Phi3-medium-4k-it's HARM ASR drops from 76.0% with Standard SFT to 17.1% with DataShield-Sm (Table 1). Average SLIMORCA win rate goes from 68.1% to 67.7% (Sp) and 67.2% (Sm).
- Comparisons and ablations: Even when baselines can use target model information, DataShield achieves lower ASR on Dolly (Table 2). On about 14K Dolly samples, DataShield-Sp uses 47.9 GB and 64 min, lower than the baselines in the table (Table 3). Decoupled masking versus cumulative score masking improves HarmBench ASR from 14.1% to 9.4% and HEx-PHI from 11.9% to 7.7%. Subspace gap outperforms one-sided scores and mean prototype gap (Table 4); d=16 and K=3 are used in the main experiments.
- Authors' conclusion: The authors believe consensus subspace alignment provides a reusable safety-preservation signal, and sample filtering with tokenizer-agnostic segment masking can reduce attack success rates on diverse target LLMs while largely maintaining downstream utility. Limitations are noted for supervised fine-tuning, two downstream datasets, and general harmful-request benchmarks; future work could extend to more model families, multilingual data, specialized tasks, and legal, medical, and financial scenarios.
Related papers
- Unintended Harms of Value-Aligned LLMs: Psychological and Empirical InsightsAnalysis / interpretabilityACL 2025
Show 3 more papers
- Large Language Models Generate Harmful Responses Using a Distinct Mechanism, Shared Across Harm TypesAnalysis / interpretabilityarXiv