逐日AI

面试题库

共 328 题,当前筛选 1 题。

Claude 高效使用:从对话到 Claude Code

D1 提示词进阶与 Claude 的「性格」:system prompt、XML 标签、让模型先思考、结构化输出

  • system prompt 应该放什么、不该放什么?如果一条规则模型总是不遵守,你会先检查什么?What belongs in a system prompt and what doesn't? If the model keeps ignoring one rule, what do you check first?
    国内高频海外高频基础#system-prompt#prompt-design

    分析过程 · 先想清楚再作答

    1. 这题考的是「职责边界」而不是「会不会写」。答成「放角色和要求」是及格线,能说出「不该放什么」以及「为什么」才有区分度。
    2. 先给一条判据:system prompt 是每次请求都重发的固定前提,所以只放整场对话都成立的东西——角色、边界(禁止项)、输出风格;每次都变的(时间、用户名、本轮材料)放 user 消息。
    3. 再说反面:把模型本来就知道的常识(「写干净的代码」)、大段 API 文档、每轮都不一样的材料塞进 system,只会稀释真正重要的规则,还会让 prompt caching 的前缀每次都变。
    4. 「规则总是不遵守」的排查顺序:先看 system 是不是太长导致规则被淹没(删到不能再删),再看规则是否含糊或与别的规则冲突,最后才考虑加强调;如果是「每次必须执行」的动作,应该改成程序层面的门禁而不是继续加规则。
    5. 可预期的追问:system 放最后行不行?可以但不推荐——模型对靠前的指令更敏感,且会破坏缓存前缀。

    How to reason about it · think before answering

    1. The question tests boundaries, not writing skill. Naming what to exclude, and why, is what separates a strong answer.
    2. Give the rule: the system prompt is a fixed premise resent on every request, so it holds only what is true for the whole conversation — role, constraints as prohibitions, output style. Anything that varies per turn belongs in the user message.
    3. Then the anti-patterns: obvious conventions, pasted API docs, and per-turn material dilute the important rules and also invalidate the prompt-cache prefix on every call.
    4. Debug order for an ignored rule: check length first and prune, then check for ambiguity or conflicting rules, and only then add emphasis. If the rule is a must-run action, move it to a deterministic gate instead of adding more words.
    5. Likely follow-up: can system go last? Possible but unwise — earlier instructions carry more weight and a moving prefix breaks caching.

    答题要点

    • 放:角色、边界(写禁止项)、输出风格;整场对话都成立的固定前提
    • 不放:会变的信息(时间、用户名、本轮材料)、模型本来就知道的常识、大段文档
    • system 每次请求重发,越长越贵,也越容易让关键规则被淹没
    • 规则不被遵守先删再改再强调;「每次必须做」的动作改成程序门禁

    Key points

    • Include role, prohibitions, and output style — premises that hold for the whole conversation
    • Exclude volatile facts, common sense the model already has, and long pasted docs
    • The system prompt is resent every request: longer means costlier and rules get buried
    • For an ignored rule: prune first, disambiguate second, emphasize last; must-run actions become deterministic gates