Get better AI results with prompt engineering techniques from the team behind Claude.

  • Category
  • Product
    Claude apps
  • Date
    November 10, 2025
  • Reading time
    5
    min
  • Share
    Copy link
    https://claude.com/blog/best-practices-for-prompt-engineering

Context engineering has emerged as an increasingly important part of working with LLMs, with prompt engineering as its essential building block.上下文工程已成为与大型语言模型合作中越来越重要的一部分,而提示工程是其基本构建块。

Prompt engineering is the craft of structuring instructions to get better outputs from AI models. It's how you phrase queries, specify style, provide context, and guide the model's behavior to achieve your goals.提示工程是构建指令以从AI模型获得更好输出的技艺。它涉及如何措辞查询、指定风格、提供上下文以及引导模型行为以实现目标。

The difference between a vague instruction and a well-crafted prompt can mean the gap between generic outputs and exactly what you need. A poorly structured prompt might require multiple back-and-forth exchanges to clarify intent, while a well-engineered prompt gets you there in one shot.模糊指令与精心设计的提示之间的差异,可能意味着通用输出与您确切所需之间的差距。结构不良的提示可能需要多次来回交流才能澄清意图,而精心设计的提示则能一次性达成目标。

To help you get started, we've assembled some of our team's best practices, including practical methods designed to improve your results right away. We'll start with simple habits you can use today, then scale up to advanced methods for complex projects.为了帮助您入门,我们整理了一些团队的最佳实践,包括旨在立即改善结果的实际方法。我们将从今天即可使用的简单习惯开始,然后扩展到适用于复杂项目的高级方法。

How to use prompt engineering如何使用提示工程

At its most basic level, prompt engineering is just modifying the query you pass your LLM. Often it's simply adding information to the query before you make your actual request—but knowing which information is the right information to share is the secret to engineering a great and effective prompt.在最基本的层面上,提示工程只是修改您传递给LLM的查询。通常,它只是在提出实际请求之前向查询添加信息——但知道哪些信息是正确信息,是设计出优秀且有效提示的秘诀。

Core techniques核心技巧

These prompt engineering techniques form the foundation of effective AI interactions. Use them consistently to see immediate improvements in response quality.这些提示工程技术构成了有效AI交互的基础。持续使用它们,您将立即看到响应质量的提升。

Be explicit and clear明确清晰

Modern AI models respond exceptionally well to clear, explicit instructions. Don't assume the model will infer what you want—state it directly. Use simple language that states exactly what you want without ambiguity.现代AI模型对清晰、明确的指令反应异常出色。不要假设模型会推断出您想要什么——直接说明。使用简单的语言,准确陈述您的需求,避免歧义。

The key principle: Tell the model exactly what you want to see. If you want comprehensive output, ask for it. If you want specific features, list them. Modern models like Claude benefit especially from explicit direction.关键原则:告诉模型您确切想看到什么。如果您想要全面的输出,就明确要求。如果您想要特定功能,就列出它们。像Claude这样的现代模型尤其受益于明确的指示。

Example: Creating an analytics dashboard示例:创建分析仪表板

Vague: "Create an analytics dashboard"模糊:“创建一个分析仪表板”

Explicit: "Create an analytics dashboard. Include as many relevant features and interactions as possible. Go beyond the basics to create a fully-featured implementation."明确:“创建一个分析仪表板。包含尽可能多的相关功能和交互。超越基础,实现一个功能完备的版本。”

The second version explicitly requests comprehensive features and signals that you want the model to go above and beyond the minimum.第二个版本明确要求全面的功能,并表明您希望模型超越最低限度。

Best practices:最佳实践:

  • Lead with direct action verbs: "Write," "Analyze," "Generate," "Create"以直接的动作动词开头:“写”、“分析”、“生成”、“创建”
  • Skip preambles and get straight to the request跳过开场白,直接提出请求
  • State what you want the output to include, not just what to work on说明您希望输出包含什么,而不仅仅是处理什么
  • Be specific about quality and depth expectations具体说明质量和深度期望

