{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/longsafety-evaluating-long-context-safety-of","title":"LongSafety: Evaluating Long-Context Safety of Large Language Models","arxiv_id":"2502.16971","date":"2025-02-24","proceeding":null,"authors":["Yida Lu","Jiale Cheng","Zhexin Zhang","Shiyao Cui","Cunxiang Wang","Xiaotao Gu","Yuxiao Dong","Jie Tang","Hongning Wang","Minlie Huang"],"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.","url_abs":"https://arxiv.org/abs/2502.16971v1","url_pdf":"https://arxiv.org/pdf/2502.16971v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"longsafety-evaluating-long-context-safety-of","repo_url":"https://github.com/thu-coai/longsafety","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=2502.16971","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2502.16971"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/thu-coai/longsafety","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/thu-coai/LongSafety","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"unverified":4},"by_repo_kind":{"official":{"samples":4,"ran":0,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"3e34927af2210615","entry":"build_prompt","repo":"thu-coai/LongSafety","repo_kind":"official","path":"src/gen_model_response.py","file_url":"https://github.com/thu-coai/LongSafety/blob/HEAD/src/gen_model_response.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3e34927af2210615"}},{"code_sha256_prefix":"962e634cb87af48b","entry":"judge","repo":"thu-coai/LongSafety","repo_kind":"official","path":"src/multi_agent_eval.py","file_url":"https://github.com/thu-coai/LongSafety/blob/HEAD/src/multi_agent_eval.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"962e634cb87af48b"}},{"code_sha256_prefix":"2b437258a1ed6a1f","entry":"load_data","repo":"thu-coai/LongSafety","repo_kind":"official","path":"src/gen_model_response.py","file_url":"https://github.com/thu-coai/LongSafety/blob/HEAD/src/gen_model_response.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2b437258a1ed6a1f"}},{"code_sha256_prefix":"7f8345e3b106eff8","entry":"load_model","repo":"thu-coai/LongSafety","repo_kind":"official","path":"src/gen_model_response.py","file_url":"https://github.com/thu-coai/LongSafety/blob/HEAD/src/gen_model_response.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7f8345e3b106eff8"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}