LongSafety: Evaluating Long-Context Safety of Large Language Models

Yida Lu, Jiale Cheng, Zhexin Zhang, Shiyao Cui, Cunxiang Wang +5 more
2/24/2025
cs.CLcs.AI

Official code: thu-coai/LongSafety (16 stars, MIT, last commit 2025-06-18).

Abstract

As Large Language Models (LLMs) continue to advance in understanding and generating long sequences, new safety concerns have been introduced through the long context. However, the safety of LLMs in long-context tasks remains under-explored, leaving a significant gap in both evaluation and improvement of their safety. To address this, we introduce LongSafety, the first comprehensive benchmark specifically designed to evaluate LLM safety in open-ended long-context tasks. LongSafety encompasses 7 categories of safety issues and 6 user-oriented long-context tasks, with a total of 1,543 test cases, averaging 5,424 words per context. Our evaluation towards 16 representative LLMs reveals significant safety vulnerabilities, with most models achieving safety rates below 55%. Our findings also indicate that strong safety performance in short-context scenarios does not necessarily correlate with safety in long-context tasks, emphasizing the unique challenges and urgency of improving long-context safety. Moreover, through extensive analysis, we identify challenging safety issues and task types for long-context models. Furthermore, we find that relevant context and extended input sequences can exacerbate safety risks in long-context scenarios, highlighting the critical need for ongoing attention to long-context safety challenges. Our code and data are available at https://github.com/thu-coai/LongSafety.

View on arXivView PDF

Code Implementations(1)

MIT

[ACL 2025] LongSafety: Evaluating Long-Context Safety of Large Language Models

160Shell, PythonJan 14, 20251 years agoMIT

Similar Papers

Cite this paper

@article{lu2025longsafety,
  title  = {LongSafety: Evaluating Long-Context Safety of Large Language Models},
  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},
  year   = {2025},
  eprint = {2502.16971},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2502.16971v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2502.16971.svg)](https://codeofpaper.com/paper/2502.16971)

Discussion