Domain Restriction via SAE Multi-Layer Transitions
Abstract
The general-purpose nature of Large Language Models (LLMs) presents a significant challenge for domain-specific applications, often leading to out-of-domain (OOD) interactions that undermine the provider's intent. Existing methods for detecting such scenarios treat the LLM as an uninterpretable black box and overlook the internal processing of inputs. In this work we show that layer transitions provide a promising avenue for extracting domain-specific signature. Specifically, we present several lightweight ways of learning on internal dynamics encoded using a sparse autoencoder (SAE) that exhibit great capability in distinguishing OOD texts. Building on top of SAEs representation transitions enables us to better interpret the LLM internal evolution of input processing and shed light on its decisions. We provide a comprehensive analysis of the method and benchmark it with the gemma-2 2B and 9B models. Our results emphasize the efficacy of the internal process in capturing fine-grained input-related details.
Lay Summary
Large language-model services are often designed to handle only certain kinds of requests, but it can be difficult to know when a user input falls outside the intended scope of the system. This paper proposes a method for detecting such out-of-domain inputs by looking inside the language model and tracking how sparse, interpretable features change across its layers. The method learns the normal internal feature-transition patterns of in-domain text and flags inputs whose internal processing deviates from those patterns. This allows the system to detect out-of-scope requests using only in-domain examples, without training the base language model on out-of-domain data. The results suggest that internal layerwise feature dynamics can provide a useful and interpretable signal for deciding whether a request should be handled, rejected, or rerouted.