Newsroom Anthropic 09月13日
优化Claude输出:掌握Prompt工程的关键技巧
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

Prompt工程是企业优化Claude模型输出的关键。有效的Prompt能提升Claude的回答准确性,降低运营成本,并确保客户体验符合品牌调性。本文将介绍几种基础但有效的Prompt工程技巧,如“逐步思考”和“少样本提示”,并结合实际案例,展示如何通过这些方法提高Claude在处理复杂问题时的准确性和效率。此外,文章还强调了Prompt工程需要Prompt工程师与领域专家协同合作,通过不断测试和迭代来优化模型表现,从而充分发挥AI的潜力。

💡 **清晰指令是基础**:与初入职场的实习生一样,Claude需要清晰、明确且包含所有必要细节的指令。Prompt工程的核心在于提供详尽的指导,如同科学研究般严谨,通过反复测试和迭代来优化效果。

🚶 **“逐步思考”提升准确性**:在给予指令后,明确要求Claude“逐步思考”(step by step),尤其是在处理逻辑推理或复杂分析任务时,这能显著提高其回答的准确性和逻辑性。例如,在处理保险理赔时,要求Claude在特定标签内展示其思考过程。

📚 **“少样本提示”提供范例**:通过提供输入和理想输出的真实具体示例,尤其是包含挑战性案例和边缘情况,能帮助Claude更精确地理解任务要求。例如,在数据脱敏任务中,提供不同格式的个人身份信息(PII)示例,指导Claude如何进行替换。

🔗 **“Prompt链”分解复杂任务**:对于高度复杂的任务,可以将它们分解成多个相互关联的Prompt。通过逐步引导Claude完成每个子任务,并利用前一步的输出作为后续Prompt的输入,可以更有效地处理复杂流程,如税务咨询,先提取相关法规,再进行内容分析,最后回答用户问题。

📈 **案例实践与协同合作**:通过与领域专家的紧密合作,结合Prompt工程的最佳实践,可以显著提升Claude的性能(如准确率提升20%)。这种跨职能的协作对于企业在AI技术领域取得成功至关重要,能加速产品上市并降低成本。

Executive summary

    Prompt engineering is an important tool for any business seeking to optimize Claude. Good prompts improve Claude’s outputs, reduce deployment costs, and ensure customer-facing experiences are on-brand.A Fortune 500 company made use of effective prompt engineering to build a Claude-powered assistant that answers its customers’ questions with enhanced accuracy and speed.

The power of prompting

As businesses build with generative AI models, crafting effective prompts has become critical for producing high-quality outputs. This post explains basic prompt engineering techniques that help our customers get the most value from Claude. With the right prompts, businesses can tap into the full potential of AI to increase productivity across a wide range of tasks.

We also share how our prompt engineering team has been helping a Fortune 500 company build a customer-facing chat assistant that answers complex questions quickly and accurately - and how you can apply those tips too.

To gain the most value from Claude, you can apply a variety of techniques to create prompts that accomplish your desired tasks. These include processing data, answering customer questions, or reviewing contracts with increasing efficiency, while providing useful, relevant, and accurate results aligned to your goals and standards.

Here are some of the benefits of effective prompts:

    Accuracy: While we have made strides in reducing Claude’s hallucination rates, effective prompting helps further reduce the risk of inaccurate outputsConsistency: Providing a cohesive experience for end-users is crucial, and well thought out prompts ensure that Claude will produce consistent results in terms of quality, formatting, relevance, and toneUsefulness: Prompt engineering helps customers deliver targeted experiences for their desired audiences and industries. With careful prompting, you can cater to very specific personas and their needsCost savings: Running inefficient inputs and outputs at scale can become costly. Optimizing your prompts helps minimize unnecessary back-and-forth, and saves money

Three tips for your business

Here are three prompting techniques that we’ve seen unlock significant performance gains for businesses.

Before we dive in, remember that no matter which techniques you choose, always start by clearly describing the task. Think of Claude as an intern on their first day of the job: provide clear, explicit instructions with all the necessary detail. Keep in mind that prompt engineering is a science, and you should approach it like a scientist: test your prompts and iterate often.

1. Step by step

It might sound overly simple, but often Claude will respond more accurately if you simply tell it to think step by step after you give it an instruction.

For example, if you wanted Claude to solve a logic puzzle, you could say:

"Here is the information a customer provided for an automotive insurance claim. Based on our policy documents and the customer's profile, does this claim meet our requirements for qualification? Think step by step in <thinking> tags."

2. Few-shot prompting

It’s helpful to give Claude realistic and specific examples of the inputs and ideal outputs you’re hoping to see. It’s useful to include challenging examples and edge cases to help Claude understand exactly what you’re looking for.