Provide context and motivation提供上下文和动机

Explaining why something matters helps AI models better understand your goals and deliver more targeted responses. This is particularly effective with newer models that can reason about your underlying objectives.解释某事为何重要,有助于AI模型更好地理解您的目标并提供更有针对性的响应。这对于能够推理您潜在目标的新模型尤其有效。

Example: Formatting preferences示例:格式偏好

Less effective: "NEVER use bullet points"效果较差:“永远不要使用项目符号”

More effective: "I prefer responses in natural paragraph form rather than bullet points because I find flowing prose easier to read and more conversational. Bullet points feel too formal and list-like for my casual learning style."效果更好:“我更喜欢自然段落形式的回复,而不是项目符号,因为我觉得流畅的散文更易读,也更适合对话。项目符号对于我随意的学习风格来说过于正式和列表化。”

The second version helps the model understand the reasoning behind the rule, which allows it to make better decisions about related formatting choices.第二个版本帮助模型理解规则背后的原因,从而使其能够就相关的格式选择做出更好的决策。

When to provide context:何时提供上下文:

  • Explaining the purpose or audience for the output解释输出的目的或受众
  • Clarifying why certain constraints exist澄清某些约束存在的原因
  • Describing how the output will be used描述输出将如何使用
  • Indicating what problem you're trying to solve指出您试图解决的问题

Be specific具体明确

Specificity in prompt engineering means structuring your instructions with explicit guidelines and requirements. The more specific you are about what you want, the better the results.提示工程中的具体性意味着用明确的指导方针和要求来构建指令。您对想要的内容越具体,结果就越好。

Example: Meal planning示例:膳食计划

Vague: "Create a meal plan for a Mediterranean diet"模糊:“为地中海饮食创建一个膳食计划”

Specific: "Design a Mediterranean diet meal plan for pre-diabetic management. 1,800 calories daily, emphasis on low glycemic foods. List breakfast, lunch, dinner, and one snack with complete nutritional breakdowns."具体:“设计一个针对糖尿病前期管理的地中海饮食膳食计划。每日1800卡路里,强调低血糖指数食物。列出早餐、午餐、晚餐和一份零食,并附上完整的营养分解。”

What makes a prompt specific enough?什么使提示足够具体?

Include:包括:

  • Clear constraints (word count, format, timeline)明确的约束(字数、格式、时间线)
  • Relevant context (who's the audience, what's the goal)相关上下文(受众是谁、目标是什么)
  • Desired output structure (table, list, paragraph)期望的输出结构(表格、列表、段落)
  • Any requirements or restrictions (dietary needs, budget limits, technical constraints)任何要求或限制(饮食需求、预算限制、技术约束)

Use examples使用示例

Examples aren't always necessary, but they shine when explaining concepts or demonstrating specific formats. Also known as one-shot or few-shot prompting, examples show rather than tell, clarifying subtle requirements that are difficult to express through description alone.示例并非总是必要,但在解释概念或演示特定格式时非常有用。也称为一次性或少量示例提示,示例通过展示而非告知来阐明难以仅通过描述表达的细微要求。

Important note for modern models: Claude 4.x and similar advanced models pay very close attention to details in examples. Ensure your examples align with the behaviors you want to encourage and minimize any patterns you want to avoid.现代模型的重要说明:Claude 4.x及类似的高级模型非常关注示例中的细节。确保您的示例与您希望鼓励的行为一致,并尽量减少您希望避免的模式。

Example: Article summarization示例:文章摘要

Without example: "Summarize this article"无示例:“总结这篇文章”

Here's an example of the summary style I want:

Article: [link to article about AI regulation]
Summary: EU passes comprehensive AI Act targeting high-risk systems. Key provisions include transparency requirements and human oversight mandates. Takes effect 2026.

