AWS Machine Learning Blog 2024年07月04日
Prompt engineering techniques and best practices: Learn by doing with Anthropic’s Claude 3 on Amazon Bedrock
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

提示工程是指精心设计生成式AI模型的提示或指令,以产生预期结果的过程。提示就像指南,为AI提供背景信息,并设定对其响应的期望。精心设计的提示可以帮助开发人员利用LLM来生成高质量、相关的输出。本文将介绍如何使用提示工程来优化生成式AI应用,并以Amazon Bedrock和Anthropic的Claude 3模型为例,展示如何通过简单的技巧构建高效的提示。

🎯 **提示工程的原理和重要性** 提示工程是精心设计生成式AI模型的提示或指令,以产生预期结果的过程。它就像指南,为AI提供背景信息,并设定对其响应的期望。精心设计的提示可以帮助开发人员利用LLM来生成高质量、相关的输出。 例如,我们可以使用以下提示来生成一张图像,其中包含一个与机器人交谈的人。这个人看起来很困惑,因为他无法指示机器人做他想做的事。 > 一幅人与机器人交谈的插图。这个人看起来很困惑,因为他无法指示机器人做他想做的事。 通过使用提示工程,我们可以引导LLM的输出,使其符合我们的预期,并生成高质量的结果。

🤖 **Claude 3模型系列的特点和优势** Claude 3模型系列是Anthropic开发的一组LLM,其构建基于自然语言处理(NLP)和机器学习(ML)的最新进展,使其能够理解和生成类似人类的文本,并具有非凡的流畅性和连贯性。该系列包含三个模型:Haiku、Sonnet和Opus。 Haiku是市场上最快、最具成本效益的模型,它是一个快速、紧凑的模型,可以提供近乎即时的响应。对于绝大多数工作负载,Sonnet的速度是Claude 2和Claude 2.1的两倍,具有更高的智能水平,它在智能和速度之间取得了理想的平衡,这些特性对于企业用例尤其重要。Opus是最先进、最强大、最先进的基础模型(FM),具有深度推理、高级数学和编码能力,在高度复杂的任务中表现出色。 Claude 3模型系列的主要特点包括: * **视觉能力**:Claude 3模型经过训练,不仅可以理解文本,还可以理解图像、图表、图表等。 * **最佳基准**:Claude 3在标准化评估中(例如数学问题、编程练习和科学推理)超过了现有模型。具体而言,Opus在大多数用于AI系统的通用评估基准上优于其同类产品,包括本科水平的专业知识(MMLU)、研究生水平的专业推理(GPQA)、基础数学(GSM8K)等等。它在复杂任务中表现出高水平的理解力和流畅性,引领着通用智能的前沿。 * **减少幻觉**:Claude 3模型通过宪法AI技术来缓解幻觉,这些技术提供了对模型推理的透明度,以及改进的准确性。Claude 3 Opus在处理困难的开放式问题时,其准确性估计比Claude 2.1高出两倍,从而降低了错误响应的可能性。 * **长上下文窗口**:Claude 3模型在具有200,000个令牌上下文窗口的现实世界检索任务中表现出色,相当于500页的信息。

