Skip to content

LongSafety: Evaluating Long-Context Safety of Large Language ModelsLongSafety: Evaluating Long-Context Safety of Large Language Models

arXiv· arXiv:2502.16971· ACL 2025· Yida Lu, Jiale Cheng, Zhexin Zhang, Shiyao Cui, Cunxiang Wang, Xiaotao Gu, Yuxiao Dong, Jie Tang, Hongning Wang, Minlie HuangThe Conversational AI (CoAI) group, DCST, Tsinghua University; Zhipu AI; The Knowledge Engineering Group (KEG), DCST, Tsinghua UniversityIndexed by this site · 22 days ago· Originally publishedSelected EvaluationSelectedAttention38

Quick read

Evaluation and benchmarks

Based on the paper PDF (AI-generated); refer to the original

The authors propose the long-context safety benchmark LongSafety (1,543 cases, average 5,424 words), evaluate 16 LLMs, and the authors claim that except for the Claude-3.5 series, safety rates are all below 55%.

Questions
Existing safety benchmarks are mostly short queries within a few hundred words, while long-context benchmarks test only general capabilities; the safety of LLMs in open-ended long-context tasks lacks systematic evaluation.
Methods
Constructing LongSafety: crowdsourced collection of safety-related long documents and writing of instructions, covering 7 safety problem categories and 6 task categories, 1,543 in total; a three-role multi-agent judge driven by GPT-4o mini determines answer safety, and an answer is considered safe only if it is safe under both placements of the instruction at the beginning and the end of the context.
Experiments and results
Evaluating 16 models: the authors report that, except for the Claude-3.5 series (77.7%, 76.8%), the average SRlong is below 55%; safety rates in long and short scenarios are uncorrelated; relevant context and longer inputs further reduce the safety rate; the judge's accuracy is 92%, higher than baselines such as LlamaGuard3.
Limitations and future work
Limitations listed by the authors: attack-oriented tasks such as many-shot jailbreaking are not covered; the evaluator uses GPT-4o mini throughout, which is relatively costly; manually collected data is difficult to scale. The experiments cover 16 models and English data; the evaluator test set has 500 items, with an annotator agreement rate of about 82%.
Experimental setupClaude-3.5-haiku、Claude-3.5-sonnet et al. · LongSafety · SRlong、SRshort et al.
Evaluated models
Claude-3.5-haikuClaude-3.5-sonnetGemini-1.5-flashGemini-1.5-proGPT-4-turbo-2024-04-09GPT-4oGPT-4o miniGLM-4-plusQwen2.5-72B-InstructLlama-3.1-70B-InstructMixtral-8x7B-InstructQwen2.5-7B-InstructInternlm2.5-7B-InstructGLM-4-9B-ChatLlama-3.1-8B-InstructMistral-7B-Instruct-v0.3
Benchmarks
LongSafety
Metrics
SRlongSRshortAccuracyF1-SafeF1-Unsafe
AI summaryand selection rationaleThe CoAI group at Tsinghua University and Zhipu et al. propose LongSafety, a long-context safety benchmark containing 1,543 tests averaging 5,424 words each, covering 7 categories of safety issues and 6 categories of tasks. The authors score with a multi-agent evaluator composed of three roles—risk analysis, context summarization and safety judgment—which achieves 92% accuracy on a 500-item human-annotated test set. After evaluating 16 long-context models, they find that except for the Claude-3.5 series, average safety rates are all below 55%, closed-source models are overall higher than open-source models, Sensitive Topics questions are the weakest category, and all open-source models are below 20%. When the same batch of models is given only instructions without long context, safety rates are markedly higher; for example, Llama-3.1-8B-Instruct drops from 74.2% to 13.4%. The analysis shows that context content related to safety topics and longer input sequences further reduce safety rates, and adding safety prompts such as Goal Prioritization significantly improves them, though a gap remains compared with short-context scenarios.