For a simple example, consider how Claude can help with removing personally-identifiable information (PII) from information, using 2 examples to help Claude understand different ways that PII could present itself in a prompt. A simplified example using claude.ai may look something like this:

You are an expert redactor. I am going to provide you with some text. Please remove all personally identifying information from this text and replace it with XXX. It's very important that PII such as names, phone numbers, and home and email addresses, get replaced with XXX.

Here are two synthetic examples of how this should be done:

<examples>
<example>
<text>
My name is Jacob LaPont. My email address is jlp@geemail.com and my phone number is 555-492-1902. I am 43 years old. My account ID is 52777930.
</text>
The output should be:
<response>
My name is XXX. My email address is XXX@XXX.XXX and my phone number is XXX. I am XXX years old. My account ID is XXX.
</response>
</example>
<example>
<text>
Bo Nguyen is a cardiologist at Mercy Health Medical Center. He can be reached at 925-123-456 or b@mercy.health.
</text>
The output should be:
<response>
XXX is a cardiologist at Mercy Health Medical Center. He can be reached at XXX-XXX-XXXX or XXX@XXX.
</response>
</example>
</examples>

Now here is the text I’d like you to redact:

<text>
The customer's name is Steven Smith with Customer ID 44201312. His email address is steven.smith@geemail.com, or reach him via telephone at 555-182-9942.
</text>

3. Prompt chaining

Sometimes Claude performs better on complex tasks if you break the task down into multiple prompts corresponding to each step. This is known as ‘prompt chaining’.

Prompt chaining allows you to iterate on a prompt over multiple steps. Each new prompt can include the previous prompt-response pairs to build on the context. This technique enables you to guide Claude through a process by repeatedly prompting, responding, and expanding the prompt with each interaction.

For example, if you want Claude to help with explaining tax situations, you could first prompt it to create a list of the tax codes that are related to the specific question, then prompt Claude to identify the relevant sections in each document, and finally, to respond to a user question based on the information Claude’s gathered.

Case study: Prompting for enhanced accuracy and speed

A Fortune 500 company wanted to build an AI-powered chat assistant that could respond to customers’ questions about some unique and complex issues.

The company tried some other solutions in the market, but were unhappy with their wordiness, stilted tone, and overall lack of cohesion. They also wanted to see if they could achieve lower latency — i.e., provide faster responses — without affecting accuracy.

They turned to Claude Instant to power a friendly, concise chatbot that could answer customers’ questions quickly and accurately.

The company’s first efforts to deploy Claude fell short of their goal for accuracy. To remedy this, we sent in an Anthropic prompt engineer to partner with the company’s subject matter experts on improving Claude’s responses.

Our prompt engineers applied several techniques to improve Claude’s outputs, including:

    Telling Claude to use a scratchpad to show its work (customers don’t see the scratchpad, but it helps improve Claude’s accuracy)Providing few-shot examples of good answers, with a focus on training Claude to use the company’s desired format and styleDirecting Claude to use the data points and workflow recommended by subject matter experts (SMEs) — in this case, a set of factors that affect a customer’s legal situation

Below is an example prompt to help bring this guidance to life. In this example, the inclusion of “relevant_quotes” serves the purpose of telling Claude to use a scratchpad.

"
Human: You are an expert AI tax analyst. You help users understand the details of the tax code.

Here is the relevant section of the tax code.
<tax_code>
{{TAX_CODE}}
</tax_code>

Here are some examples of questions and answers about this section of the tax code:

<examples>
<example>
<question>
{{EXAMPLE QUESTION 1}}
</question>
<answer>
{{EXAMPLE ANSWER 1}}
</answer>
</example>

</examples>

Now here is the user's question about the tax code that I’d like you to answer:
<question>{{QUESTION}}</question>

First, pull relevant quotes from the tax code in <relevant_quotes> tags. Then write a concise, factual response to the user’s question in <answer> tags. Your answer should be fully grounded in the relevant quotes from the tax code that you extracted.

Assistant: <relevant_quotes>"

By combining our prompt engineers’ knowledge of prompting best practices with the customer’s subject matter expertise, we improved Claude’s accuracy by 20% - and helped get their product to market faster and at a lower cost.

Getting started with prompt engineering

There’s no single best technique for prompt engineering. Every LLM is different and the best way to prompt one model may not work as well for others. AI technology itself is nascent, and our collective understanding of how models work is evolving every day.

If you’re deploying an AI-powered solution within your business, prompt engineering is essential — and it should be a collaborative effort between prompt engineers and subject matter experts.

To get started on optimizing Claude for your use case, read our prompt engineering guide or contact our sales team.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Prompt工程 Claude AI优化 自然语言处理 少样本提示 Prompt Chaining Prompt Engineering Claude AI Optimization Natural Language Processing Few-Shot Prompting Prompt Chaining
相关文章