Now summarize this article in the same style: [link to your new article]

When to use examples:何时使用示例:

  • The desired format is easier to show than describe期望的格式更容易展示而非描述
  • You need a specific tone or style您需要特定的语气或风格
  • The task involves subtle patterns or conventions任务涉及微妙的模式或惯例
  • Simple instructions haven't produced consistent results简单的指令未能产生一致的结果

Pro tip: Start with one example (one-shot). Only add more examples (few-shot) if the output still doesn't match your needs.专业提示:从一个示例开始(一次性)。仅当输出仍不符合需求时,再添加更多示例(少量示例)。

Give permission to Claude to express uncertainty允许Claude表达不确定性

Give the AI explicit permission to express uncertainty rather than guessing. This reduces hallucinations and increases reliability.明确允许AI表达不确定性,而不是猜测。这可以减少幻觉并提高可靠性。

Example: "Analyze this financial data and identify trends. If the data is insufficient to draw conclusions, say so rather than speculating."示例:“分析这些财务数据并识别趋势。如果数据不足以得出结论,请说明,而不是推测。”

This simple addition makes responses more trustworthy by allowing the model to acknowledge limitations.这个简单的添加使响应更值得信赖,因为它允许模型承认局限性。

Try these in Claude.在Claude中尝试这些。

Advanced prompt engineering techniques高级提示工程技术

These core habits will get you pretty far, but you may still encounter situations that require more sophisticated approaches. Advanced prompt engineering techniques shine when you're building agentic solutions, working with complex data structures, or need to break down multi-stage problems.这些核心习惯能让您走得很远,但您可能仍会遇到需要更复杂方法的情况。高级提示工程技术在您构建代理解决方案、处理复杂数据结构或需要分解多阶段问题时大放异彩。

Prefill the AI's response预填充AI的响应

Prefilling lets you start the AI's response for it, guiding format, tone, or structure. This technique is particularly powerful for enforcing output formats or skipping preambles.预填充让您为AI启动响应,从而引导格式、语气或结构。此技术对于强制输出格式或跳过开场白特别有效。

When to use prefilling:何时使用预填充:

  • You need the AI to output JSON, XML, or other structured formats您需要AI输出JSON、XML或其他结构化格式
  • You want to skip conversational preambles and get straight to content您希望跳过对话开场白,直接进入内容
  • You need to maintain a specific voice or character您需要保持特定的语气或角色
  • You want to control how the AI begins its response您希望控制AI如何开始其响应

Example: Enforcing JSON output示例:强制JSON输出

Without prefill, Claude might say: "Here's the JSON you requested: {...}"无预填充时,Claude可能会说:“这是您请求的JSON:{...}”

With prefill (API usage):使用预填充(API用法):

messages=[
    {"role": "user", "content": "Extract the name and price from this product description into JSON."},
    {"role": "assistant", "content": "{"}
]

The AI will continue from the opening brace, outputting only valid JSON.AI将从左大括号继续,仅输出有效的JSON。

Note: In chat interfaces, you can approximate this by being very explicit: "Output only valid JSON with no preamble. Begin your response with an opening brace."注意:在聊天界面中,您可以通过非常明确的方式近似实现:“仅输出有效的JSON,无开场白。以左大括号开始您的响应。”

Chain of thought prompting思维链提示

Chain of thought (CoT) prompting involves requesting step-by-step reasoning before answering. This technique helps with complex analytical tasks that benefit from structured thinking.思维链提示涉及在回答之前请求逐步推理。此技术有助于处理需要结构化思维的复杂分析任务。

Modern approach: Claude offers an extended thinking feature that automates structured reasoning. When available, extended thinking is generally preferable to manual chain of thought prompting. However, understanding manual CoT remains valuable for situations where extended thinking isn't available or when you need transparent reasoning you can review.现代方法:Claude提供了扩展思维功能,可自动进行结构化推理。当可用时,扩展思维通常优于手动思维链提示。然而,理解手动思维链在扩展思维不可用或需要可审查的透明推理时仍然有价值。

