跳到主要内容Skip to main content
← 深水指南Guides

提示词的解剖结构Anatomy of a prompt

提示词与工作流Prompts & workflows · 提示词指南Prompt guide

把提示词拆成角色、指令、分隔符、示例、推理五种块,讲清各块的作用、摆法与常见失效。

Break a prompt into roles, instructions, delimiters, examples, and reasoning — what each block does, where it goes, and how it fails.

提示词效果未实测。Prompt effect has not been tested.

提示词是可复跑的模板,不是效果承诺。换模型、换版本、换输入都可能改变结果;用本页的检查点自己核对,并把官方出处当作机制依据而不是效果保证。A prompt is a re-runnable template, not a promise of results. Changing the model, version or input can change the outcome. Use the checkpoints on this page to verify it yourself, and treat the official sources as evidence of mechanism rather than a guarantee of effect.

这一篇讲什么What this guide covers

提示词解剖,就是把一条提示词拆成职责明确的块。 角色、指令、分隔符、示例、推理,各块解决不同的问题。 The Prompt Report 综述整理了 58 种提示技术与 33 个术语(论文口径)。 技术名目虽多,骨架大同小异。这篇讲骨架怎么搭、块怎么摆。 这些技术的效果未实测;机制与结论均出自官方文档和论文。

