Protecting Language Models Against Unauthorized Distillation through Trace Rewriting
Summary
This paper proposes methods for protecting large language models against unauthorized knowledge distillation by rewriting reasoning traces to degrade training usefulness while preserving correctness, and embedding verifiable watermarks in distilled student models. The approach uses instruction-based and gradient-based rewriting techniques to achieve anti-distillation effects without compromising teacher model performance.
View Cached Full Text
Cached at: 04/20/26, 08:33 AM
# Protecting Language Models Against Unauthorized Distillation through Trace Rewriting
Source: https://arxiv.org/html/2602.15143
Xinhang Ma, William Yeoh, Ning Zhang, Yevgeniy Vorobeychik
Washington University in St. Louis
{m.owen, wyeoh, zhang.ning, yvorobeychik}@wustl.edu
## Abstract
Knowledge distillation is a widely adopted technique for transferring capabilities from LLMs to smaller, more efficient student models. However, unauthorized use of knowledge distillation takes unfair advantage of the considerable effort and cost put into developing frontier models. We investigate methods for modifying teacher-generated reasoning traces to achieve two objectives that deter unauthorized distillation: (1) *anti-distillation*, or degrading the training usefulness of query responses, and (2) *API watermarking*, which embeds verifiable signatures in student models. We introduce several approaches for dynamically rewriting a teacher's reasoning outputs while preserving answer correctness and semantic coherence. Two of these leverage the rewriting capabilities of LLMs, while others use gradient-based techniques. Our experiments show that a simple instruction-based rewriting approach achieves a strong anti-distillation effect while maintaining or even improving teacher performance. Furthermore, we show that our rewriting approach also enables embedding watermarks that can be reliably detected with essentially no false alarms. Our code is available at https://github.com/xhOwenMa/trace-rewriting.
## 1 Introduction
Knowledge distillation is a simple learning technique for transferring knowledge from one model (the *teacher*) to another (the *student*) Hinton et al. (2015). In its simplest form, distillation proceeds by querying a teacher model $\mathcal{T}$ with inputs $x$ to obtain responses $y=\mathcal{T}(x)$, then training a student model $\mathcal{S}$ on the resulting input-output pairs using supervised fine-tuning. Since its introduction, knowledge distillation has become a major workhorse in machine learning across a broad array of applications Gou et al. (2021); Sanh et al. (2019), as it enables using large, complex, and expensive to execute teachers to train smaller and more efficient student models. These student models can then be deployed at lower cost and exhibit lower inference time, which can be a critical enabler in real-time applications.
However, the simplicity and effectiveness of knowledge distillation even with only a black-box query access to the teacher $\mathcal{T}$—for example, when $\mathcal{T}$ is proprietary—means that this technique can also be used for knowledge and capability "stealing". This issue is especially acute with frontier reasoning-capable LLMs, the design and training of which carry enormous effort and expense Guo et al. (2025); Jaech et al. (2024). These models produce explicit reasoning traces—structured outputs that decompose problem-solving into intermediate steps before arriving at a final answer. These traces provide rich supervision signals that go beyond mere input-output pairs. As a result, practitioners increasingly seek to distill reasoning capabilities from these frontier models. Since distillation incurs a fraction of the cost of training an original teacher, its efficacy without any guardrails can disincentivize innovation.
Two classes of approaches have been proposed to counter unauthorized distillation of large language models: *anti-distillation* and *API watermarking*. Anti-distillation methods aim to degrade the efficacy of distillation training Li et al. (2025); Savani et al. (2025). However, state-of-the-art approaches for anti-distillation significantly degrade the *teacher* efficacy as well as the student, making them impractical. API watermarking, on the other hand, attempts to insert a watermark into the query responses in a way that enables its verification from the student model trained on such traces He et al. (2022a,b); Zhao et al. (2022, 2023b). However, most API watermarking approaches use token-level statistics, and tend to result in a non-negligible false-alarm rate which provides plausible deniability for the model "thief".
We propose and analyze several methods for modifying teacher-generated reasoning traces to achieve these two complementary objectives. Specifically, we propose two classes of approaches for anti-distillation. The first uses an assistant LLM to rewrite instructions specifically in order to subvert their use in downstream training while preserving semantics. This approach leverages the semantic understanding of modern LLMs to transform clean traces into modified versions that achieve our objectives. Additionally, we adapt our instruction rewriting approach to facilitate stealthy watermark embedding in reasoning traces. Our second approach uses (projected) gradient-based optimization in the embedding space with the explicit objective of degrading training efficacy of a (proxy) student.
Conceptually, the problem of anti-distillation is closely related to the extensive literature on poisoning attacks in machine learning Goldblum et al. (2022); Tian et al. (2022); Vorobeychik and Kantarcioglu (2018), and large language models in particular Wan et al. (2023); Das et al. (2025). In this literature, an array of threat models has been considered, including attacks that modify the inputs $x$, the labels $y$, or both. However, our setting is distinct from nearly all prior work on data poisoning in four important ways. First, we assume the teacher model is queried sequentially, meaning *we do not have access to the full dataset* in modifying the response to each query, but must instead do so online for each query. Second, our modification of responses $y$ to queries $x$ must preserve a high degree of functionality to avoid degrading the teacher model. Third, our responses must be modified in a way that is *stealthy*, ruling out addition of nonsensical tokens in obvious positions, such as at the end of the normal response, where they can be easily detected and removed by an adaptive student. Fourth, the rich space of LLM responses $y$ allows far more opportunities for manipulation than the typical label modification attacks.
We evaluate our methods on LLM reasoning benchmarks using a variety of student model architectures. Our results show that our optimized instruction-based rewriting approach achieves strong anti-distillation effects, reducing student accuracy by up to 61.3%—a significantly stronger anti-distillation effect than recent baseline approaches. At the same time, our approach maintains and often even *improves* teacher performance, in contrast to baselines, which exhibit significant teacher performance degradation. We also observe a scaling property where stronger student models experience greater performance degradation, suggesting that capable models more effectively learn the corrupted reasoning patterns. For API watermarking, our approach enables the embedding of watermarks into student models that can be reliably detected with few verification queries while attaining *an essentially zero false alarm rate*, significantly outperforming state-of-the-art API watermarking baselines.
In summary, our main contributions are:
1. Several prompt-based and gradient-based rewriting approaches for anti-distillation.
2. A prompt-based rewriting approach for stealthy watermark embedding.
3. Extensive experiments demonstrating that our rewriting approaches achieve (a) state-of-the-art anti-distillation effectiveness without compromising teacher accuracy, and (b) state-of-the-art watermarking reliability with essentially zero false alarms.
## 2 Related Work
**Controllable Text Generation (CTG):** CTG aims to steer LLM outputs to satisfy predefined conditions while maintaining fluency and coherence Liang et al. (2024a). Early approaches trained conditional LMs with explicit control codes that govern style and content Keskar et al. (2019). Inference-time methods such as gradient-based steering Madotto et al. (2020) and discriminator-guided decoding Yang and Klein (2021); Krause et al. (2021) offer greater flexibility by modifying generation without retraining. Prompt-based approaches are even more light-weight, employing chain-of-thought reasoning Wei et al. (2022), directional stimulus Li et al. (2023b), and iterative self-refinement Madaan et al. (2023).
**Anti-Distillation:** Recent work has explored proactive prevention of unauthorized distillation by manipulating model outputs. Antidistillation Sampling (ADS) Savani et al. (2025) is a sampling-based method that achieves a better trade-off between teacher utility and anti-distillation effectiveness compared to naive temperature sampling. However, with sampling parameters effective for anti-distillation, ADS often produces unnatural or incoherent text. Defensive output generation (DOGe) Li et al. (2025) post-trains the teacher model's final layer to be inherently defensive against distillation. While effective, DOGe's outputs are also sometimes unnatural. Moreover, as a post-training approach, DOGe fundamentally lacks flexibility: the model is either defensive or not at all, and cannot adjust defense strength without retraining. Ding et al. (2025) remove self-talk behaviors and reorder sub-conclusions ahead of the reasoning step, which is better at preserving semantics but has limited anti-distillation effects. In contrast, our method requires no modification to the teacher model, guarantees semantic coherence in the generated traces, and achieves strong anti-distillation.
**Fingerprinting and Watermarking:** Model fingerprinting aims to protect the model itself from unauthorized *fine-tuning* (e.g., if the model is openly released but with a restrictive licensing agreement) by allowing model owners to uniquely identify their models Gu et al. (2022); Xu et al. (2024a). On the other hand, model watermarking Liang et al. (2024b); Wan et al. (2022) operates on model outputs. Common *text watermarking* approaches aim to determine whether the text was AI generated Kirchenbauer et al. (2023); Zhao et al. (2023a). In contrast, *API watermarking* methods are explicitly proposed as a defense against unauthorized knowledge distillation He et al. (2022a,b); Zhao et al. (2022, 2023b). Many of the latter methods focus on traditional NLP tasks, such as sentiment analysis, and thereby assume that labels come from a simple structured space (e.g., real values or a small set of classes) Li et al. (2023a); Liu et al. (2023). Furthermore, nearly all API watermarking approaches rely on token-level statistical techniques for detection which result in a non-trivial tradeoff between verification success and false alarm rates. And for those that do operate on sentence level Hou et al. (2024); Dabiriaghdam and Wang (2025), their transferability after distillation is unreliable, or they lack teacher-specific attribution necessary for proving unauthorized distillation. In contrast, our proposed approach is both simpler and (as we show) substantially more reliable.
## 3 Preliminaries
### 3.1 LLMs and Reasoning
**Large Language Models (LLMs):** LLMs are neural networks trained on massive text corpora to predict the next token given provided context. Formally, an LLM is a parametric function $p_\theta$ with parameters $\theta$, mapping a sequence of input tokens $x_{1:t}=(x_1, x_2, \ldots, x_t)$, with $x_i$ from a vocabulary set $\mathcal{W}$, to a distribution over the next token. Given any sequence of tokens as input, the model computes the conditional probability distribution, $p_\theta(\cdot|x_{1:t})$, of all next-token probabilities.
**Reasoning Traces:** In this work, we define reasoning traces as structured outputs that explicitly decompose problem-solving processes into intermediate steps. Formally, given a problem or query $q$, a reasoning trace (response) $r$ is a sequence $r=(s_1, s_2, \ldots, s_k, a)$, where each $s_i$ represents an intermediate reasoning step, and $a$ is the final answer. The generation of reasoning traces can be elicited through prompting techniques (e.g., chain-of-thought prompting Wei et al. (2022)) or by training models explicitly to produce such structured outputs Guo et al. (2025); Jaech et al. (2024).
### 3.2 Knowledge Distillation
Knowledge distillation (KD) is a technique for transferring knowledge from a large, capable teacher model to a smaller, more efficient student model Hinton et al. (2015). In the context of LLMs, let $\mathcal{T}$ denote the teacher model and $\mathcal{S}$ denote the student model. Given a dataset of queries $Q=\{q_1, q_2, \ldots, q_n\}$, the goal is to train the student model $\mathcal{S}$ to emulate the teacher model $\mathcal{T}$'s behavior Xu et al. (2024b).
There are different training methods for knowledge distillation. In this work, we focus primarily on supervised fine-tuning (SFT)-based distillation, as it is widely adopted in practice. In SFT-based distillation, the teacher is given a sequence of queries $Q=\{q_1, \ldots, q_n\}$, one at a time, and generates responses $r_i=\mathcal{T}(q_i)$ to each $q_i$. These are then used to construct a dataset $D=\{(q_i, r_i)\}_{i=1}^n$. The student model is then trained by minimizing:
$$\mathcal{L}_{SFT}(\mathcal{S};D)=-\sum_{i=1}^{n}\sum_{t=1}^{|r_i|}\log p_\theta(r_{i,t}|r_{i,1:t-1}, q_i)$$
where $r_{i,t}$ is the $t$-th token in response $r_i$.Similar Articles
Protecting Language Models Against Unauthorized Distillation through Trace Rewriting
Researchers propose trace rewriting methods to prevent unauthorized LLM knowledge distillation while preserving answer correctness and embedding detectable watermarks.
Distillation Defenses Easily Break After Reinforcement Learning
This paper argues that existing defenses against distillation attacks in large language models are ineffective when attackers further train their models with reinforcement learning, highlighting potential flaws in current threat models.
Antidistillation is Cheap: Lightweight Distillation-Resistance via Stylistic Corruption
The paper proposes a lightweight defense against black-box knowledge distillation by injecting style-steering vectors into teacher model activations on suspected malicious queries, disrupting student learning while preserving output quality at negligible overhead.
Trace-Based On-Policy Distillation for Masked Diffusion Language Models
A paper proposing Trace-Based On-Policy Distillation (TOPD), a teacher-supervised framework for transferring reasoning abilities to masked diffusion language models without reward estimation, achieving comparable accuracy to RL-trained counterparts with significant compute speedup.
Masked Distillation: Internalizing the Chain-of-Thought in Language Models
Masked distillation is a knowledge-distillation framework that trains a student LLM to predict only solution tokens while a reasoning teacher provides feedback, aiming to internalize chain-of-thought computation into model parameters. The method shows task-dependent success, working on GSM8K but requiring small scaffolds for harder tasks like Countdown.