When to use chain of thought:何时使用思维链:

  • Extended thinking isn't available (i.e. the free Claude.ai plan)扩展思维不可用(例如免费的Claude.ai计划)
  • You need transparent reasoning that you can review您需要可审查的透明推理
  • The task requires multiple analytical steps任务需要多个分析步骤
  • You want to ensure the AI considers specific factors您希望确保AI考虑特定因素

There are three common implementations of chain of thought:思维链有三种常见实现方式:

Basic chain of thought基本思维链

Simply add "Think step-by-step" to your instructions.只需在指令中添加“逐步思考”。

Draft personalized emails to donors asking for contributions to this year's Care for Kids program.

Program information:
<program>
{{PROGRAM_DETAILS}}
</program>

Donor information:
<donor>
{{DONOR_DETAILS}}
</donor>

Think step-by-step before you write the email.

Guided chain of thought引导式思维链

Structure your prompt to provide specific reasoning stages.构建提示以提供特定的推理阶段。

Think before you write the email. First, think through what messaging might appeal to this donor given their donation history. Then, consider which aspects of the Care for Kids program would resonate with them. Finally, write the personalized donor email using your analysis.

Structured chain of thought结构化思维链

Use tags to separate reasoning from the final answer.使用标签将推理与最终答案分开。

Think before you write the email in <thinking> tags. First, analyze what messaging would appeal to this donor. Then, identify relevant program aspects. Finally, write the personalized donor email in <email> tags, using your analysis.

Note: Even when extended thinking is available, explicit CoT prompting can still be beneficial for complex tasks. The two approaches are complementary, not mutually exclusive.注意:即使扩展思维可用,明确的思维链提示对于复杂任务仍然有益。这两种方法是互补的,而非互斥的。

Control the output format控制输出格式

For modern AI models, there are several effective ways to control response formatting:对于现代AI模型,有几种有效的方法来控制响应格式:

1. Tell the AI what TO do instead of what NOT to do1. 告诉AI该做什么,而不是不该做什么

Instead of: "Do not use markdown in your response" Try: "Your response should be composed of smoothly flowing prose paragraphs"替代:“不要在响应中使用Markdown”尝试:“您的响应应由流畅的散文段落组成”

2. Match your prompt style to the desired output2. 使提示风格与期望输出匹配

The formatting style used in your prompt may influence the AI's response style. If you want minimal markdown, reduce markdown in your prompt.提示中使用的格式风格可能会影响AI的响应风格。如果您希望尽量减少Markdown,请减少提示中的Markdown。

3. Be explicit about formatting preferences3. 明确说明格式偏好

For detailed control over formatting:对于格式的详细控制:

When writing reports or analyses, write in clear, flowing prose using complete paragraphs. Use standard paragraph breaks for organization. Reserve markdown primarily for inline code, code blocks, and simple headings.

DO NOT use ordered lists or unordered lists unless you're presenting truly discrete items where a list format is the best option, or the user explicitly requests a list.

Instead of listing items with bullets, incorporate them naturally into sentences. Your goal is readable, flowing text that guides the reader naturally through ideas.

Prompt chaining提示链

Unlike the previous techniques, prompt chaining cannot be implemented in a single prompt. Chaining breaks down complex tasks into smaller sequential steps with separate prompts. Each prompt handles one stage, and the output feeds into the next instruction.与之前的技巧不同,提示链无法在单个提示中实现。链式分解将复杂任务分解为多个独立的顺序步骤,每个步骤使用单独的提示。每个提示处理一个阶段,输出馈入下一个指令。

This approach trades latency for higher accuracy by making each individual task easier. Typically this technique would be implemented using workflows or programmatically, but you could manually provide the prompts after receiving responses.这种方法通过使每个单独任务更简单,以延迟换取更高的准确性。通常,此技术将通过工作流或编程方式实现,但您也可以在收到响应后手动提供提示。

