通过对比分析 Claude 的系统 prompt,深入理解大模型的安全设计和能力权衡。对构建 AI Agent 的程序员有参考价值。
Claude 4 的 system prompt 与我们上个月分析的 3.7 版本非常相似。两者几乎完全一致,但散落在全文中的改动,充分揭示了 Anthropic 如何使用 system prompt 来定义其应用,尤其是用户体验(UX),以及这些 prompt 如何融入其开发周期。
下面我们逐一看看其中值得关注的变化。
我们曾推测,许多针对常见 LLM“陷阱”的零散指令其实都是热修复:在更完善的解决方案落地之前,先用简短指令来纠正不符合预期的行为。Claude 4.0 的 system prompt 验证了这一假设——3.7 版本中的热修复已被全部移除。不过,如果我们用其中一个“陷阱”来测试 Claude,例如“How many R’s are in Strawberry?”,它已经不会再中招。几乎可以肯定,3.7 版本通过热修复实现的这些行为,已经在 4.0 的 post-training 阶段通过 reinforcement learning 得到了解决。
当新模型在训练中已经学会避免在诗歌里使用“陈词滥调的意象”,并能在统计单词或字母时逐步思考,也就不再需要通过 system prompt 来修补这些问题。
4.0 的训练完成后,又会出现需要通过 system prompt 解决的新问题。例如,Sonnet 4.0 的 system prompt 中新增了这样一条指令:
Claude never starts its response by saying a question or idea or observation was good, great, fascinating, profound, excellent, or any other positive adjective. It skips the flattery and responds directly.
这项热修复显然受到了 OpenAI 那次“谄媚式”GPT-4o 翻车事件的启发。这次失误大约发生在一个月前,对 Anthropic 团队来说已经太晚,来不及针对这种行为重新开展训练。于是,它就被写进了 system prompt!
早在 2023 年,当用户询问发生在知识截止日期之后的话题时,chatbot 经常会不知所措。早期用户逐渐明白,LLM 的知识被冻结在某个时间点,但普通用户在询问近期新闻时,仍经常被幻觉和错误绊倒。Perplexity 曾凭借能够为许多用户取代 Google 的搜索能力脱颖而出,但如今,这项优势已经不复存在。
到了 2025 年,Search 已经成为 ChatGPT 和 Claude 的一等组件。这份 system prompt 表明,Anthropic 正在加大投入,追赶 OpenAI。
Claude 3.7 收到的指令是这样的:
Claude answers from its own extensive knowledge first for most queries. When a query MIGHT benefit from search but it is not extremely obvious, simply OFFER to search instead.
旧版 Claude 会先询问用户是否允许搜索。新版 Claude 则不再犹豫。更新后的指令如下:
Claude answers from its own extensive knowledge first for stable information. For time-sensitive topics or when users explicitly need current information, search immediately.
整个 prompt 中的相关措辞都已更新。搜索不再只在获得用户许可后进行;只要有必要,就鼓励 Claude 在第一次回答时直接搜索。
这项改动暗示了两个变化。第一,Anthropic 或许对自己的搜索工具,以及模型使用该工具的方式更有信心。Claude 不仅被鼓励主动搜索,该公司还把这项能力拆分成了专门的搜索 API。第二,Anthropic 观察到,越来越多的用户开始使用 Claude 完成搜索任务。如果一定要猜,我认为后者才是推动这次改动的主要原因。这也是一个强烈信号:chatbot 正在日益蚕食 Google 的搜索流量。
这是另一个 system prompt 根据 Anthropic 观察到的用户行为作出调整的例子。在一份说明何时应使用 Claude artifacts 的项目列表中,Anthropic 对某个使用场景进行了更细致的补充。Claude artifacts 指的是对话线程之外的独立窗口,Claude 会在其中生成篇幅较长的内容。
Claude 3.7 的 system prompt 在“You must use artifacts for:”之后写道:
“Structured documents with multiple sections that would benefit from dedicated formatting”
现在则变成了:
Structured content that users will reference, save, or follow (such as meal plans, workout routines, schedules, study guides, or any organized information meant to be used as a reference).
这是一个很好的例子,说明 Anthropic 如何根据观察到的实际用法,通过 system prompt 持续调整 chatbot 的行为。system prompt 正在对 Claude 的工作方式进行编程,只不过使用的是自然语言。
prompt 中有几处改动表明,上下文限制已经开始影响用户,尤其是那些使用 Claude 编程的用户:
For code artifacts: Use concise variable names (e.g., i, j for indices, e for event, el for element) to maximize content within context limits while maintaining readability
作为一个非常看重变量定义清晰度的人,这让我有些难受,但我也能理解。Claude 4 发布时,我注意到的唯一遗憾就是它的上下文限制:只有 200,000 tokens,而 Gemini 2.5 Pro 和 ChatGPT 4.1 的上限都是 100 万。人们对此感到失望。
Anthropic 可能是出于效率考虑而限制上下文长度,同时依靠其出色的 token caching;也可能只是无法达到 Google 和 ChatGPT 已经实现的效果。不过,最近已经有多项研究发现,随着上下文长度不断增加,模型性能并不能始终保持稳定。下面是 DataBricks 一个团队根据去年 8 月发表的研究绘制的图表:
我曾遇到过这样的情况:一些不那么严谨的竞争对手专注于发布抢眼的数字,即使这样做会导致更差的实际结果。例如在地理空间领域,很多公司会大肆宣扬其数据集中所有元素的总数量,即便其中许多元素的置信度非常低。我倾向于认为,在这个竞争极其激烈、由 benchmark 驱动的 AI 市场中,也存在一些类似的现象。
无论如何,我认为所有编程工具都会开始内置这类捷径,以节省上下文空间。更短的函数名、更精简的注释……所有手段都有可能被采用。
Claude 3.7 收到的指令是,不得帮助用户制造生物武器或核弹。Claude 4.0 则把恶意代码加入了禁止事项清单:
Claude steers away from malicious or harmful use cases for cyber. Claude refuses to write code or explain code that may be used maliciously; even if the user claims it is for educational purposes. When working on files, if they seem related to improving, explaining, or interacting with malware or any malicious code Claude MUST refuse. If the code seems malicious, Claude refuses to work on it or answer questions about it, even if the request does not seem malicious (for instance, just asking to explain or speed up the code). If the user asks Claude to describe a protocol that appears malicious or intended to harm others, Claude refuses to answer. If Claude encounters any of the above or any other malicious use, Claude does not take any actions and refuses the request.
可以理解,这里包含了大量注意事项和判断条件。既要拒绝提供这类帮助,又不能妨碍常规的编程辅助,想必是一项需要精细拿捏的工作。
回顾上面的改动——老实说,这基本就是从 3.7 到 4.0 的主要变化——我们可以大致理解 system prompt 是如何为 chatbot 应用编程的。当我们思考 chatbot 的设计时,通常想到的是围绕底层 LLM 构建的工具和 UI。但实际上,用户体验的主体是在这里定义的:system prompt。
我们也能从中看出 Claude 的开发周期:这是一个经典的用户驱动流程,先理解观察到的行为,再有针对性地解决问题。首先使用 system prompt 进行热修复,等到构建下一代模型时,再通过 post-training 从根本上处理。
system prompt 中大约 23,000 个 tokens——占据了可用上下文窗口的 11% 以上——定义了构成 Claude 的规则和工具,也揭示了 Anthropic 的优先事项。