本指南是一种方法,而不是一堆小贴士。按顺序完成这七个步骤,你就会得到一个提示词:它说明任务,带有恰当的背景,返回可预测的格式,并且已经用真实输入检查过。
贯穿全文的示例,是一个把客户反馈整理成产品报告的提示词。
步骤 1:用一句话写出目标
先写一句祈使句,点明要得到什么成果。如果写不出来,说明任务还没有定义清楚。
Classify each piece of customer feedback by product area and sentiment.
以动词开头:分类、总结、提取、撰写、比较、审查。如果提示词只描述材料(“这是我们的反馈数据”),模型就得猜你想拿它做什么。
步骤 2:补上模型缺少的背景
列出一位称职的新同事需要知道的事:输出给谁看,产品有哪些领域,什么算负面。
The feedback comes from in-app surveys for a project management tool.
Product areas: Boards, Timeline, Reports, Integrations, Billing.
The report is read by product managers who decide what to fix next.
只包含会改变回答的背景。不影响输出的背景会消耗 token,并稀释指令。
步骤 3:写明要求和约束
把期望变成一份简短的清单。涉及大小时用数字,并说明在棘手情形下该怎么做。
Requirements:
- Assign exactly one product area per item. Use "Other" if none fits.
- Sentiment is one of: positive, neutral, negative.
- Quote the phrase that justifies the sentiment, 12 words at most.
- If an item is not in English, classify it and add "language": "<code>".
宁可告诉模型该做什么,也不要只说要避免什么。“使用平实的语言”比“不要用行话”效果更好,因为禁令只点出你想去掉的东西,却没有给出替代方案。
步骤 4:定义输出格式
如果由代码读取答案,就要精确地指定格式。如果由人阅读,就指定结构和篇幅。
Return a JSON array. Each element:
{"id": string, "area": string, "sentiment": string, "evidence": string}
Return only the JSON, with no commentary.
缺少输出格式是结果不一致的最常见原因之一。关于 schema 和验证,请参阅结构化输出提示词指南。
步骤 5:把指令与数据分开
把可变的输入放进分隔符里,让模型不会把它误认为指令。这也能阻挡最简单形式的提示词注入。
<feedback>
{{feedback_items}}
</feedback>
步骤 6:如果任务需要,就加入示例
如果规则很容易写清楚,就省去示例。如果任务依赖判断,比如什么算“neutral”,就展示两三组输入输出,覆盖临界情形。如何挑选,请参阅零样本、单样本与少样本提示词。
步骤 7:测试、衡量、修订
用能代表真实使用的输入运行提示词,包括棘手的:空输入、超长输入、混合语言和带敌意的文本。记下失败之处,改动一处,再运行一次。这个循环在迭代式提示词优化和提示词评估中有详细介绍。
在用模型测试之前,先清除那些不需要模型就能发现的问题。PromptFlowEngine 提示词分析器会检查是否缺少目标、措辞含糊、大小未量化、指令冲突、缺少格式以及变量未加分隔。
最终的提示词
You are a product analyst.
## Task
Classify each piece of customer feedback by product area and sentiment.
## Context
The feedback comes from in-app surveys for a project management tool.
Product areas: Boards, Timeline, Reports, Integrations, Billing.
The report is read by product managers who decide what to fix next.
## Requirements
- Assign exactly one product area per item. Use "Other" if none fits.
- Sentiment is one of: positive, neutral, negative.
- Quote the phrase that justifies the sentiment, 12 words at most.
## Output format
Return a JSON array. Each element:
{"id": string, "area": string, "sentiment": string, "evidence": string}
Return only the JSON.
## Input
<feedback>
{{feedback_items}}
</feedback>
一份值得保留的检查清单
| 问题 | 如果答案是否 |
|---|---|
| 第一行是否说明了要做什么? | 添加目标。 |
| 新同事是否有足够的背景? | 添加受众、领域和定义。 |
| 大小是否用数字给出? | 替换“短”和“几个”。 |
| 是否指定了输出格式? | 添加格式和篇幅。 |
| 输入是否与指令分开? | 用标签包裹变量。 |
| 是否用困难的输入运行过? | 建立一个小型测试集。 |