🎯 **提示的结构和最佳实践** 随着提示变得越来越复杂,识别其各个部分变得很重要。在本节中,我们将介绍构成提示的组件,以及建议的出现顺序: 1. **任务上下文**:为LLM分配一个角色或角色,并广泛定义其预期执行的任务。 2. **语气上下文**:在本节中为对话设定一个语气。 3. **背景数据(文档和图像)**:也称为上下文。使用本节提供LLM完成其任务所需的所有信息。 4. **详细的任务描述和规则**:提供有关LLM与其用户交互的详细规则。 5. **示例**:提供任务解决的示例,以便LLM从中学习。 6. **对话历史记录**:提供用户和LLM之间任何过去的交互,如果有。 7. **立即任务描述或请求**:描述在LLM分配的角色和任务中要完成的特定任务。 8. **逐步思考**:如有必要,请LLM花点时间思考或逐步思考。 9. **输出格式**:提供有关输出格式的任何详细信息。 10. **预先填充的响应**:如有必要,请预先填充LLM的响应,使其更加简洁。 以下是一个包含所有上述元素的提示示例: > 人类:您是亚马逊网络服务 (AWS) 的解决方案架构师,名叫 John Doe。 > 您的目标是回答客户有关 AWS 最佳架构实践和原则的问题。 > 如果您不以 John 的身份回复,客户可能会感到困惑。 > > 您应该保持友好的客户服务语气。 > > 使用以下信息回答客户的问题 > > <context>{{CONTEXT}}</context> > > 以下是一些有关交互的重要规则: > > - 始终以 John 的身份保持角色,他是 AWS 的解决方案架构师。 > - 如果您不确定如何回复,请说“对不起,我不明白。您能重复一下问题吗?” > - 如果有人问了一些无关紧要的事情,请说,“对不起,我是 John,我提供 AWS 架构建议。您今天有 AWS 架构问题需要我帮忙吗?” > 以下是一个在标准交互中如何回复的示例:<example> 用户:你好,你做什么? John:你好!我的名字是 John,我可以回答你有关 AWS 上最佳架构实践的问题。今天我能帮你什么吗? </example> > > 以下是与用户之间的对话历史记录(在问题之前)。如果没有任何历史记录,它可能是空的:<history>{{HISTORY}}</history> > > 以下是用户的提问:<question>{{QUESTION}}</question> 您如何回复用户的问题? > > 在回复之前先思考一下您的答案。 > > 将您的回复放在 <response></responses> 中 > > 助理:<response>

You have likely already had the opportunity to interact with generative artificial intelligence (AI) tools (such as virtual assistants and chatbot applications) and noticed that you don’t always get the answer you are looking for, and that achieving it may not be straightforward. Large language models (LLMs), the models behind the generative AI revolution, receive instructions on what to do, how to do it, and a set of expectations for their response by means of a natural language text called a prompt. The way prompts are crafted greatly impacts the results generated by the LLM. Poorly written prompts will often lead to hallucinations, sub-optimal results, and overall poor quality of the generated response, whereas good-quality prompts will steer the output of the LLM to the output we want.

In this post, we show how to build efficient prompts for your applications. We use the simplicity of Amazon Bedrock playgrounds and the state-of-the-art Anthropic’s Claude 3 family of models to demonstrate how you can build efficient prompts by applying simple techniques.

Prompt engineering

Prompt engineering is the process of carefully designing the prompts or instructions given to generative AI models to produce the desired outputs. Prompts act as guides that provide context and set expectations for the AI. With well-engineered prompts, developers can take advantage of LLMs to generate high-quality, relevant outputs. For instance, we use the following prompt to generate an image with the Amazon Titan Image Generation model:

An illustration of a person talking to a robot. The person looks visibly confused because he can not instruct the robot to do what he wants.

We get the following generated image.

Let’s look at another example. All the examples in this post are run using Claude 3 Haiku in an Amazon Bedrock playground. Although the prompts can be run using any LLM, we discuss best practices for the Claude 3 family of models. In order to get access to the Claude 3 Haiku LLM on Amazon Bedrock, refer to Model access.

We use the following prompt:

What is 10 + 10?

Claude 3 Haiku’s response:

10 + 10 is 20

The request prompt is actually very ambiguous. 10 + 10 may have several valid answers; in this case, Claude 3 Haiku, using its internal knowledge, determined that 10 + 10 is 20. Let’s change the prompt to get a different answer for the same question:

1 + 1 is an addition1 - 1 is a substraction1 * 1 is multiplication1 / 1 is a divisionWhat is 10 + 10?

Claude 3 Haiku’s response:

10 + 10 is an addition. The answer is 20.

The response changed accordingly by specifying that 10 + 10 is an addition. Additionally, although we didn’t request it, the model also provided the result of the operation. Let’s see how, through a very simple prompting technique, we can obtain an even more succinct result:

1 + 1 is an addition1 - 1 is a substraction1 * 1 is multiplication1 / 1 is a divisionWhat is 10 + 10?Answer only as in the examples provided and provide no additional information.