Example: Research summary示例:研究摘要

  1. First prompt: "Summarize this medical paper covering methodology, findings, and clinical implications."第一个提示:“总结这篇医学论文,涵盖方法、发现和临床意义。”
  1. Second prompt: "Review the summary above for accuracy, clarity, and completeness. Provide graded feedback."第二个提示:“检查上述摘要的准确性、清晰度和完整性。提供分级反馈。”
  1. Third prompt: "Improve the summary based on this feedback: [feedback from step 2]"第三个提示:“根据此反馈改进摘要:[步骤2的反馈]”

Each stage adds refinement through focused instruction.每个阶段通过聚焦指令增加改进。

When to use prompt chaining:何时使用提示链:

  • You have a complex request that needs breaking down into steps您有一个需要分解为步骤的复杂请求
  • You need iterative refinement您需要迭代改进
  • You're doing multi-stage analysis您正在进行多阶段分析
  • Intermediate validation adds value中间验证增加价值
  • A single prompt produces inconsistent results单个提示产生不一致的结果

Trade-offs: Chaining increases latency (multiple API calls) but often dramatically improves accuracy and reliability for complex tasks.权衡:链式增加延迟(多次API调用),但通常显著提高复杂任务的准确性和可靠性。

Techniques you might have heard about您可能听说过的技巧

Some prompt engineering techniques that were popular with earlier AI models are less necessary with models like Claude. However, you may still encounter them in older documentation or find them useful in specific situations.一些在早期AI模型中流行的提示工程技术,对于像Claude这样的模型已不那么必要。然而,您可能仍会在旧文档中遇到它们,或在特定情况下发现它们有用。

XML tags for structure用于结构的XML标签

XML tags were once a recommended way to add structure and clarity to prompts, especially when incorporating large amounts of data. While modern models are better at understanding structure without XML tags, they can still be useful in specific situations.XML标签曾是为提示添加结构和清晰度的推荐方式,尤其是在包含大量数据时。虽然现代模型在没有XML标签的情况下也能更好地理解结构,但在特定情况下它们仍然有用。

Example:示例:

<athlete_information>
- Height: 6'2"
- Weight: 180 lbs
- Goal: Build muscle
- Dietary restrictions: Vegetarian
</athlete_information>

Generate a meal plan based on the athlete information above.

When XML tags might still be helpful:XML标签可能仍有帮助的情况:

  • You're working with extremely complex prompts mixing multiple types of content您正在处理极其复杂的提示,混合了多种类型的内容
  • You need to be absolutely certain about content boundaries您需要绝对确定内容边界
  • You're working with older model versions您正在使用较旧版本的模型

Modern alternative: For most use cases, clear headings, whitespace, and explicit language ("Using the athlete information below...") work just as well with less overhead.现代替代方案:对于大多数用例,清晰的标题、空白和明确的语言(“使用下面的运动员信息...”)效果同样好,且开销更少。

Role prompting角色提示

Role prompting defines expert personas and perspectives in how you phrase your query. While this can be effective, modern models are sophisticated enough that heavy-handed role prompting is often unnecessary.角色提示在您措辞查询时定义专家角色和视角。虽然这可能有效,但现代模型足够复杂,通常不需要过于强硬的角色提示。

Example: "You are a financial advisor. Analyze this investment portfolio..."示例:“您是一名财务顾问。分析这个投资组合...”

Important caveat: Don't over-constrain the role. "You are a helpful assistant" is often better than "You are a world-renowned expert who only speaks in technical jargon and never makes mistakes." Overly specific roles can limit the AI's helpfulness.重要警告:不要过度约束角色。“您是一个有用的助手”通常比“您是一位世界知名的专家,只说技术术语,从不犯错”更好。过于具体的角色可能会限制AI的有用性。

