By this point, you already know what the Prompts are and the importance of writing good prompts. Refer back to the guide “Introduction to prompts” incase you have missed it. For quick recap:
Prompts are a detailed description of desired output expected from the model. It is the interaction between a user and the AI model.
This articles covers the best practices for writing good prompts as well as covering some of the commonly used prompting techniques.
A good prompt
Writing a good prompt is essential for getting accurate and valuable responses from AI models like GPT-3.5. A well-crafted prompt provides clear instructions and context to the model, helping it understand your request and generate the desired output. Here are some tips on how to write a good prompt:
- Be clear and specific:
- Clearly state your question or request. Ambiguity can lead to inaccurate responses.
- Specify what you want the AI to do, whether it’s answering a question, providing information, or generating content.
- Provide context:
- Include relevant background information to help the model understand the topic or scenario.
- If your question refers to a specific context or scenario, describe it briefly.
- Use complete sentences:
- Write prompts in grammatically correct and complete sentences. This makes it easier for the model to understand your intent.
- Ask open-ended questions:
- Encourage detailed responses by asking open-ended questions rather than yes/no or one-word answer questions.
- Be polite and respectful:
- Use a respectful tone and language in your prompt. Avoid making offensive or inappropriate requests.
- Experiment with different phrasings:
- If you’re not getting the desired output, try rephrasing or restructuring your prompt to see if it produces better results.
- Specify the format:
- If you want the response in a specific format (e.g., a list, a summary, a paragraph), mention it in your prompt.
- Limit the scope:
- If your prompt covers a broad topic, consider narrowing it down to make it more manageable for the AI model.
- Include examples:
- Provide examples or sample sentences related to your request to give the model a better idea of what you’re looking for.
- Test and iterate:
- Experiment with different prompts and variations to find the one that works best for your specific task.
- Consider the model’s limitations:
- Be aware of the AI model’s limitations and the knowledge cutoff date. Avoid asking for real-time or extremely recent information.
- Check for spelling and grammar:
- Make sure your prompt is free from spelling and grammatical errors to avoid confusion.
An example of a good prompt,
"Explain the process of photosynthesis in plants."
This prompt is clear, specific, and asks for an explanation of a specific topic. It doesn’t require a complex or lengthy response and provides a straightforward request for information.
Elements of a Prompt
When constructing a prompt, it’s essential to understand the different parts that contribute to its effectiveness. A well-crafted prompt typically consists of instruction and context with optional formatting instruction. Understanding these parts will allow you to engineer prompts that elicit better and more precise responses.
- Question or Instruction: This is the core of your prompt, where you ask a question or provide an instruction to the AI model. It should be clear and specific about what you want.
- Context: Depending on the complexity of your request, you may include relevant context or background information to help the AI model understand the topic or scenario better. Context can provide additional details that clarify your request.
- Formatting Instructions (Optional): If you have specific formatting requirements for the response, you can include them in your prompt. For instance, you might request a bulleted list, a paragraph, or a short summary.
- Tone and Politeness: It’s important to maintain a respectful and appropriate tone in your prompt. Politeness and clarity can lead to better responses.
Here’s an example with these elements:
Question or Instruction: “Can you provide a brief summary of the causes and effects of deforestation in the Amazon rainforest?”
Context: “The Amazon rainforest is a critical ecosystem with significant global implications for biodiversity and climate. I’d like to understand the key factors driving deforestation in this region and the consequences it has on the environment.”
Formatting Instructions (Optional): “Please format your response as a short paragraph.”
Tone and Politeness: “Thank you for your assistance.”
These elements collectively make up a comprehensive prompt that helps the AI model understand your request and provide a relevant response.
Prompt techniques
Role Prompting
It is a technique used to guide the AI model’s response by assigning it a specific role or perspective within a scenario or conversation. By providing a role, you can influence the AI’s behavior and encourage it to generate responses that align with that role. This technique is particularly useful for creating interactive dialogues, simulations, or storytelling.
Here’s how to use role prompting effectively and an example to illustrate it:
How to Use Role Prompting:
- Set the Stage: Start by introducing the scenario or context of the interaction. Describe the setting, characters, or situation to provide a clear foundation for the role-playing.
- Assign Roles: Clearly define the role you want the AI model to assume. Specify the character’s name, characteristics, and any relevant background information. You can also assign roles to other entities or characters within the scenario.
- Provide Instructions: Clearly instruct the AI on how it should respond or act in its assigned role. Include any goals, actions, or behaviors you want the AI to exhibit.
- Engage in Dialogue: Interact with the AI model by assuming a role yourself or conversing with the AI from a different perspective. Keep the conversation coherent by sticking to the roles and context you’ve established.
Example of Role Prompting:
Scenario: The user wants to interact with an AI fitness trainer named “FitBot” to create a workout plan.
User (Role): “You are the user, looking to get in shape and seeking guidance from the AI fitness trainer, FitBot.”
AI (Role – FitBot): “Hello, User! I’m FitBot, your virtual fitness trainer. I’m here to help you achieve your fitness goals. What type of workout plan are you interested in? Are you looking to build muscle, lose weight, or improve your overall fitness?”
User (Role): “I want to build muscle and get stronger, FitBot.”
AI (Role – FitBot): “Great choice! To get started, let’s focus on a 4-week strength-building plan. We’ll work on different muscle groups each day. Here’s a sample plan to consider:
Week 1:
- Monday: Chest and Triceps (Push-ups, Dips)
- Wednesday: Back and Biceps (Pull-ups, Dumbbell curls)
- Friday: Legs (Squats, Lunges)
We’ll gradually increase the intensity as we progress. How does this plan sound to you, User?”
User (Role): “Sounds good, FitBot! But I’m a beginner. Can you recommend some exercises with instructions for each day?”
AI (Role – FitBot): “Of course, User! Here’s a breakdown of the exercises for Week 1:
Monday (Chest and Triceps):
- Push-ups: 3 sets of 10 reps
- Instructions: Start in a plank position with your hands shoulder-width apart. Lower your body until your chest nearly touches the floor, then push back up.
- Dips: 3 sets of 10 reps
- Instructions: Use parallel bars or sturdy furniture. Lower your body by bending your elbows, then push back up.
Remember to warm up before each workout and cool down afterward. And always maintain proper form to prevent injuries. Let’s start with this, and we’ll adjust as needed. Ready to begin, User?”
In this role prompting example, the user interacts with an AI fitness trainer, FitBot, to create a workout plan focused on building muscle. FitBot assumes the role of a virtual fitness trainer and provides a sample workout plan for the user’s goal. As the user requests more details, FitBot continues to play its role by providing exercise recommendations and instructions. This interactive role-play helps the user receive personalized fitness guidance.
Few-shot prompting
It is a technique used to provide a small amount of context or information to an AI model before asking it to perform a task or generate a response. It’s called “few-shot” because it relies on just a few examples or hints to guide the model in understanding and completing a task. This technique leverages the model’s ability to generalize from limited information.
Here’s how few-shot prompting works, along with a simple example:
How Few-Shot Prompting Works:
- Provide Context or Examples: Instead of giving a detailed prompt, you present a minimal amount of context or examples related to the task or question you want the AI model to address. These examples can be in the form of text snippets, questions, or statements.
- Frame the Request: After providing the context or examples, you frame your request or question, specifying what you want the AI to do based on the provided information.
- AI Generalizes: The AI model then generalizes from the provided context or examples to generate a response that aligns with the task or question you’ve framed.
- Review and Refine: You can review the generated response and, if needed, iterate by providing more context or examples to refine the output.
Simple Example of Few-Shot Prompting:
Scenario: You want the AI to generate a short poem about the ocean, but you provide just a few keywords and phrases as context.
Context or Examples:
- “Ocean waves”
- “Golden sands”
- “Endless horizon”
Request (Prompt): “Compose a short poem about the ocean using the provided keywords and phrases.”
AI-Generated Response:
Ocean waves crash on golden sands, Underneath the endless horizon it stands, A world of beauty, vast and wide, Where the ebbing tide is nature's tide.
In this example, you provided minimal context in the form of keywords and phrases related to the ocean. The AI model used this limited input to generate a short poem that incorporates the provided elements. Few-shot prompting allows you to guide the AI’s creativity and generate content with limited input, making it a versatile technique for various tasks.
Chain of Thought
“Chain of Thought” prompting is a technique where you engage in a conversation or dialogue with an AI model by building upon previous responses or thoughts. Instead of providing a single, isolated prompt, you maintain context and continuity in the conversation, creating a natural flow of ideas and information. This technique is particularly useful for interactive and dynamic interactions with AI models.
Here’s how Chain of Thought prompting works, along with a detailed example:
How Chain of Thought Prompting Works:
- Initiate the Conversation: Begin the conversation with an initial question or statement. This sets the stage for the AI model to respond.
- Respond and Continue: After receiving the AI’s response, build upon it by asking follow-up questions, providing feedback, or introducing new ideas. Maintain a conversational flow.
- AI Responds in Context: The AI model responds to each step in the conversation, taking into account the context provided by previous interactions.
- Iterate and Explore: Continue the back-and-forth interaction, exploring various topics or aspects within the same conversation. This allows you to dig deeper into a subject or explore multiple ideas.
- Conclude or Transition: When you’re ready to conclude the conversation or switch to a different topic, provide a clear signal or question to wrap up the current chain of thought.
Example of Chain of Thought Prompting:
Scenario: You want to have a conversation with an AI model about travel destinations. You start with a general question and build upon the AI’s responses to explore different aspects of the topic.
User: “What are some popular travel destinations around the world?”
AI: “Certainly! Some popular travel destinations include Paris, Tokyo, New York City, and Rome. Each of these places offers a unique experience. Where would you like to learn more about first?”
User: “Tell me about Paris. What are the must-visit attractions there?”
AI: “Paris is known for its iconic attractions. The Eiffel Tower, Louvre Museum, and Notre-Dame Cathedral are must-visit spots. Are you interested in historical landmarks, art, or something else in Paris?”
User: “I love art! Tell me about the art scene in Paris.”
AI: “Paris has a vibrant art scene. The Louvre is home to thousands of artworks, including the famous Mona Lisa. There are also many galleries and street art in neighborhoods like Montmartre. Would you like to know more about specific artists or art events in Paris?”
In this example, the user engages in a conversation with the AI model about travel destinations and art. The conversation flows naturally, with each response building upon the previous one. Chain of Thought prompting allows for dynamic and exploratory interactions, making it useful for in-depth discussions on various topics.
Zero Shot Chain of Thought
It is a technique that combines the principles of “Chain of Thought” prompting with the “Zero Shot” capability of an AI model. In this approach, you initiate a conversation with an AI model without providing any initial context or prompt. The AI model generates responses based solely on the ongoing conversation, allowing it to adapt and follow the natural flow of discussion.
Here’s how Zero Shot Chain of Thought prompting works, along with a detailed example:
How Zero Shot Chain of Thought Prompting Works:
- Start the Conversation: Begin the conversation with a general statement or question without providing specific instructions or context. This allows the AI to respond based solely on the ongoing dialogue.
- Engage in a Flowing Conversation: Keep the conversation going by asking questions, making statements, or sharing thoughts. Allow the AI model to respond naturally to each step in the conversation.
- AI Responds Adaptively: The AI model generates responses that build upon the previous messages in the conversation. It adapts to the evolving context and continues the discussion coherently.
- Iterate and Explore: Explore various topics or ideas within the same conversation, just as you would in a real conversation with a person. The AI follows your lead and provides relevant responses.
- Conclude or Transition: When you’re ready to conclude the conversation or switch to a different topic, provide a clear signal or question to wrap up the current chain of thought.
Example of Zero Shot Chain of Thought Prompting:
Scenario: You want to have a free-flowing conversation with an AI model about technology and its impact on society. You initiate the conversation without a specific prompt or context.
User: “Hi there! I’ve been thinking about how technology is shaping our lives. What are your thoughts on that?”
AI: “Hello! Technology has certainly transformed various aspects of our lives. From smartphones to AI-driven assistants, it’s all around us. How do you think it’s impacting us the most?”
User: “I believe it’s changing the way we communicate. We can instantly connect with anyone globally. What’s your take on the future of communication tech?”
AI: “I agree, communication tech is evolving rapidly. In the future, we might see even more immersive forms of communication, like virtual reality meetings. Do you think there are any downsides to this constant connectivity?”
User: “Absolutely, there are concerns about privacy and digital overload. But it’s also opened up new opportunities for remote work and global collaboration. How do you see the balance evolving?”
AI: “Finding the right balance is key. As tech continues to advance, there will likely be more emphasis on user control and data protection. What do you think will be the next big technological breakthrough?”
User: “That’s a tough one! I’m curious about AI advancements, especially in healthcare. They could revolutionize diagnostics. What are your thoughts on AI in healthcare?”
AI: “AI in healthcare is promising. It can aid in early disease detection and personalized treatment. Ethical concerns and data security will be important to address. What other areas do you see AI making a significant impact?”
User: “AI could also play a role in environmental conservation and sustainability efforts. By analyzing data, it could help us make informed decisions to protect our planet. How do you envision AI contributing to that?”
AI: “You’re spot on! AI can analyze vast amounts of environmental data and support conservation efforts. For example, it can help track and protect endangered species. It’s exciting to see tech used for positive change. What other tech-driven changes are you excited about?”
User: “Space exploration! With advancements in technology, we’re inching closer to exploring other planets. It’s a fascinating time for science and discovery. What’s your perspective on our future in space?”
AI: “Space exploration is indeed thrilling. The future might hold exciting missions to Mars and beyond. It’s a testament to human innovation. Where would you like to see our exploration efforts directed in the coming years?”
In this example, the user initiates a conversation about technology’s impact on society without providing an initial prompt. The AI model adapts to the conversation’s flow, providing responses based on the evolving context. This allows for a dynamic and exploratory discussion on various topics related to technology and its implications. Zero Shot Chain of Thought prompting enables a more natural and interactive conversation experience.
Least to Most Prompting
It is a technique used to guide an AI model’s response by gradually providing it with additional information or context, starting with minimal guidance and progressively adding more details until the desired output is achieved. This approach allows you to control the level of assistance provided to the AI model and helps refine the response iteratively.
Here’s how Least to Most Prompting works, along with a detailed example:
How Least to Most Prompting Works:
- Start with a Minimal Prompt: Begin with a basic or open-ended prompt that provides minimal information or context. This is the “least” amount of guidance.
- Review the Initial Response: Evaluate the AI’s initial response to the minimal prompt. This response may be incomplete or require further refinement.
- Add Incremental Details: Gradually introduce additional information, context, or instructions to guide the AI model toward the desired output. These details are added step by step, moving from the “least” to the “most” guidance.
- Review and Refine: After each iteration, assess the AI’s response and continue to add more details as needed until you achieve the desired outcome.
- Conclude or Transition: Once you’re satisfied with the response or have obtained the information you need, you can conclude the interaction or transition to a different topic or task.
Example of Least to Most Prompting:
Scenario: You want the AI model to provide a recipe for chocolate chip cookies. You start with minimal guidance and gradually provide more details.
- Minimal Prompt (Least Guidance): “Can you give me a recipe for cookies?”
AI: “Sure, here’s a basic cookie recipe: Combine flour, sugar, eggs, butter, and baking powder. Mix and bake at 350°F.”
(The initial response is too vague and lacks important details.)
- Add More Details (More Guidance): “Can you provide a recipe for chocolate chip cookies? Start with the ingredients.”
AI: “Certainly! For chocolate chip cookies, you’ll need the following ingredients: 2 1/4 cups all-purpose flour, 1/2 teaspoon baking soda, 1 cup unsalted butter, 1/2 cup granulated sugar, 1 cup packed brown sugar, 1 teaspoon salt, 2 teaspoons pure vanilla extract, 2 large eggs, and 2 cups semisweet chocolate chips.”
(The response now includes the list of ingredients, but the steps are still missing.)
- Provide More Instructions (Even More Guidance): “Great! Now, could you please give me the step-by-step instructions on how to make the cookies?”
AI: “Of course! Here are the step-by-step instructions for making chocolate chip cookies:
- Preheat your oven to 350°F (175°C).
- In a small bowl, mix the flour and baking soda.
- In a separate large bowl, cream together the butter, granulated sugar, brown sugar, and vanilla extract.
- Beat in the eggs one at a time, then stir in the flour mixture.
- Finally, fold in the chocolate chips.
- Drop rounded tablespoons of cookie dough onto ungreased baking sheets.
- Bake for 10-12 minutes, or until the edges are golden brown.
- Allow the cookies to cool on the baking sheet for a few minutes before transferring them to wire racks to cool completely.”
(Now the response includes the complete recipe with step-by-step instructions.)
In this example, Least to Most Prompting begins with a minimal request for a cookie recipe and gradually adds more details and context to guide the AI model toward providing the desired outcome, which is the complete chocolate chip cookie recipe with instructions. This technique allows for a more controlled and iterative interaction with the AI model.
Dual Prompt Approach
It is a technique that involves presenting two related prompts to an AI model simultaneously. By using two prompts, one providing context or information and the other specifying the task or question, you can guide the AI’s response more effectively. This approach helps ensure that the AI understands both the context and the specific request, resulting in more accurate and relevant responses.
Here’s how the Dual Prompt Approach works, along with a detailed example:
How the Dual Prompt Approach Works:
- Context Prompt: The first prompt sets the context by providing relevant information, background, or context related to the topic or task.
- Task Prompt: The second prompt specifies the desired task, question, or instruction you want the AI model to follow based on the provided context.
- AI Processes Both Prompts: The AI model processes both prompts simultaneously, using the context from the first prompt to inform its response to the task specified in the second prompt.
- AI Generates a Response: The AI generates a response that integrates the context and task, ensuring that the output is directly related to the provided information and the specific request.
- Review and Refine: After receiving the response, you can review it and make any necessary adjustments to the context or task prompts to fine-tune the AI’s output.
Example of the Dual Prompt Approach:
Scenario: You want to obtain information about the historical significance of the Great Wall of China. You use the Dual Prompt Approach to ensure that the AI model understands both the context and the specific question.
Context Prompt: “The Great Wall of China is a UNESCO World Heritage site and a symbol of China’s rich history. It stretches over thousands of miles and has a fascinating history.”
Task Prompt: “Can you provide details about the historical significance of the Great Wall of China and its role in Chinese history?”
AI-Generated Response: “Certainly! The Great Wall of China holds immense historical significance. It was constructed over several centuries, starting in the 7th century BC, primarily during the Qin, Han, and Ming dynasties. The wall served various purposes, including defense against invasions by nomadic tribes, trade regulation, and border control.
One of its most significant historical roles was as a protective barrier against raids and invasions by northern nomadic tribes, such as the Xiongnu. It played a vital role in safeguarding Chinese states and promoting cultural exchange along the Silk Road.
Additionally, the Great Wall symbolizes the unity and determination of the Chinese people throughout history. Its construction involved the labor of countless workers and soldiers, becoming a testament to China’s ancient engineering prowess.
In modern times, it has become a symbol of national identity and a prominent tourist attraction, drawing millions of visitors from around the world. Overall, the Great Wall of China is a remarkable historical monument that reflects China’s enduring cultural and historical heritage.”
In this example, the Dual Prompt Approach is used to provide the AI model with context about the Great Wall of China’s significance and then specify the task of providing historical details. The resulting response seamlessly integrates both the context and the specific information requested, resulting in a comprehensive and relevant answer.
Combining Techniques
It refers to the practice of using multiple prompting techniques together to achieve specific goals or to generate more comprehensive and tailored responses from AI models. By combining techniques, users can leverage the strengths of different approaches to obtain more accurate, detailed, or creative outputs.
Here’s an explanation of how combining techniques work, along with an example:
How Combining Techniques Work:
- Identify the Goal: Determine the specific objective or information you want to obtain from the AI model. Consider whether a single technique is sufficient or if a combination of techniques can better achieve the desired outcome.
- Select Appropriate Techniques: Choose the prompting techniques that best align with your goal. These techniques can include question-answering, role-playing, few-shot prompting, chain of thought, and more.
- Sequence and Structure: Decide on the sequence and structure of the combined techniques. Determine the order in which you’ll apply each technique and how they will complement each other.
- Execute and Iterate: Present the prompts using the selected techniques in the designated order. Evaluate the AI’s responses and make adjustments as needed. You may need to iterate or refine the combination to achieve the desired result.
- Review and Fine-Tune: Review the generated content, and fine-tune the combination of techniques if required. Ensure that the output is coherent, accurate, and aligned with your goals.
Example of Combining Techniques:
Scenario: You want to engage in a creative writing exercise with an AI model to generate a fictional story about space exploration. To achieve this, you decide to combine the “role-playing” and “creative writing” techniques.
Combination of Techniques:
- Role-Playing Technique:
- “You are the user, and you are an astronaut embarking on a mission to explore a distant galaxy. Describe the excitement and anticipation you feel as you prepare for this epic journey.”
- Creative Writing Technique:
- “Now, as the AI model, craft a vivid and imaginative narrative that brings to life the astronaut’s journey. Describe the spacecraft, the alien worlds, and the challenges they encounter during this intergalactic expedition.”
AI-Generated Response:
(Astronaut’s Perspective – Role-Playing) “I can hardly contain my excitement! Tomorrow, I’ll be boarding the StarQuest-9 spacecraft, the pinnacle of human engineering. As I go through my final preparations, I think about the endless possibilities that await me in the uncharted territories of space.”
(Creative Writing – AI Model) “The StarQuest-9 gleamed in the morning sun, its sleek design a testament to human ingenuity. It hummed with life as I boarded, and the countdown began. Our journey would take us to distant galaxies, where alien worlds with vibrant ecosystems awaited.
The first stop was the luminous planet of Zephyria, where we marveled at phosphorescent flora and met a species of sentient energy beings known as the Luminescents. Their wisdom and kindness left a lasting impression. But our expedition wasn’t without challenges. The asteroid belt of Nebulae-7 tested our skills, and a cosmic storm threatened to derail our mission.
Yet, our determination and teamwork prevailed. We pushed deeper into the cosmos, encountering wonders beyond imagination. Each new discovery was a testament to the human spirit’s quest for knowledge and adventure.”
In this example, combining the “role-playing” technique with “creative writing” results in a narrative that seamlessly transitions from the user’s perspective as an astronaut to the AI model’s imaginative storytelling. This combination allows for an engaging and immersive fictional story about space exploration.
What to avoid when creating prompts?
Before rounding up, they are some things we should avoid when creating prompts:
- Information Overload (Ambiguity): Try as much as possible to provide brief information since it could become junk and reduce the accuracy of the results.
- Open-Ended Questions: It is recommended that we avoid asking inexact or open-ended questions. A vague question might be: Can you help me find my way home? They are non-specific and too generic and will cause imprecision and less resourceful responses.
- Poor Use of Constraints: Constraints are boundaries and limitations to how scattered a situation can get. This requires providing specific requirements. This could be to role-play the model.
Conclusion
In conclusion, prompts play a crucial role in obtaining accurate and valuable responses from AI models. They provide clear instructions and context to the model, guiding it to generate desired output. To create effective prompts, it’s essential to be clear, specific, and polite, provide context, use complete sentences, and consider the format you want the response in. Additionally, you can experiment with different phrasings, limit the scope, include examples, test and iterate, and be mindful of the model’s limitations.