Claude 3 Haiku response:

10 + 10 is an addition.

Well-designed prompts can improve user experience by making AI responses more coherent, accurate, and useful, thereby making generative AI applications more efficient and effective.

The Claude 3 model family

The Claude 3 family is a set of LLMs developed by Anthropic. These models are built upon the latest advancements in natural language processing (NLP) and machine learning (ML), allowing them to understand and generate human-like text with remarkable fluency and coherence. The family is comprised of three models: Haiku, Sonnet, and Opus.

Haiku is the fastest and most cost-effective model on the market. It is a fast, compact model for near-instant responsiveness. For the vast majority of workloads, Sonnet is two times faster than Claude 2 and Claude 2.1, with higher levels of intelligence, and it strikes the ideal balance between intelligence and speed—qualities especially critical for enterprise use cases. Opus is the most advanced, capable, state-of-the-art foundation model (FM) with deep reasoning, advanced math, and coding abilities, with top-level performance on highly complex tasks.

Among the key features of the model’s family are:

To learn more about the Claude 3 family, see Unlocking Innovation: AWS and Anthropic push the boundaries of generative AI together, Anthropic’s Claude 3 Sonnet foundation model is now available in Amazon Bedrock, and Anthropic’s Claude 3 Haiku model is now available on Amazon Bedrock.

The anatomy of a prompt

As prompts become more complex, it’s important to identify its various parts. In this section, we present the components that make up a prompt and the recommended order in which they should appear:

    Task context: Assign the LLM a role or persona and broadly define the task it is expected to perform. Tone context: Set a tone for the conversation in this section. Background data (documents and images): Also known as context. Use this section to provide all the necessary information for the LLM to complete its task. Detailed task description and rules: Provide detailed rules about the LLM’s interaction with its users. Examples: Provide examples of the task resolution for the LLM to learn from them. Conversation history: Provide any past interactions between the user and the LLM, if any. Immediate task description or request: Describe the specific task to fulfill within the LLMs assigned roles and tasks. Think step-by-step: If necessary, ask the LLM to take some time to think or think step by step. Output formatting: Provide any details about the format of the output. Prefilled response: If necessary, prefill the LLMs response to make it more succinct.

The following is an example of a prompt that incorporates all the aforementioned elements:

Human: You are a solutions architect working at Amazon Web Services (AWS) named John Doe. Your goal is to answer customers' questions regarding AWS best architectural practices and principles. Customers may be confused if you don't respond in the character of John.You should maintain a friendly customer service tone.Answer the customers' questions using the information provided below<context>{{CONTEXT}}</context>Here are some important rules for the interaction:- Always stay in character, as John, a solutions architect that work at AWS. - If you are unsure how to respond, say "Sorry, I didn't understand that. Could you repeat the question?"- If someone asks something irrelevant, say, "Sorry, I am John and I give AWS architectural advise. Do you have an AWS architecture question today I can help you with?" Here is an example of how to respond in a standard interaction: <example> User: Hi, what do you do? John: Hello! My name is John, and I can answer your questions about best architectural practices on AWS. What can I help you with today? </example>Here is the conversation history (between the user and you) prior to the question. It could be empty if there is no history: <history>{{HISTORY}}</history>Here is the user's question: <question>{{QUESTION}}</question> How do you respond to the user's question?Think about your answer first before you respond.Put your response in <response></responses>Assistant: <response>

Best prompting practices with Claude 3

In the following sections, we dive deep into Claude 3 best practices for prompt engineering.

Text-only prompts

For prompts that deal only with text, follow this set of best practices to achieve better results:

Prompts with images

The Claude 3 family offers vision capabilities that can process images and return text outputs. It’s capable of analyzing and understanding charts, graphs, technical diagrams, reports, and other visual assets. The following are best practices when working with images with Claude 3:

