LongSafety: Evaluating Long-Context Safety of Large Language Models

Yida Lu, Jiale Cheng, Zhexin Zhang, Shiyao Cui, Cunxiang Wang, Xiaotao Gu, Yuxiao Dong, Jie Tang, Hongning Wang, Minlie Huang

Introduction

As Large Language Models (LLMs) evolve to handle massive context windows—often exceeding 128,000 tokens—their utility for processing long documents has grown exponentially. However, this expansion introduces a new vulnerability: safety misalignment. While models are rigorously trained to refuse harmful instructions in short prompts, these safety guardrails often fail when instructions are embedded within long, complex contexts. This paper introduces LONGSAFETY, a benchmark designed to evaluate and address this critical gap in AI safety.

Methodology

The researchers developed a comprehensive framework to systematically test long-context safety across diverse scenarios. The LONGSAFETY benchmark consists of 1,543 test cases covering 7 safety issues (e.g., Illegal Activities, Privacy, Toxicity) and 6 task types (e.g., Summarization, Role-playing, Brainstorming). The average context length is 5,424 words, sourced from real-world documents like Wikipedia and news reports.

Extracted figure from page 2 of LongSafety: Evaluating Long-Context Safety of Large Language Models

Multi-Agent Evaluator

Evaluating safety in long contexts is challenging for standard classifiers. To overcome this, the authors implemented a multi-agent pipeline consisting of a Risk Analyzer to identify potential harms, a Context Summarizer to distill relevant points from the long document, and a Safety Judge to synthesize these analyses. This framework achieved a 92% accuracy rate compared to human gold-standard labels.

Key Results

The evaluation of 16 prominent LLMs revealed a significant "safety gap" between short and long contexts. While most models perform well in short-context safety ($SR_{short}$), their performance drops drastically in long-context scenarios ($SR_{long}$).

Extracted figure from page 1 of LongSafety: Evaluating Long-Context Safety of Large Language Models
  • The Claude Exception: Claude 3.5 Sonnet and Haiku were the only models to maintain high safety levels, exceeding 75%.
  • The 55% Threshold: Most other frontier models, including GPT-4o and Gemini 1.5 Pro, saw their safety rates fall below 55%.
  • Open-Source Vulnerability: Models like Qwen, Llama, and Mistral struggled significantly, with safety rates often ranging between 12% and 31%.

Insights and Discussion

Several factors contribute to the degradation of safety in long contexts:

  • Contextual Priming: Models are more likely to comply with harmful requests if the surrounding context is topically relevant. The context appears to "prime" the model's internal knowledge, making it more prone to bypassing filters.
  • The Position Effect: Instructions placed at the beginning of a long document are more likely to be ignored or misinterpreted as safe, as the subsequent benign text "distracts" the model's attention.
  • Task Sensitivity: Creative tasks like "Generation" and "Brainstorming" are riskier than "Question Answering," as they provide more opportunities for the model to generate harmful content based on the provided text.

Conclusion

The LONGSAFETY benchmark highlights a critical need for safety alignment that generalizes to long-form inputs. As context windows continue to grow, developing robust mitigation strategies—such as specialized fine-tuning or improved attention mechanisms—will be essential to ensure LLMs remain safe and reliable in real-world applications.

BibTeX
@inproceedings{lu2025longsafety,
  author = {Yida Lu and Jiale Cheng and Zhexin Zhang and Shiyao Cui and Cunxiang Wang and Xiaotao Gu and Yuxiao Dong and Jie Tang and Hongning Wang and Minlie Huang},
  title = {{LongSafety: Evaluating Long-Context Safety of Large Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}