When role prompting might help:角色提示可能有帮助的情况:

  • You need consistent tone across many outputs您需要在多个输出中保持一致的语气
  • You're building an application that requires a specific persona您正在构建需要特定角色的应用程序
  • You want domain expertise framing for complex topics您希望为复杂主题提供领域专业知识框架

Modern alternative: Often, being explicit about what perspective you want is more effective: "Analyze this investment portfolio, focusing on risk tolerance and long-term growth potential" rather than assigning a role.现代替代方案:通常,明确说明您想要的视角更有效:“分析这个投资组合,重点关注风险承受能力和长期增长潜力”,而不是分配角色。

Try in Claude.在Claude中尝试。

Putting it all together综合运用

You've now seen individual techniques in isolation, but their real power emerges when you combine them strategically. The art of prompt engineering isn't using every technique available—it's selecting the right combination for your specific need.您现在已单独了解了各个技巧,但它们的真正力量在于战略性地组合使用。提示工程的艺术不是使用所有可用技巧,而是为您的特定需求选择正确的组合。

Example combining multiple techniques:组合多种技巧的示例:

xtract key financial metrics from this quarterly report and present them in JSON format.

I need this data for automated processing, so it's critical that your response contains ONLY valid JSON with no preamble or explanation.

Use this structure:
{
  "revenue": "value with units",
  "profit_margin": "percentage",
  "growth_rate": "percentage"
}

If any metric is not clearly stated in the report, use null rather than guessing.

