AI 学习资料 · 提示设计策略
Gemini 3 的提示词写法
编者注:本章是原文专门针对 Google Gemini 3 系列模型的建议。结构清晰、长材料在前问题在后之类的做法可以在其他模型上试用;但“默认回答简洁”、下面的日期和知识截止日期子句、内部“思考”及其 token 消耗,都是 Gemini 的行为和设置,换用其他模型时请以其文档为准。
Gemini 3 模型专为高级推理和指令遵循而设计,最适合直接、结构清晰、明确界定了任务和各项限制条件的提示词。要用 Gemini 3 获得最佳效果,建议采用以下做法:
提示词的核心原则
- 准确、直接:清楚、简洁地说明目标。避免多余的措辞,也不要用过度劝说的语气。
- 结构保持一致:用清晰的分隔符隔开提示词的各个部分。XML 风格的标签(例如
<context>、<task>)或 Markdown 标题都很有效。选定一种格式,在同一个提示词里始终沿用。 - 定义参数:对任何含义不明确的术语或参数作出明确解释。
- 控制输出的详略:默认情况下,Gemini 3 模型给出的回答直接、高效。如果需要更口语化或更详细的回答,必须在指令中明确提出。
- 统一处理多模态输入:使用文本、图片、音频或视频时,把它们当作地位相同的输入。需要时,在指令中明确提到每种模态的输入。
- 重要指令放在前面:把关键的行为限制、角色定义(人设)和输出格式要求放在系统指令中,或者放在用户提示词的最开头。
- 长上下文的结构:提供大量上下文(例如文档、代码)时,先给出全部上下文,再把具体的指令或问题放在提示词的最末尾。
- 锚定上下文:在一大段数据之后,用一句清楚的过渡语把上下文和问题衔接起来,例如“根据以上信息……”。
Gemini 3 Flash 的策略
-
当前日期的准确性:在系统指令中加入下面这段话,帮助模型注意到当前是 2026 年:
示例For time-sensitive user queries that require up-to-date information, you MUST follow the provided current time (date and year) when formulating search queries in tool calls. Remember it is 2026 this year. -
知识截止日期的准确性:在系统指令中加入下面这段话,让模型知道自己的知识截止日期:
示例Your knowledge cutoff date is January 2025.编者注:这里的“2025 年 1 月”是原文为 Gemini 3 Flash 写的截止日期。其他模型的知识截止日期各不相同,应填写所用模型文档中给出的日期。
-
依据上下文作答的表现:在系统指令中加入下面这段话(可按需修改),提高模型只依据所给上下文作答(grounding)的能力:
示例You are a strictly grounded assistant limited to the information provided in the User Context. In your answers, rely **only** on the facts that are directly mentioned in that context. You must **not** access or utilize your own knowledge or common sense to answer. Do not assume or infer from the provided facts; simply report them exactly as they appear. Your answer must be factual and fully truthful to the provided text, leaving absolutely no room for speculation or interpretation. Treat the provided context as the absolute limit of truth; any facts or details that are not directly mentioned in the context must be considered **completely untruthful** and **completely unsupported**. If the exact answer is not explicitly written in the context, you must state that the information is not available.
增强推理和规划能力
Gemini 2.5 和 3 系列模型会自动生成内部“思考”文本来提升推理表现。因此,一般不需要让模型在返回的回答里列提纲、做计划或写出详细的推理步骤。对于需要大量推理的问题,简单提一句(例如“回答前请认真思考”)就能提升表现,代价是多消耗一些思考 token。
详情请参阅 Gemini 思考文档。
编者注:内部“思考”、思考 token 以及 API 中调节思考深度的参数,都是 Gemini 的机制和设置(详见上面链接的文档)。其他模型会不会先“思考”、能不能调节、怎样计费,各不相同,请看所用模型和平台的说明。
结构化提示词示例
使用标签或 Markdown,可以帮助模型区分指令、上下文和任务。
XML 示例:
<role>
You are a helpful assistant.
</role>
<constraints>
1. Be objective.
2. Cite sources.
</constraints>
<context>
[Insert User Input Here - The model knows this is data, not instructions]
</context>
<task>
[Insert the specific user request here]
</task>
Markdown 示例:
# Identity
You are a senior solution architect.
# Constraints
- No external libraries allowed.
- Python 3.11+ syntax only.
# Output format
Return a single code block.
综合最佳实践的模板示例
这个模板体现了为 Gemini 3 编写提示词的核心原则。请务必针对具体用例反复迭代和修改。
系统指令:
<role>
You are Gemini 3, a specialized assistant for [Insert Domain, e.g., Data Science].
You are precise, analytical, and persistent.
</role>
<instructions>
1. **Plan**: Analyze the task and create a step-by-step plan.
2. **Execute**: Carry out the plan.
3. **Validate**: Review your output against the user's task.
4. **Format**: Present the final answer in the requested structure.
</instructions>
<constraints>
- Verbosity: [Specify Low/Medium/High]
- Tone: [Specify Formal/Casual/Technical]
</constraints>
<output_format>
Structure your response as follows:
1. **Executive Summary**: [Short overview]
2. **Detailed Response**: [The main content]
</output_format>
用户提示词:
<context>
[Insert relevant documents, code snippets, or background info here]
</context>
<task>
[Insert specific user request here]
</task>
<final_instruction>
Remember to think step-by-step before answering.
</final_instruction>