Prompt engineering techniques and best practices: Learn by doing with Anthropic’s Claude 3 on Amazon Bedrock … – AWS Blog
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.
Originally posted here:
Prompt engineering techniques and best practices: Learn by doing with Anthropic's Claude 3 on Amazon Bedrock ... - AWS Blog
- AI and Machine Learning - AI and geospatial companies join forces to map Africa - Smart Cities World - July 30th, 2025 [July 30th, 2025]
- Summer research project explores alternative machine learning framework - Mercer University - July 30th, 2025 [July 30th, 2025]
- Unveiling multiscale drivers of wind speed in Michigan using machine learning - Nature - July 30th, 2025 [July 30th, 2025]
- New machine learning tool reveals atomic structure of ultra-thin film materials - Phys.org - July 28th, 2025 [July 28th, 2025]
- Optimizing base fluid composition for PEMFC cooling: A machine learning approach to balance thermal and rheological performance - Nature - July 28th, 2025 [July 28th, 2025]
- Overview: Machine learning in the medical space - Scientist Live - July 28th, 2025 [July 28th, 2025]
- IMD develops a novel machine-learning-based tool to predict urban rainfall trends in India - Research Matters - July 28th, 2025 [July 28th, 2025]
- Unsupervised System 2 Thinking: The Next Leap in Machine Learning with Energy-Based Transformers - MarkTechPost - July 27th, 2025 [July 27th, 2025]
- A machine learning-based approach to predict depression in Chinese older adults with subjective cognitive decline: a longitudinal study - Nature - July 27th, 2025 [July 27th, 2025]
- Machine Learning Identifies Role of Impaired Purine Metabolism in Gout Pathogenesis - HCPLive - July 27th, 2025 [July 27th, 2025]
- Detection of breast cancer using machine learning and explainable artificial intelligence - Nature - July 27th, 2025 [July 27th, 2025]
- Investigation of key ferroptosis-associated genes and potential therapeutic drugs for asthma based on machine learning and regression models - Nature - July 27th, 2025 [July 27th, 2025]
- Predicting postoperative trauma-induced coagulopathy in patients with severe injuries by machine learning - Nature - July 27th, 2025 [July 27th, 2025]
- Machine learning based multi-stage intrusion detection system and feature selection ensemble security in cloud assisted vehicular ad hoc networks -... - July 27th, 2025 [July 27th, 2025]
- Comparative analysis of machine learning models for malaria detection using validated synthetic data: a cost-sensitive approach with clinical domain... - July 27th, 2025 [July 27th, 2025]
- Statistical modelling and forecasting of HIV and anti-retroviral therapy cases by time-series and machine learning models - Nature - July 27th, 2025 [July 27th, 2025]
- Seeing Through the Rust: How Machine Learning is Improving Corrosion Detection - Research Matters - July 27th, 2025 [July 27th, 2025]
- Machine-Learning Approach to Increase the Potency and Overcome the Hemolytic Toxicity of Gramicidin S - ACS Publications - July 24th, 2025 [July 24th, 2025]
- Machine learning-based academic performance prediction with explainability for enhanced decision-making in educational institutions - Nature - July 24th, 2025 [July 24th, 2025]
- Can External Validation Tools Can Improve Annotation Quality for LLM-as-a-Judge - Apple Machine Learning Research - July 24th, 2025 [July 24th, 2025]
- How to use learning curves to evaluate the sample size for malaria prediction models developed using machine learning algorithms - Malaria Journal - July 24th, 2025 [July 24th, 2025]
- Development and validation of a dynamic early warning system with time-varying machine learning models for predicting hemodynamic instability in... - July 24th, 2025 [July 24th, 2025]
- Early and non-destructive prediction of the differentiation efficiency of human induced pluripotent stem cells using imaging and machine learning -... - July 24th, 2025 [July 24th, 2025]
- Algorithmica Reports 35% Return in First Fiscal Year, Driven by Machine Learning Trading Technology - PR Newswire - July 24th, 2025 [July 24th, 2025]
- New research using machine learning further links increase in earthquakes, quake intensity, in Raton Basin to wastewater injections - The... - July 24th, 2025 [July 24th, 2025]
- Early modern text transcription revolutionized by ethical machine learning tools - Archaeology News Online Magazine - July 22nd, 2025 [July 22nd, 2025]
- Role of Artificial Intelligence and Machine Learning in Conservative Dentistry and Endodontics: A Review - Cureus - July 22nd, 2025 [July 22nd, 2025]
- NTT Researchers Advance AI and Machine Learning Accuracy, Security and Cost Effectiveness at ICML 2025 - Business Wire - July 22nd, 2025 [July 22nd, 2025]
- Exploring Phase Stability and Transport Properties of Emerging Thermoelectric Materials: Machine Learning and Experimental Insights - ACS Publications - July 22nd, 2025 [July 22nd, 2025]
- Google expands Ad Manager partner guidelines with machine learning restrictions - PPC Land - July 22nd, 2025 [July 22nd, 2025]
- Leveraging Generative AI into Wargaming and Machine Learning to Shape War Termination Scenarios in Ukraine - oodaloop.com - July 22nd, 2025 [July 22nd, 2025]
- Predictive AI Too Hard To Use? GenAI Makes It Easy - Machine Learning Week 2025 - July 22nd, 2025 [July 22nd, 2025]
- Wheat is becoming more climate-resilient through nature-based plant breeding and machine learning - Phys.org - July 22nd, 2025 [July 22nd, 2025]
- Machine learning enhanced ultra-high vacuum system for predicting field emission performance in graphene reinforced aluminium based metal matrix... - July 22nd, 2025 [July 22nd, 2025]
- Machine learning-guided evolution of pyrrolysyl-tRNA synthetase for improved incorporation efficiency of diverse noncanonical amino acids - Nature - July 22nd, 2025 [July 22nd, 2025]
- Dietary intervention optimized using machine learning could lower risk of dementia - Medical Xpress - July 20th, 2025 [July 20th, 2025]
- Application of machine learning algorithms and SHAP explanations to predict fertility preference among reproductive women in Somalia - Nature - July 20th, 2025 [July 20th, 2025]
- From Reactive to Predictive: Forecasting Network Congestion with Machine Learning and INT - Towards Data Science - July 20th, 2025 [July 20th, 2025]
- Artificial intelligence and machine learning in the development of vaccines and immunotherapeuticsyesterday, today, and tomorrow - Frontiers - July 20th, 2025 [July 20th, 2025]
- How Machine Learning is Revolutionizing Threat Detection for Businesses in Real-Time - Eye On Annapolis - July 20th, 2025 [July 20th, 2025]
- Identification of clinical diagnostic and immune cell infiltration characteristics of acute myocardial infarction with machine learning approach -... - July 20th, 2025 [July 20th, 2025]
- Predicting the mechanical performance of industrial waste incorporated sustainable concrete using hybrid machine learning modeling and parametric... - July 20th, 2025 [July 20th, 2025]
- Integrative multi-omics and machine learning reveal critical functions of proliferating cells in prognosis and personalized treatment of lung... - July 20th, 2025 [July 20th, 2025]
- Systematic measurement and machine learning-based profile characterization of community noise in a medium-large city in the United States - Nature - July 20th, 2025 [July 20th, 2025]
- Prediction of birthweight with early and mid-pregnancy antenatal markers utilising machine learning and explainable artificial intelligence - Nature - July 20th, 2025 [July 20th, 2025]
- A comprehensive machine learning for high throughput Tuberculosis sequence analysis, functional annotation, and visualization - Nature - July 20th, 2025 [July 20th, 2025]
- AI and Machine Learning Skills Are Make or Break for Developers: 71% of Tech Leaders Wont Hire Without Them - The National Law Review - July 20th, 2025 [July 20th, 2025]
- Quality-of-life scale machine learning approach to predict immunotherapy response in patients with advanced non-small cell lung cancer - Frontiers - July 20th, 2025 [July 20th, 2025]
- Inversion and validation of soil water-holding capacity in a wild fruit forest, using hyperspectral technology combined with machine learning - Nature - July 20th, 2025 [July 20th, 2025]
- Machine Learning in Drug Discovery Market to Witness Exponential Growth: Key Players, $250M Eli Lilly Deal & Regional Insights for 2025-2034 -... - July 18th, 2025 [July 18th, 2025]
- Automated seafood freshness detection and preservation analysis using machine learning and paper-based pH sensors - Nature - July 18th, 2025 [July 18th, 2025]
- Do You Know What It Means To Train a Machine Learning Model? - LSU - July 18th, 2025 [July 18th, 2025]
- Establishment of an interpretable MRI radiomics-based machine learning model capable of predicting axillary lymph node metastasis in invasive breast... - July 18th, 2025 [July 18th, 2025]
- A Machine Learning-Reconstructed Dataset of River Discharge, Temperature, and Heat Flux into the Arctic Ocean - Nature - July 18th, 2025 [July 18th, 2025]
- Leveraging computational linguistics and machine learning for detection of ultra-high risk of mental health disorders in youths | Schizophrenia -... - July 18th, 2025 [July 18th, 2025]
- Development and validation of machine learning-based diagnostic models using blood transcriptomics for early childhood diabetes prediction - Frontiers - July 18th, 2025 [July 18th, 2025]
- Fatigue and stamina prediction of athletic person on track using thermal facial biomarkers and optimized machine learning algorithm - Nature - July 18th, 2025 [July 18th, 2025]
- Identifying the crucial oncogenic mechanisms of DDX56 based on a machine learning-based integration model of RNA-binding proteins - Nature - July 18th, 2025 [July 18th, 2025]
- AI and Machine Learning Skills Are Make or Break for Developers: 71% of Tech Leaders Wont Hire Without Them - Yahoo Finance - July 18th, 2025 [July 18th, 2025]
- Developing an explainable machine learning and fog computing-based visual rating scale for the prediction of dementia progression - Nature - July 18th, 2025 [July 18th, 2025]
- Prognosis of air quality index and air pollution using machine learning techniques - Nature - July 18th, 2025 [July 18th, 2025]
- Integrating vision transformer-based deep learning model with kernel extreme learning machine for non-invasive diagnosis of neonatal jaundice using... - July 18th, 2025 [July 18th, 2025]
- PlayStation 6 Likely to Feature 24 GB RAM for Advanced Ray Tracing and Machine Learning Without Raising Costs - Wccftech - July 18th, 2025 [July 18th, 2025]
- Machine Learning-Assisted Iterative Screening for Efficient Detection of Drug Discovery Starting Points - ACS Publications - July 16th, 2025 [July 16th, 2025]
- 2025 IT Camp on AI & Machine Learning for Beginners to be held August 5 - Southeastern Oklahoma State University - July 16th, 2025 [July 16th, 2025]
- Utilizing machine learning to predict MRI signal outputs from iron oxide nanoparticles through the PSLG algorithm - Nature - July 16th, 2025 [July 16th, 2025]
- Developing a machine-learning model to enable treatment selection for neoadjuvant chemotherapy for esophageal cancer - Nature - July 16th, 2025 [July 16th, 2025]
- Advancing crop recommendation system with supervised machine learning and explainable artificial intelligence - Nature - July 16th, 2025 [July 16th, 2025]
- Predicting clozapine-induced adverse drug reaction biomarkers using machine learning - Nature - July 16th, 2025 [July 16th, 2025]
- Postoperative complication severity prediction in penile prosthesis implantation: a machine learning-based predictive modeling study - Nature - July 16th, 2025 [July 16th, 2025]
- The Future of AI & Machine Learning: Perspective on Shaping Tomorrows Business Landscape - Vocal - July 16th, 2025 [July 16th, 2025]
- Machine Learning: Your Ticket to a Thriving Career in the Tech World - The Impressive Times - July 14th, 2025 [July 14th, 2025]
- Integrative analysis of multi-omics data and gut microbiota composition reveals prognostic subtypes and predicts immunotherapy response in colorectal... - July 14th, 2025 [July 14th, 2025]
- Comprehensive multi-omics and machine learning framework for glioma subtyping and precision therapeutics - Nature - July 14th, 2025 [July 14th, 2025]
- Development and validation of a machine learning-based nomogram for survival prediction of patients with hilar cholangiocarcinoma after... - July 12th, 2025 [July 12th, 2025]
- Geochemical-integrated machine learning approach predicts the distribution of cadmium speciation in European and Chinese topsoils - Nature - July 12th, 2025 [July 12th, 2025]
- Machine learning-based construction of a programmed cell death-related model reveals prognosis and immune infiltration in pancreatic adenocarcinoma... - July 12th, 2025 [July 12th, 2025]
- Application of supervised machine learning and unsupervised data compression models for pore pressure prediction employing drilling, petrophysical,... - July 12th, 2025 [July 12th, 2025]
- Machine learning identifies lipid-associated genes and constructs diagnostic and prognostic models for idiopathic pulmonary fibrosis - Orphanet... - July 12th, 2025 [July 12th, 2025]
- An evaluation methodology for machine learning-based tandem mass spectra similarity prediction - BMC Bioinformatics - July 12th, 2025 [July 12th, 2025]