Thank you! Below is the Prompt Engineering Guide formatted in Markdown. You can copy and paste this into a .md
file for easy reading and sharing.
Note: This guide consolidates key principles and best practices in prompt engineering, drawing on recent advances and insights from industry leaders like Anthropic and OpenAI. While some information may align with established practices, the aim is to provide a comprehensive resource that enhances your ability to craft effective prompts. Understanding the inner workings of large language models (LLMs) is crucial for guiding their behavior to produce desired outcomes.
Prompt engineering is the process of designing and structuring prompts to guide AI models in generating accurate, relevant, and useful responses. Effective prompts serve as clear instructions that help the AI understand the task, context, and desired output. In models like OpenAI's GPT-4 and Anthropic's Claude, the way you phrase your prompt can significantly influence the model's reasoning, ethics, and style of response.
Key aspects of prompt engineering include:
By mastering these concepts, you can leverage AI models more effectively for tasks ranging from answering questions and generating creative content to problem-solving and data analysis.
Define the AI's Role Clearly:
Provide Relevant Context:
Be Specific with Instructions:
Set the Desired Tone and Style:
Limit the Scope:
Encourage Step-by-Step Reasoning:
Specify the Format:
Avoid Ambiguity:
Instruct on Handling Uncertainty:
Address Ethical and Sensitive Topics Appropriately:
Avoid Unnecessary Apologies:
Use Positive Language:
Set Knowledge Cutoff Dates:
Encourage Creativity and Originality:
Ask for Multiple Perspectives:
Use Examples to Clarify:
Instruct to Cite Sources When Necessary:
Break Down Complex Tasks:
Use Tags or Headings for Organization:
Explanation: Structure your prompt with headings to separate different instructions.
Example:
[Objective]: ...
[Constraints]: ...
[Format]: ...
Confirm Understanding:
Keep Augmented Context in Mind:
Multi-step process:
Start with a Simple Prompt and Build Upon It:
Experiment with Different Phrasings:
Use Open-Ended Questions for Elaborate Responses:
Provide Examples in Your Prompt:
Specify the Intended Audience:
Set Length Constraints if Needed:
Encourage the Use of Analogies:
Request a Particular Point of View:
Ask for Clarification if the Response is Unclear:
Iterate Based on Feedback:
Below are examples that demonstrate how to apply the guidelines and tips effectively, each referencing specific guidelines and tips.
Prompt: "You are a historian specializing in ancient civilizations. Explain the significance of the Rosetta Stone to a group of college students."
Analysis:
Prompt: "Step-by-step, calculate the total interest earned on a $5,000 investment over 3 years at an annual interest rate of 5% compounded annually."
Expected Response:
References:
Prompt: "In a table format, compare the key features of electric cars and hybrid cars, focusing only on environmental impact and cost."
Expected Response:
Feature | Electric Cars | Hybrid Cars |
---|---|---|
Environmental Impact | - Zero tailpipe emissions - Reduces greenhouse gases if electricity is from renewable sources |
- Lower emissions than traditional cars - Higher emissions than electric cars due to gasoline use |
Cost | - Generally higher upfront cost - Lower maintenance and fuel costs over time |
- Moderate upfront cost - Fuel savings compared to traditional cars but less than electric cars |
References:
Prompt: "Discuss the ethical considerations of genetic editing in humans, ensuring an unbiased perspective suitable for a graduate-level audience."
Expected Response:
References:
Prompt: "Calculate the final price after a 15% discount on an item that costs $200, and then add a 7% sales tax. Confirm each step."
Expected Response:
References:
Prompt: "Invent a new sport that combines elements of soccer and basketball, and describe how it is played."
Expected Response:
References:
Prompt: "Evaluate the impact of automation on employment, discussing both the positive and negative effects."
Expected Response:
References:
Prompt: "Provide three recent statistics on cybersecurity threats, citing reputable sources."
Expected Response:
References:
Prompt: "Outline the steps needed to plan a successful product launch for a new smartphone."
Expected Response:
References:
Prompt:
[Role]: Financial Analyst
[Task]: Assess the financial viability of investing in renewable energy stocks.
[Constraints]: Focus on data from the last five years.
[Format]: Provide a summary followed by recommendations.
Expected Response:
References:
Prompt: "Before solving, summarize this problem in your own words: 'A cyclist travels at an average speed of 15 km/h for 2 hours and then increases the speed to 20 km/h for the next 1.5 hours. What is the total distance covered?'"
Expected Response:
References:
Prompt: "Who is predicted to win the next presidential election?"
Expected Response:
References:
This project is licensed under the Apache License 2.0.