开始之前
生成器交回来的,通常是提示词模板。它是带有命名空位的提示词,这些空位叫变量,由你或你的代码稍后填入,比如客户的邮件或公司名称。生成器背后的那段指令,通称元提示词(meta-prompt)。
本课讲两条路线。Anthropic 的路线是它的 cookbook 里的一个 notebook,需要一个 Anthropic API 密钥,以及能运行 notebook 的地方,比如 Colab。OpenAI 的路线是 Playground 里的 Generate 按钮,它的指南还把按钮背后的元提示词整段印了出来。Anthropic 的 notebook 说,它写出的提示词不保证最优,所以要准备好修改。变量的更多细节,见提示词模板那一课。
用 Anthropic 的 metaprompt 处理一个任务
这个 notebook 称自己是解决“空白页问题”的工具。你输入一个任务,也可以写上想用的变量名,它就给你一个可以反复修改的起点。它是为单轮问答式提示词设计的,不适用于多轮对话。metaprompt notebook里是一条很长的提示词,里面放着针对不同任务的示例提示词。notebook 自己的文字说是大约六个,它印出的全文里有五个。你的任务放在最后,后面跟三条指令:列出输入,规划结构,再写出指令。它还告诉模型,篇幅很长的变量值要放在使用它们的指示之前。
需要你改的单元格很短。下面是 notebook 里的原文,带着它默认的任务和两个变量:
TASK = "Draft an email responding to a customer complaint" # Replace with your task!
# Optional: specify the input variables you want Claude to use. If you want
# Claude to choose them for you, leave VARIABLES as an empty list.
VARIABLES = ["CUSTOMER_EMAIL", "COMPANY_NAME"]
# TASK = "Choose an item from a menu for me given my preferences"
# VARIABLES = ["MENU", "PREFERENCES"]- 在 Colab 或任何能运行 notebook 的地方打开它,运行第一个代码单元格,它会安装
anthropic包。 - 把 API 密钥填在 notebook 指定的位置,或者留空,改用环境变量
ANTHROPIC_API_KEY。 - 把 TASK 这一行换成你自己的任务。写清楚模型要做什么、为谁做,不要只写一个主题。
- 想指定变量名,就用大写字母列出来,notebook 会把它们写成
{$NAME}的形式。列表留空,就由 Claude 自己起名。 - 改了任务之后,到靠近底部的测试部分,把变量的示例值填进
VARIABLE_VALUES。 - 运行所有单元格。notebook 提醒,metaprompt 很长,要等 20 到 30 秒。你的模板会出现在第 1 部分。
用 OpenAI 的元提示词生成提示词
OpenAI 的提示词生成指南说,Playground 里的 Generate 按钮能根据任务描述生成提示词、函数和 schema。生成提示词用的是元提示词,建立在 OpenAI 的提示词工程最佳实践之上,每种输出类型各有一条,比如音频。指南把文本元提示词整段印在下面。它的代码把这段话作为系统消息发出去,用户消息是 Task, Goal, or Current Prompt: 加上你的任务。
它本身就是纯文本,所以你也可以把它粘贴在聊天窗口的最上面,下面写上你的任务。这个捷径是本课的建议,指南里没有写。
Given a task description or existing prompt, produce a detailed system prompt to guide a language model in completing the task effectively.
# Guidelines
- Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.
- Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.
- Reasoning Before Conclusions**: Encourage reasoning steps before any conclusions are reached. ATTENTION! If the user provides examples where the reasoning happens afterward, REVERSE the order! NEVER START EXAMPLES WITH CONCLUSIONS!
- Reasoning Order: Call out reasoning portions of the prompt and conclusion parts (specific fields by name). For each, determine the ORDER in which this is done, and whether it needs to be reversed.
- Conclusion, classifications, or results should ALWAYS appear last.
- Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.
- What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.
- Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.
- Formatting: Use markdown features for readability. DO NOT USE ``` CODE BLOCKS UNLESS SPECIFICALLY REQUESTED.
- Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.
- Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.
- Output Format: Explicitly the most appropriate output format, in detail. This should include length and syntax (e.g. short sentence, paragraph, JSON, etc.)
- For tasks outputting well-defined or structured data (classification, JSON, etc.) bias toward outputting a JSON.
- JSON should never be wrapped in code blocks (```) unless explicitly requested.
The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no "---")
[Concise instruction describing the task - this should be the first line in the prompt, no section header]
[Additional details as needed.]
[Optional sections with headings or bullet points for detailed steps.]
# Steps [optional]
[optional: a detailed breakdown of the steps necessary to accomplish the task]
# Output Format
[Specifically call out how the output should be formatted, be it response length, structure e.g. JSON, markdown, etc]
# Examples [optional]
[Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]
[If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]
# Notes [optional]
[optional: edge cases, details, and an area to call or repeat out specific important considerations]- Reasoning Before Conclusions 要求生成器把推理放在任何结论之前,示例如果先给结论,就把顺序倒过来。
- Preserve User Content 会保留你的规则、示例、变量和占位符,所以把手头已有的内容一并贴进任务里。
- Constants 要求把指南、评分标准和示例直接写进提示词,因为它们不会受到提示词注入的影响。
- Output Format 要求详细写明输出格式,包括长度和语法,分类任务倾向于输出 JSON。
- 指南还说,OpenAI 以后可能引入更先进的技术,比如 DSPy,第 4 课会讲 DSPy。
两个生成器的区别
两者都要求模型把推理或理由放在结论之前。区别在于怎么运行、交回来的是什么,以及对输出格式说了多少:OpenAI 的元提示词有一条 Output Format 规则,而 notebook 只说想让输出放在标签里时,要写明标签的名字。
| Anthropic metaprompt | OpenAI Generate | |
|---|---|---|
| 在哪里运行 | 带 API 密钥的 notebook | Playground 按钮,或通过 API 调用元提示词 |
| 为谁设计 | 单轮问答式提示词 | 针对任务的系统提示词 |
| 从什么出发 | 任务,加可选的变量名 | 任务描述,或已有的提示词 |
| 变量 | {$NAME} 占位符 | 保留你的变量,示例里用 [方括号] |
| 推理排在结论前面 | 是 | 是 |
| 固定的输出部分 | Inputs、Instructions Structure、Instructions | Steps、Output Format、Examples、Notes |
| 还能生成函数和 schema | 否 | 是 |
来源:Anthropic on GitHub: claude-cookbooks, metaprompt notebook (2026年11月6日 查阅);OpenAI Docs: Prompt generation (2026年11月6日 查阅)
Anthropic 说它的 Console 生成器做了什么
Anthropic 也在 Console 里内置了提示词生成器。它的 X 账号在 2024 年 5 月 10 日宣布了这个功能:描述你想达成的目标,Claude 会用思维链推理这类技术写出提示词。帖子只讲了技术名称,没有讲步骤,所以 Console 里的具体措辞在这里读不到。cookbook 里的 metaprompt 是全文公开的那一个。
描述你想达成的目标,Claude 会用思维链推理这类提示词工程技术,写出更有效、更精准、更可靠的提示词。
X 官方嵌入卡片的截图,拍摄于 2026 年 11 月 6 日,时间为 UTC。点击截图可到 X 上打开原帖。
检查生成器写出的结果
生成的提示词看上去总像是完成品,其实未必,因为它总是带着整齐的小标题和笃定的语气出现。下面五项检查来自两个生成器自己的要求,这张表是本课整理的。
| 检查什么 | 缺了怎么办 | 哪个生成器提出这个要求 |
|---|---|---|
| 每个变量都放在自己的标签里,篇幅长的值排在指令之前 | 用 XML 标签把变量包起来,并移到前面 | Anthropic 的 metaprompt |
| 推理或理由排在结论之前 | 要求先写推理,最后再打分 | 两个生成器都有 |
| 写明了输出格式,包括长度和语法 | 把格式写进去,并附一个样例 | OpenAI 元提示词的 Output Format |
| 你自己的规则和示例还在 | 从原稿里把它们贴回去 | OpenAI 元提示词的 Preserve User Content |
| 没有残留 [Your Name] 这样的占位符 | 手动填写,因为 notebook 只替换 {$NAME} 变量 | Anthropic 的 notebook |
常见错误
- 任务只写三个字。“写邮件”让生成器无从下手,要说清邮件发给谁、输入是什么、好的结果长什么样。
- 把一条已经好用的长提示词交给生成器,还指望得到一份全新的改写。对复杂的提示词,OpenAI 的元提示词只补充清晰度和缺少的部分,原有结构保持不变。
- 用 metaprompt 做多轮对话的聊天机器人。Anthropic 是为单轮提示词设计的。
- 改了任务却忘了
VARIABLE_VALUES。notebook 会用input()逐个向你要值,没法提问时就用占位文字。 - 直接存下第一版草稿。Anthropic 明说了,不要害怕修改它。
动手试试
- 挑一件你在工作里反复做的事,比如回复投诉,或给客服工单打标签。
- 把它写成一行任务,再加上会变化的输入的名字。
- 从 notebook 拿一版草稿,从 OpenAI 的元提示词拿一版草稿,再用检查表把两版各过一遍。
- 把较好的一版放到三个真实输入上跑,记下它在哪里出错。这些错误,正是后面几课帮你修正的东西。
下一课:改进你已有的提示词
生成的提示词只是第一版。第 2 课从一条已经存在的提示词出发,讲 OpenAI 的 optimizer 和编辑元提示词怎样改写它,也转述 Anthropic 对 prompt improver 的说法。
自测一下
Anthropic 的 metaprompt notebook 是为哪一类提示词设计的?
查看答案
A. 单轮问答式提示词 notebook 写明,它是为单轮问答式提示词设计的,不适用于多轮对话。
OpenAI 的元提示词怎样处理生成提示词里的推理和结论?
查看答案
C. 把推理步骤放在任何结论之前 它的 Reasoning Before Conclusions 准则要求先推理,并说结论、分类和结果永远要放在最后。
在 notebook 里,VARIABLES = ["CUSTOMER_EMAIL", "COMPANY_NAME"] 起什么作用?
查看答案
B. 指定生成的模板必须使用的输入变量 notebook 要求模型恰好使用这些输入变量,不能多也不能少,写成 {$NAME} 的形式。
你有一条已经好用的长提示词。OpenAI 的元提示词怎样对待复杂的提示词?
查看答案
D. 补充清晰度和缺少的部分,但不改变结构 它的 Minimal Changes 准则说,已有的提示词只有在简单时才改进。对复杂的提示词,它补充清晰度和缺少的部分,不改变原有结构。
常见问题
什么是 AI 提示词生成器?
它是一种工具,或者一条提示词,能把一句简短的任务描述变成提示词的第一稿。Anthropic 和 OpenAI 各有一个。它不可能知道的东西要由你补上,比如你的产品、你的语气,以及什么样的回答算好。
什么是 metaprompt?
它是输出结果为另一条提示词的提示词。Anthropic 的 notebook 用 metaprompt 这个名字,OpenAI 的指南则用 meta-prompt 称呼 Generate 按钮背后的指令。
我能用 ChatGPT 或 Claude 帮我写提示词吗?
可以。直接让聊天应用为你的任务写提示词是行得通的,而元提示词多给了一套固定的规则,让每一稿都遵循同样的结构。想重复使用,就先粘贴它的文本,再写你的任务。
生成的提示词比我自己写的更好吗?
两家都没有这样说。OpenAI 把生成看作快速上手的办法。拿同样的输入分别跑生成的提示词和你自己写的,留下回复更让你满意的那一条,第 3 课会教你怎么比。
Anthropic 的 metaprompt 适用于多轮对话的聊天机器人吗?
它写的是一问一答,聊天机器人来回多轮的情形,不在 notebook 声称能处理的范围内。做聊天产品时,手动改写生成的草稿,再用多轮对话去测。
怎样给提示词生成器写好任务描述?
说清提示词是给谁用的,输入什么,要输出什么,以及哪些规则必须成立。notebook 自带的示例,从“按评分标准给简历打分”到“用简单的话解释复杂的科学概念”,各自写明了一项工作。
资料来源
- Anthropic on GitHub: claude-cookbooks, metaprompt notebook https://github.com/anthropics/claude-cookbooks/blob/main/misc/metaprompt.ipynb
- OpenAI Docs: Prompt generation https://developers.openai.com/api/docs/guides/prompt-generation
- X: Anthropic (@AnthropicAI) on generating prompts in the Anthropic Console https://x.com/AnthropicAI/status/1788958483565732213