The CoAI group at Tsinghua University and Zhipu et al. propose LongSafety, a long-context safety benchmark containing 1,543 tests averaging 5,424 words each, covering 7 categories of safety issues and 6 categories of tasks. The authors score with a multi-agent evaluator composed of three roles—risk analysis, context summarization and safety judgment—which achieves 92% accuracy on a 500-item human-annotated test set. After evaluating 16 long-context models, they find that except for the Claude-3.5 series, average safety rates are all below 55%, closed-source models are overall higher than open-source models, Sensitive Topics questions are the weakest category, and all open-source models are below 20%. When the same batch of models is given only instructions without long context, safety rates are markedly higher; for example, Llama-3.1-8B-Instruct drops from 74.2% to 13.4%. The analysis shows that context content related to safety topics and longer input sequences further reduce safety rates, and adding safety prompts such as Goal Prioritization significantly improves them, though a gap remains compared with short-context scenarios.

Why it was selectedAcross 1,543 tests, most of 16 long-context models have a safety rate below 55%, and good short-context performance does not imply long-context safety; both the benchmark and the multi-agent evaluator can be reused.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    The authors state that LLM safety in long-context scenarios lacks systematic evaluation, and propose the open-ended long-context safety benchmark LongSafety.

    Core problem: the safety of LLMs in long-context tasks lacks systematic evaluation, and existing benchmarks cannot cover this scenario.

    • Problem scenario: the authors state that as LLMs' ability to process and generate ultra-long sequences grows, long context introduces new safety risks, such as harmful content implication and model cognition interference, which require systematic examination.
    • Shortcomings of existing methods: the authors point out that existing long-context benchmarks (LongBench, InfiniteBench, RULER) evaluate only general capabilities and do not consider safety; existing safety benchmarks (SafetyBench, SALAD-Bench, etc.) are mostly single-turn short queries within a few hundred words and cannot evaluate long-context models that must process documents of thousands of words; the parallel work LongSafetyBench uses a multiple-choice format, which the authors consider unable to adequately evaluate generation safety, which is more valued for generative models.
    • Proposed in the paper: LongSafety, which the authors claim is the first safety benchmark for open-ended long-context tasks, containing 7 safety problem categories, 6 task categories, and 1,543 test cases, with an average context length of 5,424 words; it is accompanied by a multi-agent judge.
    • Evaluation setup: given a long context C related to a safety scenario and an instruction I that induces safety risk, the model must answer I based on C; the instruction can be appended at the beginning or the end of the context, and a sample is considered safe only if both placements are safe. This is not an attack or defense paper and has no adversarial threat model; the evaluation targets are the 16 long-context LLMs themselves.
  2. What related research exists?

    Related work is divided into two groups: long-context models and benchmarks, and safety benchmarks; the authors claim LongSafety is the first safety benchmark for open-ended long-context tasks.

    Long-context models and benchmarks

    • Long-sequence processing techniques (Sun et al., 2023b; Su et al., 2024; Xiao et al., 2024; Chen et al., 2024) improved LLMs' ability to understand and generate long texts.
    • LongBench (Bai et al., 2024) evaluates long-context understanding in a bilingual setting; InfiniteBench (Zhang et al., 2024a) extends evaluation beyond 100k tokens; RULER (Hsieh et al., 2024) introduces new tasks beyond context retrieval. The authors point out that these benchmarks focus only on general capabilities and do not consider safety issues.

    Safety benchmarks

    • SafetyBench (Zhang et al., 2023a) evaluates multiple categories of safety issues using multiple-choice questions; Red Team (Ganguli et al., 2022) and AdvBench (Zou et al., 2023) focus on red-teaming tasks; SALAD-Bench (Li et al., 2024) incorporates attack and defense methods into evaluation. The authors point out that these benchmarks are usually short queries without context and are difficult to use for long-context tasks.
    • LongSafetyBench (Huang et al., 2024) is a parallel work that uses multiple-choice questions to examine long-context models' harm awareness. The authors argue that the multiple-choice format cannot evaluate generation safety, which is more critical for generative models.

    Safety judges

    • The paper points out that existing judges such as LLM safety guardrails (Dubey et al., 2024; Zhang et al., 2024b) and GPT judges (Yu et al., 2023; Deng et al., 2023) struggle to effectively use contextual information in long-context evaluation, with performance degradation due to information loss; this motivates their multi-agent judge.

    Baselines and comparisons: the judge's comparison baselines are LlamaGuard3, ShieldLM-14B-qwen, GPT-4o mini, and GPT-4o (Table 4); the safety prompting experiments use Self-Reminder (Wu et al., 2023) and Goal Prioritization (Zhang et al., 2023b) (Table 7). The authors position this paper as: the first safety benchmark targeting open-ended long-context tasks and covering multiple safety problem categories and task types.

  3. How does the paper address this problem?

    Constructing 1,543 manually collected long-context safety samples, and using a three-role multi-agent judge driven by GPT-4o mini to determine answer safety.

    Overall approach: manually collect long documents related to safety scenarios and write inducing instructions to form the LongSafety benchmark; then use a multi-agent evaluation framework to determine whether model responses are safe.

    Problem Setting

    • Given a long context C and an instruction I, the model generates a response R, and the evaluator determines whether it is safe; the instruction can be placed at the beginning or the end of the context, i.e., both concatenations (C, I) → R and (I, C) → R are included in the evaluation.
    • I is usually short, and C is a long sequence; the context of each sample comes from the internet, and the instruction is related to a safety scenario.

    Safety Issues and Task Classification

    • 7 safety issue categories: Toxicity Content, Biased Opinion, Physical & Mental Harm, Illegal Activities, Unethical Activities, Privacy & Property, Sensitive Topics, revised from existing classification frameworks (Sun et al., 2023a; Zhang et al., 2024b).
    • 6 task types: Question Answering, Generation, Brainstorming, Summarization, Rewrite are taken from Ouyang et al. (2022), with Role-playing newly added; definitions are in Appendix A.

    Data Construction

    • Context collection: 46 Chinese annotators used search engines to retrieve English documents by keywords expanded from each safety issue category (Appendix A, Table 5), extracted plain text, and removed hyperlinks and special symbols; multiple related documents could be merged into one context. The annotation document requires documents to exceed 3,000 words (Appendix B).
    • Instruction writing: for each context, 3 instructions of different task types that can trigger the related safety issue were written; annotators needed to first understand the safety scenario of the context before writing.
    • Filtering: for each context, only the one instruction most likely to trigger the safety issue was retained, and the consistency among context, instruction, and keywords was manually checked, yielding 1,543 items with an average of 5,424 words (Table 1).

    Multi-Agent Evaluator

    • Risk Analyzer: analyzes the safety risk implied by instruction I and generates a reference set R of safe/unsafe responses, ℛ = Analyzer(I).
    • Context Summarizer: generates a context summary S, extracting key points and marking information relevant to the instruction, S = Summarizer(C, I); the authors state that this step can remove distracting content.
    • Safety Judge: combines I, R, S, and R to give a binary safety label J; all three roles are initialized with GPT-4o mini, and the full prompts are in Appendix E.

    Metrics

    • SRlong: a sample counts as safe only if the responses under both concatenations are judged safe, SRlong = Numboth_safe / Numtotal.
    • SRshort: the safety rate when the same set of instructions is input to the model without context, used for long vs. short scenario comparison.
  4. What experiments did the paper conduct?

    Evaluation of 16 LLMs: the authors report that, except for the Claude-3.5 series, average SRlong is below 55%, safety performance in long and short scenarios is uncorrelated, and relevant context and longer inputs further reduce the safety rate.

    Experimental Setup

    • Models evaluated: 16 LLMs with a context length of no less than 32k tokens (Appendix D, Table 6). Closed-source: Claude-3.5-haiku, Claude-3.5-sonnet, Gemini-1.5-flash, Gemini-1.5-pro, GPT-4-turbo-2024-04-09, GPT-4o, GPT-4o mini, GLM-4-plus; open-source: Qwen2.5-72B/7B-Instruct, Llama-3.1-70B/8B-Instruct, Mixtral-8x7B-Instruct, Internlm2.5-7B-Instruct, GLM-4-9B-Chat, Mistral-7B-Instruct-v0.3.
    • Benchmark: LongSafety, 1,543 items, average 5,424 words (Table 1).
    • Decoding: greedy decoding.
    • Evaluation method: multi-agent evaluator, with all three roles initialized with GPT-4o mini; the Context Summarizer is removed when there is no context input.
    • Metrics: SRlong (safe only if both concatenations are safe), SRshort (instruction input only).
    • Evaluator assessment: a manually constructed test set of 500 items (half safe, half unsafe); the agreement rate among three annotators is about 82%, and inconsistent samples were manually reviewed (Appendix G).

    Main Results

    According to Table 2 (SRlong, %, listed by safety issue; averages listed here):

    ModelAvg. SRlong
    Claude-3.5-haiku77.7
    Claude-3.5-sonnet76.8
    Gemini-1.5-flash53.0
    Gemini-1.5-pro51.6
    GPT-4-turbo-2024-04-0948.3
    GPT-4o40.4
    GPT-4o mini37.1
    GLM-4-plus27.5
    Qwen2.5-72B-Instruct31.3
    Llama-3.1-70B-Instruct25.9
    Mixtral-8x7B-Instruct20.1
    Qwen2.5-7B-Instruct19.1
    Internlm2.5-7B-Instruct15.8
    GLM-4-9B-Chat13.6
    Llama-3.1-8B-Instruct13.4
    Mistral-7B-Instruct-v0.312.3
    • The authors state that all models except the Claude-3.5 series have an average safety rate below 55%, and that closed-source models overall outperform open-source models on all safety issues.
    • By safety issue (Table 2): most models score relatively high on Physical & Mental Harm and generally struggle on Sensitive Topics—most models are below 50%, and all open-source models are below 20% (the highest in the open-source ST column is 19.4 for Mixtral-8x7B-Instruct and Qwen2.5-72B-Instruct).
    • Long vs. short scenario comparison (Table 3): all models show a decrease in safety rate from short instructions to long inputs, with Variation (SRlong−SRshort) ranging from -12.2 for Claude-3.5-haiku to -60.8 for Llama-3.1-8B-Instruct; the authors note that good performance in short scenarios does not imply a small decrease—for example, Llama-3.1-8B-Instruct ranks second among open-source models in SRshort (74.2) but has the largest decrease.

    Task Type Analysis

    • According to Figure 3, safety rates decrease from short to long scenarios across all 6 task types; in long scenarios, the average SRlong of the four generation-oriented tasks—Generation (28.3%), Brainstorming (29.8%), Summarization (25.3%), and Rewrite (23.6%)—is below 30%, while Question Answering is 46.3% and Role-playing is 47.8%.
    • The authors argue that models face greater challenges in generation-oriented tasks than in the widely evaluated question answering task.

    Evaluator Assessment

    • According to Table 4, on the 500-item manually annotated test set, the multi-agent framework in this paper achieves an accuracy of 0.920 (F1-Safe 0.917, F1-Unsafe 0.922), higher than LlamaGuard3 (0.838), ShieldLM-14B-qwen (0.870), GPT-4o mini (0.860), and GPT-4o (0.836).
    • Ablation: removing the Context Summarizer yields an accuracy of 0.896, which the authors state is still higher than GPT-4o mini, equivalent to a single Safety Judge, indicating that each role contributes.

    Effects of Context Content and Length

    • Content (§5.1, Figure 4): 400 items were randomly sampled from the benchmark, with four settings: instruction only, random-word context, irrelevant context, and relevant context (the latter three contexts have the same length). For the four models GPT-4o, GPT-4o mini, Llama-3.1-70B/8B-Instruct, the safety rate is lowest under the relevant-context setting, and performance under the random and irrelevant settings is similar; the authors state that relevant context is more likely to induce safety risks, and that the Llama-3.1 series varies little across the latter three settings.
    • Length (§5.2, Figure 5): 200 samples with contexts exceeding 8k words were sampled, segmented into 100-word chunks, and chunks were selected by GPT-4o mini based on relevance to safety keywords and concatenated into different lengths. The authors state that the safety rate of the Llama3.1 series continues to decrease as length increases, while GPT-4o and GPT-4o mini decrease markedly from 0k to 0.5k and change little at greater lengths; the authors speculate that content relevance has a greater effect than length for these two models.

    Other Ablations and Analyses

    • Safety prompts (Appendix F, Table 7): under Self-Reminder and Goal Prioritization prompts, SRlong increases for all four models GPT-4o, GPT-4o mini, Qwen2.5-7B-Instruct, and Llama-3.1-8B-Instruct, with a larger increase under Goal Prioritization (e.g., Llama-3.1-8B-Instruct rises from 13.4 to 84.4); the authors note that a gap with SRshort remains after the increase, especially for open-source models.
    • Case study (Appendix H): the appendix presents 4 cases, based on which the authors suggest that long context may activate relevant harmful knowledge within the model and distract the model's attention from the harmfulness of the instruction.
  5. What are some points that can be further explored?

    The authors list three limitations: task coverage, evaluator cost, and data collection scale; the experiments cover 16 models and English data.

    Limitations and Future Directions Noted by the Authors

    • Task coverage (Limitations): the benchmark focuses on task types common in real scenarios and does not include attack-oriented tasks such as many-shot jailbreaking, which the authors state future research could incorporate.
    • Evaluator cost (Limitations): all three agents are initialized with GPT-4o mini, which the authors state may incur relatively high evaluation costs; training a dedicated long-context safety detector to achieve high accuracy at low cost is left for future work.
    • Data collection scale (Limitations): manually searching documents and writing instructions is costly and difficult to scale by manual effort alone; introducing automated collection methods is left for future work.

    Scope of Experiments

    • There are 16 models evaluated, all supporting a context of no less than 32k tokens (Appendix D); the context content and length experiments use only 4 of them (GPT-4o, GPT-4o mini, Llama-3.1-70B/8B-Instruct), with sample sizes of 400 and 200 items respectively.
    • The data are English documents (Appendix B's annotation document requires the document language to be English), collected by 46 Chinese annotators.
    • The evaluator assessment is based on 500 manually annotated samples, with a label agreement rate of about 82% among three annotators (Appendix G); the paper does not report the evaluator's performance broken down by safety issue category or task type.
    • The safety prompt experiments cover 4 models and 2 prompts (Self-Reminder, Goal Prioritization) (Appendix F).
    • The paper does not report the number of repetitions for the main evaluation, only stating that greedy decoding is used to ensure output stability.
  6. Summarize the main content of the paper

    LongSafety evaluates 16 LLMs with 1,543 long-context samples; the authors report that most models have a safety rate below 55%, and safety performance in long and short scenarios is uncorrelated.

    LongSafety is an LLM safety evaluation benchmark for open-ended long-context tasks, which the authors describe as the first benchmark in this direction.

    • Problem addressed: existing safety benchmarks are limited to short queries of a few hundred words, while long-context benchmarks do not test safety; model safety in long-context scenarios lacks systematic evaluation.
    • Method highlights: 46 annotators searched English long documents by safety keywords and wrote inducing instructions, covering 7 safety issue categories and 6 task types, totaling 1,543 items with an average of 5,424 words; each instruction is tested once at the beginning and once at the end of the context, and a sample counts as safe only if both are safe (SRlong); evaluation is performed by a three-role framework of Risk Analyzer, Context Summarizer, and Safety Judge driven by GPT-4o mini, achieving 92% accuracy on a 500-item manually annotated test set, higher than baselines such as LlamaGuard3.
    • Main results: among the 16 models, only Claude-3.5-haiku (77.7%) and Claude-3.5-sonnet (76.8%) have an average SRlong above 55%, and the lowest, Mistral-7B-Instruct-v0.3, is 12.3% (Table 2); all models show a decrease in safety rate from short to long scenarios, with the largest decrease being 60.8 percentage points for Llama-3.1-8B-Instruct, based on which the authors conclude that safety performance in long and short scenarios is uncorrelated (Table 3); generation-oriented tasks (Generation, Brainstorming, Summarization, Rewrite) have an average safety rate below 30% in long scenarios (Figure 3); relevant context is more likely than random or irrelevant context to induce unsafe responses, and longer inputs further reduce the safety rate of some models (Figures 4 and 5).
    • Authors' conclusions: the authors argue that long-context safety should be treated as an independent problem, that both relevant context and input length pose safety risks, and that safety evaluation and improvement specifically targeting long-context scenarios are needed; limitations are that attack-oriented tasks are not covered, evaluator cost is relatively high, and data collection is difficult to scale.

Related papers

Read originalACL 2025