arXiv:2501.12521cs.SEcs.AI2025-01

自动检测修复开发者提示词中的偏见、漏洞和低效问题

An Empirically-grounded tool for Automatic Prompt Linting and Repair: A Case Study on Bias, Vulnerability, and Optimization in Developer Prompts

  • 基于实证分析构建提示词诊断工具,识别三类核心问题
  • 在2173个提示词中发现3.46%含偏见,10.75%易遭注入攻击
  • 提供VSCode插件,可直接集成到开发流程中优化提示词

大型语言模型的快速发展推动其被广泛应用于各类软件系统中。许多系统通过提示词与这些黑箱模型交互,结合自然语言与运行时动态值完成从情感分析到问答等任务。这类融合自然语言与编程/标记语言结构的提示词被称为开发者提示词(Dev Prompts)。由于其特殊性,传统软件评估方法不适用。为此,本文提出PromptDoctor,一款专为检测和修复开发者提示词中偏见、漏洞及性能低下问题而设计的工具。在对40,573个提示词中随机抽取的2,173个样本分析中发现:3.46%存在偏见,10.75%易受提示注入攻击;另有3,310个提示词具备自动化优化潜力。应用PromptDoctor后,成功去偏见68.29%的有问题提示词,加固41.81%脆弱提示词,提升37.1%低效提示词表现。最后,我们开发了PromptDoctor VSCode扩展,使开发者可在原有工作流中便捷优化提示词。数据与代码已公开。

原文摘要 · Abstract (English)

The tidal wave of advancements in Large Language Models (LLMs) has led to their swift integration into application-level logic. Many software systems now use prompts to interact with these black-box models, combining natural language with dynamic values interpolated at runtime, to perform tasks ranging from sentiment analysis to question answering. Due to the programmatic and structured natural language aspects of these prompts, we refer to them as Developer Prompts. Unlike traditional software artifacts, Dev Prompts blend natural language instructions with artificial languages such as programming and markup languages, thus requiring specialized tools for analysis, distinct from classical software evaluation methods. In response to this need, we introduce PromptDoctor, a tool explicitly designed to detect and correct issues of Dev Prompts. PromptDoctor identifies and addresses problems related to bias, vulnerability, and sub-optimal performance in Dev Prompts, helping mitigate their possible harms. In our analysis of 2,173 Dev Prompts, selected as a representative sample of 40,573 Dev Prompts, we found that 3.46% contained one or more forms of bias, 10.75% were vulnerable to prompt injection attacks. Additionally, 3,310 were amenable to automated prompt optimization. To address these issues, we applied PromptDoctor to the flawed Dev Prompts we discovered. PromptDoctor de-biased 68.29% of the biased Dev Prompts, hardened 41.81% of the vulnerable Dev Prompts, and improved the performance of 37.1% sub-optimal Dev Prompts. Finally, we developed a PromptDoctor VSCode extension, enabling developers to easily enhance Dev Prompts in their existing development workflows. The data and source code for this work are available at

提示词工程安全检测LLM应用开发工具

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