Begin your response with an opening brace: {

This prompt combines:此提示结合了:

  • Explicit instructions (exactly what to extract)明确的指令(确切要提取的内容)
  • Context (why format matters)上下文(格式为何重要)
  • Example structure (showing the format)示例结构(展示格式)
  • Permission to express uncertainty (use null if unsure)允许表达不确定性(如果不确定则使用null)
  • Format control (begin with opening brace)格式控制(以左大括号开始)

Choosing the right techniques选择正确的技巧

Not every prompt needs every technique. Here's a decision framework:并非每个提示都需要所有技巧。以下是一个决策框架:

Start here:从这里开始:

  1. Is your request clear and explicit? If no, work on clarity first您的请求是否清晰明确?如果不是,先提高清晰度
  2. Is the task simple? Use core techniques only (be specific, be clear, provide context)任务是否简单?仅使用核心技巧(具体、清晰、提供上下文)
  3. Does the task require specific formatting? Use examples or prefilling任务是否需要特定格式?使用示例或预填充
  4. Is the task complex? Consider breaking it down (chaining)任务是否复杂?考虑分解(链式)
  5. Does it need reasoning? Use extended thinking (if available) or chain of thought是否需要推理?使用扩展思维(如果可用)或思维链

Technique selection guide:技巧选择指南:

If you need... Use...
Specific output format Examples, prefilling, or explicit format instructions
Step-by-step reasoning Extended thinking (Claude 4.x) or chain of thought
Complex multi-stage task Prompt chaining
Transparent reasoning Chain of thought with structured output
To prevent hallucinations Permission to say "I don't know"

Troubleshooting common prompt issues常见提示问题故障排除

Even well-intentioned prompts can produce unexpected results. Here are common issues and how to fix them:即使是精心设计的提示也可能产生意外结果。以下是常见问题及解决方法:

  • Problem: Response is too generic → Solution: Add specificity, examples, or explicit requests for comprehensive output. Ask the AI to "go beyond the basics."问题:响应过于通用 → 解决方案:添加具体性、示例或明确要求全面输出。要求AI“超越基础”。
  • Problem: Response is off-topic or misses the point → Solution: Be more explicit about your actual goal. Provide context about why you're asking.问题:响应偏离主题或未抓住要点 → 解决方案:更明确地说明您的实际目标。提供关于您为何提问的上下文。
  • Problem: Response format is inconsistent → Solution: Add examples (few-shot) or use prefilling to control the start of the response.问题:响应格式不一致 → 解决方案:添加示例(少量示例)或使用预填充来控制响应的开始。
  • Problem: Task is too complex, results are unreliable → Solution: Break into multiple prompts (chaining). Each prompt should do one thing well.问题:任务过于复杂,结果不可靠 → 解决方案:分解为多个提示(链式)。每个提示应做好一件事。
  • Problem: AI includes unnecessary preambles → Solution: Use prefilling or explicitly request: "Skip the preamble and get straight to the answer."问题:AI包含不必要的开场白 → 解决方案:使用预填充或明确要求:“跳过开场白,直接给出答案。”
  • Problem: AI makes up information → Solution: Explicitly give permission to say "I don't know" when uncertain.问题:AI编造信息 → 解决方案:明确允许在不确定时说“我不知道”。
  • Problem: AI suggests changes when you wanted implementation → Solution: Be explicit about action: "Change this function" rather than "Can you suggest changes?"问题:AI建议更改,而您想要实现 → 解决方案:明确说明操作:“更改此函数”,而不是“您能建议更改吗?”

Pro tip: Start simple and add complexity only when needed. Test each addition to see if it actually improves results.专业提示:从简单开始,仅在需要时增加复杂性。测试每个添加项,看它是否确实改善了结果。

Common mistakes to avoid应避免的常见错误

Learn from these common pitfalls to save time and improve your prompts:从这些常见陷阱中学习,以节省时间并改进您的提示:

  • Don't over-engineer: Longer, more complex prompts are NOT always better.不要过度设计:更长、更复杂的提示并不总是更好。
  • Don't ignore the basics: Advanced techniques won't help if your core prompt is unclear or vague.不要忽视基础:如果核心提示不清晰或模糊,高级技巧也无济于事。
  • Don't assume the AI reads minds: Be specific about what you want. Leaving things ambiguous gives the AI room to misinterpret.不要假设AI能读心:具体说明您想要什么。留下模糊空间会让AI有误解的余地。
  • Don't use every technique at once: Select techniques that address your specific challenge.不要同时使用所有技巧:选择针对您特定挑战的技巧。
  • Don't forget to iterate: The first prompt rarely works perfectly. Test and refine.不要忘记迭代:第一个提示很少完美。测试并改进。
  • Don't rely on outdated techniques: XML tags and heavy role prompting are less necessary with modern models. Start with explicit, clear instructions.不要依赖过时的技巧:XML标签和强角色提示对于现代模型已不那么必要。从明确、清晰的指令开始。

Prompt engineering considerations提示工程注意事项

Working with long content处理长内容

One of the challenges of implementing advanced prompt engineering is that it adds context overhead through additional token usage. Examples, multiple prompts, detailed instructions—they all consume tokens, and context management is a skill in its own right.实施高级提示工程的挑战之一是,它通过额外的令牌使用增加了上下文开销。示例、多个提示、详细指令——它们都消耗令牌,而上下文管理本身就是一项技能。

Remember to use prompt engineering techniques when they make sense and justify their usage. For comprehensive guidance on managing context effectively, check out our blog post on context engineering.请记住,在合理且证明其用途的情况下使用提示工程技术。有关有效管理上下文的全面指导,请查看我们关于上下文工程的博客文章。

Context awareness improvements: Modern AI models, including Claude 4.x, have significantly improved context awareness capabilities that help address historical "lost-in-the-middle" issues where models struggled to attend equally to all parts of long contexts.上下文感知改进:现代AI模型,包括Claude 4.x,显著改进了上下文感知能力,有助于解决历史性的“中间迷失”问题,即模型难以平等关注长上下文的所有部分。

Why task-splitting still helps: Even with these improvements, breaking large tasks into smaller, discrete chunks remains a valuable technique—not because of context limitations, but because it helps the model focus on doing its best work within a very specific set of requirements and scope. A focused task with clear boundaries consistently produces higher quality results than trying to accomplish multiple objectives in a single prompt.为什么任务拆分仍然有帮助:即使有这些改进,将大任务分解为更小的离散块仍然是一种有价值的技术——不是因为上下文限制,而是因为它帮助模型专注于在非常具体的需求和范围内做到最好。一个具有明确边界的聚焦任务,始终比试图在单个提示中完成多个目标产生更高质量的结果。

Strategy: When working with long contexts, structure your information clearly with the most critical details at the beginning or end. When working with complex tasks, consider whether breaking them into focused subtasks would improve the quality and reliability of each component.策略:处理长上下文时,清晰组织信息,将最关键细节放在开头或结尾。处理复杂任务时,考虑是否将其分解为聚焦的子任务,以提高每个组件的质量和可靠性。

What does a good prompt look like?好的提示是什么样的?

Prompt engineering is a skill, and it's going to take a few tries before you master it. The only way to know if you're doing it right is to test it and see. The first step is to just try it yourself. You'll see right away the differences between queries with and without the prompting techniques we covered here.提示工程是一项技能,需要几次尝试才能掌握。判断是否做对的唯一方法是测试并观察。第一步是亲自尝试。您会立即看到使用和未使用我们介绍的提示技巧的查询之间的差异。

To really hone your prompt engineering skills, you'll need to objectively measure the effectiveness of your prompts. The good news is that is exactly what is covered in our prompt engineering course at anthropic.skilljar.com.要真正磨练您的提示工程技能,您需要客观衡量提示的有效性。好消息是,这正是我们在anthropic.skilljar.com的提示工程课程中涵盖的内容。

Quick evaluation tips:快速评估技巧:

  • Does the output match your specific requirements?输出是否符合您的具体要求?
  • Did you get the result in one attempt or need multiple iterations?您是一次性获得结果,还是需要多次迭代?
  • Is the format consistent across multiple attempts?多次尝试中格式是否一致?
  • Are you avoiding the common mistakes listed above?您是否避免了上面列出的常见错误?

Final words of advice最后的建议

Prompt engineering is ultimately about communication: speaking the language that helps AI most clearly understand your intent. Start with the core techniques covered early in this guide. Use them consistently until they become second nature. Only layer in advanced techniques when they solve a specific problem.提示工程归根结底是沟通:用最能帮助AI清晰理解您意图的语言说话。从本指南早期介绍的核心技巧开始。持续使用它们,直到它们成为第二天性。仅在解决特定问题时才加入高级技巧。

Remember: the best prompt isn't the longest or most complex. It's the one that achieves your goals reliably with the minimum necessary structure. As you practice, you'll develop an intuition for which techniques suit which situations.请记住:最好的提示不是最长或最复杂的。而是以最少的必要结构可靠地实现目标的提示。随着练习,您将培养出对哪些技巧适合哪些情况的直觉。

The shift toward context engineering doesn't diminish prompt engineering's importance. In fact, prompt engineering is a fundamental building block within context engineering. Every well-crafted prompt becomes part of the larger context that shapes AI behavior, working alongside conversation history, attached files, and system instructions to create better outcomes.向上下文工程的转变并不会削弱提示工程的重要性。事实上,提示工程是上下文工程中的基本构建块。每个精心设计的提示都成为塑造AI行为的更大上下文的一部分,与对话历史、附加文件和系统指令一起,创造更好的结果。

Start prompting in Claude today.立即在Claude中开始提示。

Additional resources其他资源

No items found.
Prev
0/5
Next
eBook

No items found.
Start prompting in Claude today.

Transform how your organization operates with Claude

See pricing
Contact sales

Get the developer newsletter

Product updates, how-tos, community spotlights, and more. Delivered monthly to your inbox.

Subscribe

Please provide your email address if you'd like to receive our monthly developer newsletter. You can unsubscribe at any time.

Thank you! You’re subscribed.
Sorry, there was a problem with your submission, please try again later.
Claude apps
Productivity
Agents