Prompt anatomy means breaking a prompt into blocks with clear responsibilities. Roles, instructions, delimiters, examples, reasoning — each block solves a different problem. The Prompt Report survey organizes 58 prompting techniques and 33 vocabulary terms (the paper's own count). The names proliferate, but the skeleton is much the same. This guide covers how to assemble it and where each block goes. We have not run hands-on tests of these techniques; mechanisms and conclusions come from official docs and papers.

消息角色:对话的骨架Message roles: the conversation skeleton

API 收到的不是一整段文本,而是带角色的消息序列。 Anthropic 官方教程以 Messages API 为例: messages 是 user 与 assistant 交替的数组,首条必须是 user。 system 是独立参数,放任务背景、规则与指引,不与对话混排。 max_tokens 是硬上限:到了就停,可能停在半句话。

OpenAI 的 GPT-4.1 指南同样按角色组织: 系统提示放行为规则,工具走 API 的 tools 字段。 官方不建议把工具描述手工塞进提示词,再自写解析器。 角色分错,后面所有块都摆不稳。

What the API receives is not one blob of text but a sequence of messages with roles. Anthropic's official tutorial uses the Messages API as its example: messages is an array of alternating user and assistant turns, and the first message must be user. system is a separate parameter for task background, rules, and guidelines — kept apart from the conversation. max_tokens is a hard ceiling: generation stops there, possibly mid-sentence.

OpenAI's GPT-4.1 guide organizes by role the same way: behavioral rules go in the system prompt, tools go through the API's tools field. The official advice is against hand-injecting tool descriptions into the prompt and writing your own parser. Get the roles wrong and no later block sits on a stable base.

指令块与分隔符Instruction blocks and delimiters

OpenAI 给出的起点骨架,按需增删: 角色与目标 → 指令(可分子类)→ 推理步骤 → 输出格式 → 示例 → 上下文 → 收尾指令。

分隔符决定模型能否分清各块。 GPT-4.1 指南的建议:从 Markdown 标题起步; XML 适合精确包裹、嵌套和挂元数据;JSON 更啰嗦、要转义。 长上下文喂大量文档时,OpenAI 自测 XML 表现好、JSON 明显差。 这是厂商自述的测试结论,换模型要重新验证。

OpenAI's starting skeleton, add or remove sections as needed: role and objective → instructions (with sub-categories) → reasoning steps → output format → examples → context → final instructions.

Delimiters decide whether the model can tell the blocks apart. The GPT-4.1 guide's advice: start with Markdown headers; XML suits precise wrapping, nesting, and attaching metadata; JSON is more verbose and needs escaping. When feeding many documents in long context, OpenAI's own testing found XML performed well and JSON notably poorly. That is a vendor-reported test result — re-verify when you change models.

示例与推理块Examples and reasoning blocks

示例块用「示范」代替「描述」。 The Prompt Report 把这类技术归为 few-shot:给若干输入输出对,让模型照着做。 不给示例叫 zero-shot,给一个例子叫 one-shot。 GPT-4.1 指南提醒:示例里展示的关键行为,规则里也要写明,两处对齐。

推理块让模型先想后答。 GPT-4.1 不是推理模型,但可以用提示诱导它逐步规划。 代价写在官方指南里:更多输出 token,更高延迟。 从简单的「逐步思考」起步,再按失败案例补充具体策略。

The examples block demonstrates instead of describing. The Prompt Report classifies this family as few-shot: give input-output pairs and let the model follow suit. No examples is zero-shot; one example is one-shot. The GPT-4.1 guide's reminder: key behaviors shown in examples must also be stated in the rules — keep the two aligned.

The reasoning block makes the model think before answering. GPT-4.1 is not a reasoning model, but a prompt can induce step-by-step planning. The cost is stated in the official guide: more output tokens, higher latency. Start with a simple "think step by step", then add concrete strategies based on failure cases.

位置与顺序Placement and order

块的内容重要,摆的位置也重要。 GPT-4.1 指南的长上下文实验结论: 指令放在上下文首尾两端,好于只放一端; 只放一处时,放上下文上方好于下方。 指令互相冲突时,GPT-4.1 倾向服从靠近结尾的那条。 收尾指令不是客套,是最后一道纠偏。

What the blocks say matters; where they sit matters too. The GPT-4.1 guide's long-context experimental findings: instructions at both the beginning and the end of the context beat instructions at only one end; if placed only once, above the context beats below it. When instructions conflict, GPT-4.1 tends to follow the one closer to the end. The closing instruction is not a courtesy — it is the last corrective.

失败模式Failure modes

  1. 字面服从:要求「回答前必须调工具」,信息不足时模型可能编造参数。官方建议补一句:信息不够就向用户要。
  2. 示例复读:给了示范短语,模型可能逐字照搬。要明确要求按情况变化。
  3. 自由发挥:没约束时,模型爱加解释和多余格式。用指令和示例收住。
  4. 迁移失效:换模型后,旧提示词里靠模型脑补的隐含规则会失效,要显式写清。

官方自己的告诫:没有放之四海皆准的建议。 提示词工程是经验学科,要配评测持续迭代。

  1. Literal obedience: demand "call a tool before answering" and the model may fabricate arguments when information is missing. The official fix: add "ask the user when you lack information".
  2. Example parroting: given sample phrases, the model may repeat them verbatim. Explicitly require variation.
  3. Improvisation: without constraints the model adds explanations and extra formatting. Rein it in with instructions and examples.
  4. Migration breakage: after a model switch, implicit rules the old model used to infer stop working — spell them out.

The official caveat: no advice is one-size-fits-all. Prompt engineering is an empirical discipline; pair it with evals and keep iterating.

出处Sources

核验日 2026-11-07,三条均直抓成功。 OpenAI 与 Anthropic 的文档主站本次网络不可达,官方内容取自两家官方仓库的 raw 文件。

Verified 2026-11-07; all three fetched directly with HTTP 200. The OpenAI and Anthropic doc sites were unreachable from this network; official content was taken from raw files in both vendors' official repositories.

出处Sources

来源Source链接URL
OpenAI Cookbook · GPT-4.1 Prompting Guide(官方仓库 raw 文件,2026-11-07 直抓 200)OpenAI Cookbook · GPT-4.1 Prompting Guide (official repo raw file, direct fetch 200 on 2026-11-07)https://raw.githubusercontent.com/openai/openai-cookbook/main/examples/gpt4-1_prompting_guide.ipynbhttps://raw.githubusercontent.com/openai/openai-cookbook/main/examples/gpt4-1_prompting_guide.ipynb
Anthropic 官方教程 · Basic Prompt Structure(官方仓库 raw 文件,2026-11-07 直抓 200)Anthropic official tutorial · Basic Prompt Structure (official repo raw file, direct fetch 200 on 2026-11-07)https://raw.githubusercontent.com/anthropics/courses/master/prompt_engineering_interactive_tutorial/Anthropic%201P/01_Basic_Prompt_Structure.ipynbhttps://raw.githubusercontent.com/anthropics/courses/master/prompt_engineering_interactive_tutorial/Anthropic%201P/01_Basic_Prompt_Structure.ipynb
The Prompt Report 论文(arXiv 2406.06608,2026-11-07 直抓摘要页)The Prompt Report paper (arXiv 2406.06608, abstract page direct-fetched 2026-11-07)https://arxiv.org/abs/2406.06608https://arxiv.org/abs/2406.06608

资料快照日期:2026-11-07;单项复核范围与日期见对应正文或来源记录。产品功能与条款可能变化,使用前请核对原始来源。Source snapshot: 2026-11-07; item-specific rechecks and their scope are recorded in the text or source notes. Features and terms may change; check the original sources before use.