arXiv:2508.06942cs.SEcs.AI2025-08ICLR被引 7

用软件工程方法让自然语言提示更准确可靠,提升人机交互效果。

When Prompt Engineering Meets Software Engineering: CNL-P as Natural and Robust "APIs'' for Human-AI Interaction

  • 结合提示工程与软件工程,设计结构化自然语言提示规范
  • 实验表明该方法显著提升大模型输出质量与一致性
  • 适合希望高效使用大模型的开发者和非技术用户

随着大语言模型能力增强,其在智能客服、代码生成和知识管理等领域广泛应用。自然语言提示作为人与大模型交互的‘API’,其质量直接影响效果。本文提出受控自然语言提示(CNL-P),融合提示工程最佳实践与软件工程核心原则,引入精确语法结构与严格语义规范,有效消除自然语言歧义,实现用户意图的声明式、结构化表达。这使大模型能更准确理解并执行指令,提升输出的一致性与质量。我们还开发了基于大模型的NL2CNL-P转换工具,支持用户以自然语言写提示,自动转为规范格式,降低学习门槛。特别地,首次将静态分析技术应用于自然语言,构建了校验工具,检查提示的语法与语义正确性。大量实验证明,CNL-P通过提示工程与软件工程的有机融合,显著提升大模型响应质量。我们认为,该方法可弥合新兴提示工程与传统软件工程的鸿沟,为以自然语言为核心的新型编程范式奠定基础。

原文摘要 · Abstract (English)

With the growing capabilities of large language models (LLMs), they are increasingly applied in areas like intelligent customer service, code generation, and knowledge management. Natural language (NL) prompts act as the ``APIs'' for human-LLM interaction. To improve prompt quality, best practices for prompt engineering (PE) have been developed, including writing guidelines and templates. Building on this, we propose Controlled NL for Prompt (CNL-P), which not only incorporates PE best practices but also draws on key principles from software engineering (SE). CNL-P introduces precise grammar structures and strict semantic norms, further eliminating NL's ambiguity, allowing for a declarative but structured and accurate expression of user intent. This helps LLMs better interpret and execute the prompts, leading to more consistent and higher-quality outputs. We also introduce an NL2CNL-P conversion tool based on LLMs, enabling users to write prompts in NL, which are then transformed into CNL-P format, thus lowering the learning curve of CNL-P. In particular, we develop a linting tool that checks CNL-P prompts for syntactic and semantic accuracy, applying static analysis techniques to NL for the first time. Extensive experiments demonstrate that CNL-P enhances the quality of LLM responses through the novel and organic synergy of PE and SE. We believe that CNL-P can bridge the gap between emerging PE and traditional SE, laying the foundation for a new programming paradigm centered around NL.

提示工程自然语言大模型编程范式

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