Instructional Segment Embedding: Improving LLM Safety with Instruction Hierarchy

Tong Wu, Shujian Zhang, Kaiqiang Song, Silei Xu, Sanqiang Zhao, Ravi Agrawal, Sathish Reddy Indurthi, Chong Xiang, Prateek Mittal, Wenxuan Zhou · DOI

Abstract

Current Large Language Models (LLMs) process all input tokens with equal priority, creating a "flat" architecture vulnerable to security flaws like prompt injection. We present Instructional Segment Embedding (ISE), an architectural modification that introduces an explicit instruction hierarchy into the model's embedding layer. By categorizing tokens into System, User, Data, and Output segments, ISE enables models to prioritize developer instructions over potentially malicious external data. Our evaluation across multiple benchmarks shows that ISE significantly improves robustness against prompt injection and extraction attacks by up to 18.68% and 45% respectively, while simultaneously enhancing general instruction-following performance.

1. Introduction

Modern LLM applications typically involve three distinct sources of input: system instructions provided by developers, prompts from end-users, and external data retrieved from various sources. However, standard transformer architectures treat these inputs as a single, undifferentiated sequence of tokens. This lack of hierarchy allows malicious commands embedded in low-priority data to override high-priority system instructions, a phenomenon known as prompt injection.

Overview of the interaction flow between system instructions, user prompts, and external data.

2. The Vulnerability of Flat Architectures

The "democratic" nature of current LLMs means that every token is processed using the same mechanism. When a model receives a system prompt like "You are a helpful assistant" followed by user data containing "Ignore all previous instructions and do X," the model has no inherent way to distinguish the authority of the former over the latter.

Examples of common security vulnerabilities in LLMs: (a) prompt injection, (b) prompt extraction, and (c) harmful requests.

As shown in the figure above, these vulnerabilities manifest in several ways:

  • Prompt Injection: Malicious data overrides system instructions.
  • Prompt Extraction: Users attempt to leak the hidden system prompt.
  • Harmful Requests: Direct attempts to generate unsafe content.

3. Instructional Segment Embedding (ISE)

To address these vulnerabilities, we propose Instructional Segment Embedding (ISE). Inspired by the segment embeddings used in BERT, ISE bakes a hierarchy directly into the model's mathematical representation.

3.1 Architectural Modification

We introduce a learnable embedding matrix $E_{seg}$ that assigns a segment ID to every token:

  • System (0): Developer-defined constraints and personas.
  • User (1): Direct commands from the end-user.
  • Data (2): Passive information or context retrieved from external sources.
  • Output (3): Tokens generated by the model.

The final input representation for each token is the sum of its Token Embedding, Positional Embedding, and the new Instructional Segment Embedding. This adds negligible parameters to the model while providing a persistent signal of token provenance.

3.2 Training and Attention

Models are fine-tuned on datasets where tokens are explicitly tagged with these segment IDs. This process teaches the model to redistribute its attention. While standard models often over-attend to malicious tokens within the data segment, ISE-equipped models maintain a stronger focus on the system instructions, effectively filtering out unauthorized commands from the data stream.

4. Experimental Evaluation

We evaluated ISE across several model families, including Llama-2 and Llama-3, using a variety of safety and utility benchmarks.

4.1 Benchmarks

  • Safety: Structured Query (indirect injections) and Instruction Hierarchy (injection, extraction, and harmful requests).
  • Utility: AlpacaEval 1.0 and MT-Bench to ensure no degradation in general capabilities.

4.2 Key Results

ISE demonstrated significant improvements in both safety and utility:

  • Robustness: Robust accuracy improved by 15.75% on Structured Query and 18.68% on Instruction Hierarchy benchmarks.
  • Extraction Defense: Worst-case robustness against prompt extraction improved by approximately 45%.
  • Utility Synergy: Surprisingly, ISE improved instruction-following performance on AlpacaEval by up to 4.1%, suggesting that clear role differentiation aids model reasoning.
  • Reduced Over-refusal: Compliance rates on benign prompts in the WildChat benchmark improved by roughly 10%, indicating the model is less likely to be "paranoid."

5. Conclusion and Future Work

Instructional Segment Embedding provides a lightweight yet powerful method for enforcing instruction hierarchy in LLMs. By moving the hierarchy from the text prompt to the embedding layer, we create a defense that is harder to bypass. While ISE shows great promise against standard injections, future work will explore its effectiveness against more complex adversarial "jailbreak" suffixes and its scalability to 70B+ parameter models. Integrating ISE during the initial pre-training phase may further solidify these safety gains.

Summary updated

BibTeX
@inproceedings{wu2025instructional,
  author = {Tong Wu and Shujian Zhang and Kaiqiang Song and Silei Xu and Sanqiang Zhao and Ravi Agrawal and Sathish Reddy Indurthi and Chong Xiang and Prateek Mittal and Wenxuan Zhou},
  title = {{Instructional Segment Embedding: Improving LLM Safety with Instruction Hierarchy}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=sjWG7B8dvt},
}
Figure