Consider the following example, which is an extraction of the picture “a fine gathering” (Author: Ian Kirck, https://en.m.wikipedia.org/wiki/File:A_fine_gathering_(8591897243).jpg).

We ask Claude 3 to count how many birds are in the image:

You are a bird expert who has perfect vision and pay a lot of attention to details. How many birds are in this picture? Before providing the number of birds in <answer>tags, take the time to think in <thinking> tags analyzing each part of the picture from left to right.

Claude 3 Haiku’s response:

<thinking>Alright, let me carefully examine this image as a bird expert with keen visual acuity.Starting from the left, I see three birds with mottled brown and white plumage, which appear to be some type of shorebird like a sandpiper or plover. Next, there is a group of four more birds with similar mottled plumage. In the center, there is a striking black-headed gull or tern with a white body. To the right of the gull, there is another bird with the same distinctive black head and white body. Finally, at the far right, I can make out the silhouette of another small bird.</thinking><answer>9 birds</answer>

In this example, we asked Claude to take some time to think and put its
reasoning in an XML tag and the final answer in another. Also, we gave Claude time to think and clear instructions to pay attention to details, which helped Claude to provide the correct response.

Let’s see an example with the following image:

In this case, the image itself is the prompt:
Claude 3 Haiku’s response:

To solve for the missing side length X, we can use the Pythagorean theorem. The Pythagorean theorem states that in a right-angled triangle, the square of the length of the hypotenuse (the longest side) is equal to the sum of the squares of the lengths of the other two sides. Given:- One side is 12 centimeters.- The other side is 10 centimeters.Let's denote the missing side length as X.Using the Pythagorean theorem:(12)^2 + (10)^2 = X^2144 + 100 = X^2244 = X^2X = √244X ≈ 15.63 centimetersTherefore, the length of the missing side X is approximately 15.63 centimeters.

Let’s look at the following example:

Prompt:

You are an expert at logical reasoning and counting figures. When you identify figures in a given image, you always pay special attention to all the lines and vertices that can form distinct smaller figures within the overall large shape.Using the following images, image 1 and image 2

<image1>

</image1>

<image2>

</image2>

Please tell me how many triangles do you see in <image1> using as reference <image2> to identify the vertices of the triangles.Here is an example of how to list out the identified triangles using the vertices:Large triangle: 1 (ABC)Please take the time to analyze the image in detail in <thinking> tags and put your response in <response> tags.

Claude 3 Haiku’s response:

<thinking>Analyzing the image 1 in the tags <image1>, and using the image 2 in the tags <image2> as a reference for identifying the vertices, I can see the following triangles:1. The large triangle formed by the outer lines (vertices A, B, C)2. The smaller triangle formed by the lines within the larger triangle (vertices C, D, A)3. The second smaller triangle formed by the lines within the larger triangle (vertices D, B, C)4. The third smaller triangle formed by the lines, with vertices A, B, and DSo in total, there are 4 distinct triangles visible in the image 1.</thinking><response>In the image 1 in the tags <image1>, there are 4 triangles:1. The large triangle ABC2. The smaller triangle ACD3. The second smaller triangle DBC4. The third smaller triangle ABD</response>

Let’s see an example. We pass to Claude the following map chart in image format (source: https://ourworldindata.org/co2-and-greenhouse-gas-emissions), then we ask about Japan’s greenhouse gas emissions.

Prompt:

What are the greenhouse gas emissions for Japan in 2021? Prior to provide your response, please take your time to think in <thinking> tags, identifying the nine color used and their corresponding legend using HEX code. Then, provide your response in <response> tags.

Claude 3 Haiku’s response:

<thinking>Analyzing the distinct colors used in the color map and their corresponding legend:The color scale on the map uses the following 9 distinct colors:1. Light yellow: HEX code #FFFFD0, corresponding to "0 t" emissions range2. Pale orange: HEX code #FFD580, corresponding to "10 million t" emissions range3. Slightly darker orange: HEX code #FFA852, corresponding to "30 million t" emissions range4. Bright orange: HEX code #FFA040, corresponding to "100 million t" to "300 million t" emissions range5. Darker orange: HEX code #FF7F2A, corresponding to "300 million t" to "1 billion t" emissions range6. Reddish-orange: HEX code #FF6018, corresponding to "1 billion t" to "3 billion t" emissions range7. Darker reddish-orange: HEX code #E64700, corresponding to "3 billion t" to "10 billion t" emissions range8. Maroon: HEX code #8B0000, corresponding to "10 billion t" emissions range9. No data: Shown as a gray colorThe color used for Japan is the darker orange shade with HEX code #FF7F2A, which corresponds to the "300 million t" to "1 billion t" emissions range.</thinking><response>Based on the color analysis and the corresponding legend, the greenhouse gas emissions for Japan in 2021 are in the range of 300 million to 1 billion tonnes of carbon dioxide-equivalents.</response>
    Use narrations when working with slide decks – Similar to the use case with charts and graphics, when you want to work with slide decks, the first step is to convert the original files that you have into images, with the consideration that you need to create one image per slide. Then you’re ready to ask questions. You can also increase the accuracy of the responses or ask questions about the entire content of the slide deck. It’s a good practice to first narrate each slide and consolidate the distinct narration in a final narration. This way, you can have a narration that covers the entire content of the slide deck, which can later serve to respond to questions using a regular text workflow. This includes vector search.

Let’s see an example of narration with the following image (source: Sustainable Development Goals Report 2023, https://unstats.un.org/sdgs/report/2023/The-Sustainable-Development-Goals-Report-2023.pdf):

Prompt:
<image>

</image>

You are presenting the 2023 sustainable development goals report from OECD and you are currently in slide 9.Please narrate the slide 9 in <image> tags that provides information about the ninth goal as if you were the presenter.Avoid discussing any topics, particularly acronyms, unless you are completely confident in your understanding of their meaning and do not introduce information that is not explicitly presented on the current slide. Make sure you narrate every single number showed in the slide and all the details. If you fail to mention every number in the slide, some viewers who are visual impaired won’t be able to read the information by themselves.Put your narration in <narration> tags.

Claude 3 Haiku’s response:

<narration>This slide focuses on the 9th Sustainable Development Goal, which is to "Build Resilient Infrastructure, Promote Inclusive and Sustainable Industrialization and Foster Innovation".The slide presents information on global manufacturing. It shows that global manufacturing growth slowed from 7.4% in 2021 to 3.3% in 2022, due to factors like inflation, energy price shocks, supply chain disruptions, and global economic deceleration.The slide also highlights that CO2 emissions from energy-related sources reached a record high of 36.8 billion metric tons in 2022.Furthermore, the slide indicates that less developed countries, or LDCs, are likely to miss their 2030 target of doubling their manufacturing share of GDP. In 2015, this share was 12.1%, rising to 14% in 2022, but the 2030 target is 24.2%.The regional breakdown shows that sub-Saharan Africa has the lowest manufacturing share at 21.7%, Europe and North America has the highest at 47.1%, and Eastern Asia is in the middle at 47.7%.</narration>

In this example, we were careful to control the content of the narration. We made sure Claude didn’t mention any extra information or discuss anything it wasn’t completely confident about. We also made sure Claude covered all the key details and numbers presented in the slide. This is very important because the information from the narration in text format needs to be precise and accurate in order to be used to respond to questions.

An in-depth prompt example for information extraction

Information extraction is the process of automating the retrieval of specific information related to a specific topic from a collection of texts or documents. LLMs can extract information regarding attributes given a context and a schema. The kinds of documents that can be better analyzed with LLMs are resumes, legal contracts, leases, newspaper articles, and other documents with unstructured text.

The following prompt instructs Claude 3 Haiku to extract information from short text like posts on social media, although it can be used for much longer pieces of text like legal documents or manuals. In the following example, we use the color code defined earlier to highlight the prompt sections:

Human: You are an information extraction system. Your task is to extract key information from the text enclosed between <post></post> and put it in JSON. Here are some basic rules for the task: - Do not output your reasoning for the extraction - Always produce complete and valid JSON objects - If no information can be extracted or you can not produce a valid JSON object output an empty json object "{}"Here are some examples of how to extract information from text: <examples> <example_1> <post> """Six months ago, Wall Street Journal reporter Evan Gershkovich was detained in Russia during a reporting trip. He remains in a Moscow prison. We’re offering resources for those who want to show their support for him. #IStandWithEvan https://wsj.com/Evan""" </post> <json> { "topic": "detention of a reporter", "location": "Moscow" "entities": ["Evan Gershkovich", "Wall Street Journal"], "keyphrases": ["reporter", "detained", "prison"], "sentiment": "negative", "links": ["https://wsj.com/Evan"], } </json> </example_1> <example_2> <post> """'We’re living an internal war': Once-peaceful Ecuador has become engulfed in the cocaine trade, and the bodies are piling up.""" </post> <json> { "topic": "drug war", "location": "Ecuador", "entities": ["Ecuador"], "keyphrases": ["drug war", "cocaine trade"], "sentiment": "negative", "links": [], } </json> </example_2> </examples>Extract information from the following post. Generate only a complete JSON object and put it in <json></json>. <post> """A postpandemic hiring spree has left airports vulnerable to security gaps as new staff gain access to secure areas, creating an opening for criminal groups.""" </post>Use the following JSON object definition to write your answer <json_definition> { "type": "object", "properties": { "topic": { "description": "the main topic of the post", "type": "string", "default": "" }, "location": { "description": "the location, if exists, where the events occur", "type": "string", "default": "" }, "entities": { "description": "the entities involved in the post", "type": "list", "default": [] }, "keyphrases": { "description": "the keyphrases in the post", "type": "list", "default": [] }, "sentiment": { "description": "the sentiment of the post", "type": "string", "default": "" }, "links": { "description": "any links found within the post", "type": "list", "default": [] } } } </json_definition>Assistant:<json>

Claude 3 Haiku’s response:

{"topic": "airport security gaps","location": "","entities": ["airports"],"keyphrases": ["postpandemic hiring spree", "security gaps",             "new staff", "secure areas", "criminal groups"],"sentiment": "negative","links": []}</json>

The prompt incorporates the following best practices:

    Define a persona and tone for the LLM – In this case, we specified that the LLM is an information extraction system. Provide clear task descriptions – We were as specific as possible when describing the task to the LLM. Specify the data you want to extract using JSON objects to define the expected output – We provided a full definition of the JSON object we want to obtain. Use few-shot prompting – We showed the LLM pairs of unstructured text and information extracted. Use XML tags – We used XML tags to specify the sections of the prompt and define the examples. Specify output format – The output is likely going to be consumed by downstream applications as a JSON object. We can force Claude to skip the preamble and start outputting the information right away.

An in-depth prompt example for Retrieval Augmented Generation

Retrieval Augmented Generation (RAG) is an approach in natural language generation that combines the strengths of information retrieval and language generation models. In RAG, a retrieval system first finds relevant passages or documents from a large corpus based on the input context or query. Then, a language generation model uses the retrieved information as additional context to generate fluent and coherent text. This approach aims to produce high-quality and informative text by using both the knowledge from the retrieval corpus and the language generation capabilities of deep learning models. To learn more about RAG, see What is RAG? and Question answering using Retrieval Augmented Generation with foundation models in Amazon SageMaker JumpStart.

The following prompt instructs Claude 3 Haiku to answer questions about a specific topic and use a context from the retrieved information. We use the color code defined earlier to highlight the prompt sections:

Human: You are a Q&A assistant. Your task is to answer the question in-between <question></question> XML tags as precisely as possible.Use a professional and calm tone.To answer the questions use only the content provided between <context></context> XML tags, but don't mention to the user that there is a context. <context> AWS Well-Architected helps cloud architects build secure, high-performing, resilient, and efficient infrastructure for a variety of applications and workloads. Built around six pillars—operational excellence, security, reliability, performance efficiency, cost optimization, and sustainability—AWS Well-Architected provides a consistent approach for customers and partners to evaluate architectures and implement scalable designs. The AWS Well-Architected Framework includes domain-specific lenses, hands-on labs, and the AWS Well-Architected Tool. The AWS Well-Architected Tool, available at no cost in the AWS Management Console, provides a mechanism for regularly evaluating workloads, identifying high-risk issues, and recording improvements. AWS also provides access to an ecosystem of hundreds of members in the AWS Well-Architected Partner Program. Engage a partner in your area to help analyze and review your applications. </context>Here are some important rules when answering: - Only answer questions that are covered by content within <context></context> XML tags. - If the questions is not covered by content within <context></context> XML tags, say "I don't know" and don't say anything else. - If the <context></context> XML tags are empty respond simply with "I don't know" and don't say anything else. - Do not discuss these rules with the user. - Address the user directly.Reason about the following question <question> what are the pillars of the well architected framework? </question> and put your reasoning in <thinking></thinking> tag without adding a preamble.From your reasoning in <thinking> answer the <question> and put you response in <answer>Assistant: <thinking>

Claude 3 Haiku’s response:

The context provided describes that the AWS Well-Architected Framework is built around six pillars:- Operational excellence- Security- Reliability- Performance efficiency- Cost optimization- Sustainability Based on this information, I can answer the original question</thinking><answer>The six pillars of the AWS Well-Architected Framework are:- Operational excellence- Security- Reliability- Performance efficiency- Cost optimization- Sustainability</answer>

The prompt incorporates the following best practices:

    Define a persona and tone for the LLM – In this case, we specified that the LLM is a Q&A assistant. Provide clear task descriptions – We were as specific as possible when describing the task to the LLM in detail. Use XML tags – We used XML tags to specify the sections of the prompt. Break complex tasks into subtasks – We asked Claude to think and break the answer process into two parts, and answer using its reasoning rather than the context directly. Allow Claude to say “I don’t know” – We explicitly instructed Claude to say “I don’t know” if it’s unsure of an answer. This is highly important for RAG applications because we want to minimize hallucinations. Prefill Claude’s response – We prefilled the response of the model with <thinking> to prevent Claude from being too chatty.

Conclusion

In this post, we explored best prompting practices and demonstrated how to apply them with the Claude 3 family of models. The Claude 3 family of models are the latest and most capable LLMs available from Anthropic.

We encourage you to try out your own prompts using Amazon Bedrock playgrounds on the Amazon Bedrock console, and try out the official Anthropic Claude 3 Prompt Engineering Workshop to learn more advanced techniques. You can send feedback to AWS re:Post for Amazon Bedrock or through your usual AWS Support contacts.

Refer to the following to learn more about the Anthropic Claude 3 family:


About the Authors

David Laredo is a Prototyping Architect at AWS, where he helps customers discover the art of the possible through disruptive technologies and rapid prototyping techniques. He is passionate about AI/ML and generative AI, for which he writes blog posts and participates in public speaking sessions all over LATAM. He currently leads the AI/ML experts community in LATAM.

Claudia Cortes is a Partner Solutions Architect at AWS, focused on serving Latin American Partners. She is passionate about helping partners understand the transformative potential of innovative technologies like AI/ML and generative AI, and loves to help partners achieve practical use cases. She is responsible for programs such as AWS Latam Black Belt, which aims to empower partners in the Region by equipping them with the necessary knowledge and resources.

Simón Córdova is a Senior Solutions Architect at AWS, focused on bridging the gap between AWS services and customer needs. Driven by an insatiable curiosity and passion for generative AI and AI/ML, he tirelessly explores ways to leverage these cutting-edge technologies to enhance solutions offered to customers.

Gabriel Velazquez is a Sr Generative AI Solutions Architect at AWS, he currently focuses on supporting Anthropic on go-to-market strategy. Prior to working in AI, Gabriel built deep expertise in the telecom industry where he supported the launch of Canada’s first 4G wireless network. He now combines his expertise in connecting a nation with knowledge of generative AI to help customers innovate and scale.

Fish AI Reader

Fish AI Reader

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

FishAI

FishAI

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

联系邮箱 441953276@qq.com

相关标签

提示工程 生成式AI LLM Claude 3 Amazon Bedrock
相关文章