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 dont 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 Anthropics Claude 3 family of models to demonstrate how you can build efficient prompts by applying simple techniques.
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.
Lets 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:
Claude 3 Haikus response:
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. Lets change the prompt to get a different answer for the same question:
Claude 3 Haikus response:
The response changed accordingly by specifying that 10 + 10 is an addition. Additionally, although we didnt request it, the model also provided the result of the operation. Lets see how, through a very simple prompting technique, we can obtain an even more succinct result:
Claude 3 Haiku response:
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 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 speedqualities 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 models family are:
To learn more about the Claude 3 family, see Unlocking Innovation: AWS and Anthropic push the boundaries of generative AI together, Anthropics Claude 3 Sonnet foundation model is now available in Amazon Bedrock, and Anthropics Claude 3 Haiku model is now available on Amazon Bedrock.
As prompts become more complex, its 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:
The following is an example of a prompt that incorporates all the aforementioned elements:
In the following sections, we dive deep into Claude 3 best practices for prompt engineering.
For prompts that deal only with text, follow this set of best practices to achieve better results:
The Claude 3 family offers vision capabilities that can process images and return text outputs. Its 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:
Claude 3 Haikus response:
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.
Lets see an example with the following image:
In this case, the image itself is the prompt: Claude 3 Haikus response:
Lets look at the following example:
Prompt:
Claude 3 Haikus response:
Lets 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 Japans greenhouse gas emissions.
Prompt:
Claude 3 Haikus response:
Lets 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:
Claude 3 Haikus response:
In this example, we were careful to control the content of the narration. We made sure Claude didnt mention any extra information or discuss anything it wasnt 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.
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:
Claude 3 Haikus response:
The prompt incorporates the following best practices:
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:
Claude 3 Haikus response:
The prompt incorporates the following best practices:
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:
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.
Simn Crdova 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 Canadas first 4G wireless network. He now combines his expertise in connecting a nation with knowledge of generative AI to help customers innovate and scale.
Read the original here:
- 10 books thatll help you become a better software engineer - The Next Web [Last Updated On: November 11th, 2020] [Originally Added On: November 11th, 2020]
- Total hands out UKCS engineering framework deals to trio of consultants - News for the Oil and Gas Sector - Energy Voice [Last Updated On: November 11th, 2020] [Originally Added On: November 11th, 2020]
- Prometheus: Why The Engineers Were Heading To Earth | Screen Rant - Screen Rant [Last Updated On: November 11th, 2020] [Originally Added On: November 11th, 2020]
- Management CEMETERY SUPERINTENDENT The City of Gibbon is currently accepting - Kearney Hub [Last Updated On: November 11th, 2020] [Originally Added On: November 11th, 2020]
- Transportation Engineering and Safety Conference to be held Dec. 9-11 - Penn State News [Last Updated On: November 11th, 2020] [Originally Added On: November 11th, 2020]
- 'Bending' light to engineer improved optical devices and circuits - ND Newswire [Last Updated On: November 11th, 2020] [Originally Added On: November 11th, 2020]
- UC Merced Engineering Center to Focus on Ag Technology - AG INFORMATION NETWORK OF THE WEST - AGInfo Ag Information Network Of The West [Last Updated On: November 11th, 2020] [Originally Added On: November 11th, 2020]
- Head of Engineering Maintenance job with DURHAM UNIVERSITY | 233561 - Times Higher Education (THE) [Last Updated On: November 11th, 2020] [Originally Added On: November 11th, 2020]
- Civil Engineering student part of National Women in Engineering "Dream Team" panel - uoflnews.com [Last Updated On: November 11th, 2020] [Originally Added On: November 11th, 2020]
- Breaking News - Engineering at Its Best... and Worst: Don't Miss the Return of Science Channel's Hit Series "Deadly Engineering" and... [Last Updated On: November 11th, 2020] [Originally Added On: November 11th, 2020]
- Tesla is No. 1 most attractive company for engineering students, and thats a massive advantage - Electrek [Last Updated On: November 11th, 2020] [Originally Added On: November 11th, 2020]
- Wolves alter wetland creation and recolonization by killing ecosystem engineers - UMN News [Last Updated On: November 17th, 2020] [Originally Added On: November 17th, 2020]
- Global Automotive Simulation Market To Witness Astonishing Growth 2026 | Altair Engineering Inc., ANSYS Inc., PTC, Siemens AG, Autodesk Inc.,... [Last Updated On: November 17th, 2020] [Originally Added On: November 17th, 2020]
- Engineers Without Borders urges industry reflection - The Engineer [Last Updated On: November 17th, 2020] [Originally Added On: November 17th, 2020]
- 9 Engineers on the Hardest Song They Ever Mixed - Vulture [Last Updated On: November 17th, 2020] [Originally Added On: November 17th, 2020]
- Daewoo Engineering and Construction and SPH Engineering disclose AI partnership - sUAS News [Last Updated On: November 17th, 2020] [Originally Added On: November 17th, 2020]
- TRIPLE EIGHT BATHURST WINNING ENGINEER TO JOIN WAU - Auto Action [Last Updated On: November 24th, 2020] [Originally Added On: November 24th, 2020]
- First-year engineering classes for Anna University affiliated colleges take the e-way from today - The New Indian Express [Last Updated On: November 24th, 2020] [Originally Added On: November 24th, 2020]
- Datafold raises seed from NEA to keep improving the lives of data engineers - TechCrunch [Last Updated On: November 24th, 2020] [Originally Added On: November 24th, 2020]
- Tech has overtaken engineering as Bristol's fastest-growing industry with more than $1.07bn invested in the city since 2014 - Business Leader [Last Updated On: November 24th, 2020] [Originally Added On: November 24th, 2020]
- Start 2021 as an electrical engineer with this training for less than $20 - Boing Boing [Last Updated On: November 24th, 2020] [Originally Added On: November 24th, 2020]
- The Global Engineering Plastics Market is expected to grow by $ 43.00 bn during 2020-2024 progressing at a CAGR of 8% during the forecast period -... [Last Updated On: November 24th, 2020] [Originally Added On: November 24th, 2020]
- Elementary students test their engineering skills with Mayflower project - williamsonherald.com [Last Updated On: November 24th, 2020] [Originally Added On: November 24th, 2020]
- Global Architectural Engineering and Construction Solutions (AECS) Market 2020-2024 | Market Analysis, Drivers, Restraints, Opportunities, and Threats... [Last Updated On: December 14th, 2020] [Originally Added On: December 14th, 2020]
- American Institute of Chemical Engineers Celebrates Organizations and Leaders for Doing a World of Good - GlobeNewswire [Last Updated On: December 14th, 2020] [Originally Added On: December 14th, 2020]
- 2 Texas Engineers Honored Among Top Inventors in US - UT News - UT News | The University of Texas at Austin [Last Updated On: December 14th, 2020] [Originally Added On: December 14th, 2020]
- Chemical engineering alumna named Woman of the Year in Engineering - Penn State News [Last Updated On: December 14th, 2020] [Originally Added On: December 14th, 2020]
- 14 Largest Engineering Companies In The World - Yahoo Finance [Last Updated On: December 14th, 2020] [Originally Added On: December 14th, 2020]
- Vails namesake was a controversial state highway engineer - The Grand Junction Daily Sentinel [Last Updated On: December 14th, 2020] [Originally Added On: December 14th, 2020]
- The Next Frontier of Learning Engineering: AI That Teaches Other AI - EdSurge [Last Updated On: December 14th, 2020] [Originally Added On: December 14th, 2020]
- $496M Contract Will Give DOD Engineering Capabilities, Official Says - Nextgov [Last Updated On: December 14th, 2020] [Originally Added On: December 14th, 2020]
- William H. Robinson has a 'new and expanded leadership' post at Vanderbilt University - BlackEngineer.com [Last Updated On: December 14th, 2020] [Originally Added On: December 14th, 2020]
- Di Appointed to Lead Computer Science and Computer Engineering - University of Arkansas Newswire [Last Updated On: December 14th, 2020] [Originally Added On: December 14th, 2020]
- English is easier: India is woefully underprepared to teach engineering in regional languages - The Times of India Blog [Last Updated On: December 15th, 2020] [Originally Added On: December 15th, 2020]
- VW Bolsters U.S. Footprint With Advancements In Electric Car Portfolio, Infrastructure And Engineering - CarScoops [Last Updated On: December 15th, 2020] [Originally Added On: December 15th, 2020]
- These 4 Measures Indicate That SIA Engineering (SGX:S59) Is Using Debt Reasonably Well - Simply Wall St [Last Updated On: December 15th, 2020] [Originally Added On: December 15th, 2020]
- New engineering business opens its doors in Netherton despite the pandemic - expressandstar.com [Last Updated On: December 15th, 2020] [Originally Added On: December 15th, 2020]
- 'Earables' the next milestone in wearable tech, say engineers - E&T Magazine [Last Updated On: December 15th, 2020] [Originally Added On: December 15th, 2020]
- Senior Lecturer in Mechanical Engineering job with BIRMINGHAM CITY UNIVERSITY | 238845 - Times Higher Education (THE) [Last Updated On: December 15th, 2020] [Originally Added On: December 15th, 2020]
- New collaboration provides opportunity for future water scientists and engineers - Cranfield University [Last Updated On: December 15th, 2020] [Originally Added On: December 15th, 2020]
- Box Opens Research and Development Engineering Site in Warsaw, Poland - Business Wire [Last Updated On: December 15th, 2020] [Originally Added On: December 15th, 2020]
- Engineering and Technology Management students achieve high pass rate on certification exam - Morehead State University News [Last Updated On: December 15th, 2020] [Originally Added On: December 15th, 2020]
- Hydram Engineering warns Covid-19 and Brexit will dent its turnover - Business Live [Last Updated On: January 4th, 2021] [Originally Added On: January 4th, 2021]
- Calculating The Intrinsic Value Of Watts International Maritime Engineering Limited (HKG:2258) - Simply Wall St [Last Updated On: January 4th, 2021] [Originally Added On: January 4th, 2021]
- Is Suprajit Engineering Limited's (NSE:SUPRAJIT) Stock's Recent Performance A Reflection Of Its Financial Health? - Simply Wall St [Last Updated On: January 4th, 2021] [Originally Added On: January 4th, 2021]
- Engineering CAD Software Market is Flourishing due to Rising Emergence of Technical Implementation Drives Growth by 2027 | TurboCAD, SketchUp,... [Last Updated On: January 4th, 2021] [Originally Added On: January 4th, 2021]
- Apple vs. Tesla: Which Offers Software Engineers the Biggest Salaries? - Dice Insights [Last Updated On: January 4th, 2021] [Originally Added On: January 4th, 2021]
- From the classroom: Mechanical engineering at global top 10 uni - Study International News [Last Updated On: January 4th, 2021] [Originally Added On: January 4th, 2021]
- 'A lot of unknowns': Grass Valley Assistant City Engineer Bjorn Jones said the city has adapted under the pandemic - The Union of Grass Valley [Last Updated On: January 31st, 2021] [Originally Added On: January 31st, 2021]
- Associate Professor in Broadcast Engineering job with BIRMINGHAM CITY UNIVERSITY | 243677 - Times Higher Education (THE) [Last Updated On: January 31st, 2021] [Originally Added On: January 31st, 2021]
- CORRECTING and REPLACING: KCI, One of the Top Engineering Firms in the US, Adopts ProStar's PointMan SaaS Solution for SUE - Business Wire [Last Updated On: January 31st, 2021] [Originally Added On: January 31st, 2021]
- Purdue's online engineering graduate programs again rank in the top 3 nationally - Purdue News Service [Last Updated On: January 31st, 2021] [Originally Added On: January 31st, 2021]
- Faculty Positions of Intelligent Engineering and Microelectronics job with South China University of Technology (SCUT) | 314652 - The Chronicle of... [Last Updated On: January 31st, 2021] [Originally Added On: January 31st, 2021]
- Examining the Engineering of the Kasukabe Reservoir in Japan - Interesting Engineering [Last Updated On: January 31st, 2021] [Originally Added On: January 31st, 2021]
- Home - Springer [Last Updated On: January 31st, 2021] [Originally Added On: January 31st, 2021]
- SIA Engineering ekes out small profit in third quarter - Flightglobal [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- ST Engineering Launches Anti-Microbial Solution Approved for Use in Cabin Interiors - AviationPros.com [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Journey Engineering announces the addition of a new VP and Principal, Projects and Engineering - BOE Report [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- K-2 Ventures Advises Mark Two Engineering on Its Sale to CORE Industrial Partners - Business Wire [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Global Engineering Liability Insurance Market latest demand by 2020-2025 with leading players & COVID-19 Analysis KSU | The Sentinel Newspaper -... [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- First recipient of the Black Engineer of the Year Award is appointed Deans' Professor in Education and Engineering - BlackEngineer.com [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Google will pay $2.5 million to underpaid female engineers and overlooked Asian applicants - The Verge [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Clay County teen whose dream is to be an astronaut introduces other girls to STEM pursuits - The Florida Times-Union [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- Universal Engineering Sciences Strengthens Western Expansion By Acquiring Construction Testing & Engineering, Inc., In Southern California -... [Last Updated On: February 2nd, 2021] [Originally Added On: February 2nd, 2021]
- U.S. Navy Has Patents on Tech It Says Will Engineer the Fabric of Reality - VICE [Last Updated On: February 5th, 2021] [Originally Added On: February 5th, 2021]
- Cummins and Isuzu collaborate on mid-range powertrains and advanced engineering - Engine Technology International [Last Updated On: February 5th, 2021] [Originally Added On: February 5th, 2021]
- Liberty engineering teams helmet prototype earns second place in NFLs 1st and Future competition - WFXRtv.com [Last Updated On: February 5th, 2021] [Originally Added On: February 5th, 2021]
- FM Global executive on the insurer's risk-engineering based approach - Insurance Business Australia [Last Updated On: February 5th, 2021] [Originally Added On: February 5th, 2021]
- Black former NASA engineer: We have to teach our children well - WFXRtv.com [Last Updated On: February 5th, 2021] [Originally Added On: February 5th, 2021]
- Cummins and Isuzu announce global mid-range powertrain and advanced engineering collaboration - Automotive World [Last Updated On: February 5th, 2021] [Originally Added On: February 5th, 2021]
- University of Iowa College of Engineering receives diversity recognition, but still has work to do - UI The Daily Iowan [Last Updated On: February 5th, 2021] [Originally Added On: February 5th, 2021]
- Darin Gray Named Engineer of the Year - USC Viterbi | School of Engineering - USC Viterbi School of Engineering [Last Updated On: February 5th, 2021] [Originally Added On: February 5th, 2021]
- Rubrik transitions to new phase as sales and engineering heads leave Blocks and Files - Blocks and Files [Last Updated On: February 5th, 2021] [Originally Added On: February 5th, 2021]
- A*Star scientist Jackie Ying elected to prestigious US engineering academy based on work in Singapore - The Straits Times [Last Updated On: February 14th, 2021] [Originally Added On: February 14th, 2021]
- A Disillusioned ExxonMobil Engineer Quits to Take Action on Climate Change and Stop Making the World Worse - InsideClimate News [Last Updated On: February 14th, 2021] [Originally Added On: February 14th, 2021]
- USC Junior Advances Communities By Engineering Infrastructures That Serve The People - USC Viterbi | School of Engineering - USC Viterbi School of... [Last Updated On: February 14th, 2021] [Originally Added On: February 14th, 2021]
- Join us on Saturday, Feb. 13 at 7:00 pm EST for the Black Engineer of the Year Awards - BlackEngineer.com [Last Updated On: February 14th, 2021] [Originally Added On: February 14th, 2021]
- Sebastian Ceria Elected to the National Academy of Engineering - Salamanca Press [Last Updated On: February 14th, 2021] [Originally Added On: February 14th, 2021]
- Three Harvard Professors Elected to the National Academy of Engineering | News - Harvard Crimson [Last Updated On: February 14th, 2021] [Originally Added On: February 14th, 2021]
- Newsmaker: South Shore native working on NASA space telescope - The Patriot Ledger [Last Updated On: February 14th, 2021] [Originally Added On: February 14th, 2021]