arXiv:2501.17132cs.SEcs.CL2025-01被引 8

自动生成多样且实时的危险测试用例,高效发现大模型安全漏洞。

ASTRAL: Automated Safety Testing of Large Language Models

  • 用黑盒覆盖准则生成多类别、多风格的危险提示,确保测试多样性。
  • 相比静态数据集,相同测试量下可发现近两倍的不安全行为。
  • 结合网络搜索与大模型生成,实现动态更新的实时安全测试。

大型语言模型(LLMs)在生成类人内容方面表现出色,但其安全性至关重要,因可能产生有害回应。现有测试框架常受限于数据不平衡和过时问题。本文提出ASTRAL,一种自动化生成并执行测试用例(即提示)以评估LLM安全性的工具。首先,引入新颖的黑盒覆盖率标准,在多种安全类别及语言特征(如不同写作风格与说服技巧)间生成平衡且多样的不安全输入。其次,提出基于大模型的方法,利用检索增强生成(RAG)、少样本提示策略和网络浏览,生成最新信息驱动的测试输入。最后,沿用当前自动化测试技术,使用大模型作为测试判别器,自动区分安全与不安全输出,实现全自动化测试。在多个知名大模型上的评估显示:i) GPT3.5作为测试判别器表现最佳,准确识别不安全输出,甚至优于更先进的GPT-4及专为检测不安全输出设计的LlamaGuard;ii) 本方法在相同测试输入数量下,可发现近乎两倍的不安全行为;iii) 黑盒覆盖率准则结合网络浏览,能有效引导模型生成最新、最相关的不安全测试输入,显著提升不安全行为的检测数量。

原文摘要 · Abstract (English)

Large Language Models (LLMs) have recently gained attention due to their ability to understand and generate sophisticated human-like content. However, ensuring their safety is paramount as they might provide harmful and unsafe responses. Existing LLM testing frameworks address various safety-related concerns (e.g., drugs, terrorism, animal abuse) but often face challenges due to unbalanced and obsolete datasets. In this paper, we present ASTRAL, a tool that automates the generation and execution of test cases (i.e., prompts) for testing the safety of LLMs. First, we introduce a novel black-box coverage criterion to generate balanced and diverse unsafe test inputs across a diverse set of safety categories as well as linguistic writing characteristics (i.e., different style and persuasive writing techniques). Second, we propose an LLM-based approach that leverages Retrieval Augmented Generation (RAG), few-shot prompting strategies and web browsing to generate up-to-date test inputs. Lastly, similar to current LLM test automation techniques, we leverage LLMs as test oracles to distinguish between safe and unsafe test outputs, allowing a fully automated testing approach. We conduct an extensive evaluation on well-known LLMs, revealing the following key findings: i) GPT3.5 outperforms other LLMs when acting as the test oracle, accurately detecting unsafe responses, and even surpassing more recent LLMs (e.g., GPT-4), as well as LLMs that are specifically tailored to detect unsafe LLM outputs (e.g., LlamaGuard); ii) the results confirm that our approach can uncover nearly twice as many unsafe LLM behaviors with the same number of test inputs compared to currently used static datasets; and iii) our black-box coverage criterion combined with web browsing can effectively guide the LLM on generating up-to-date unsafe test inputs, significantly increasing the number of unsafe LLM behaviors.

大模型安全自动化测试提示工程

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。