10 Prompt Engineering Best Practices

10 Prompt Engineering Best Practices

My first time using an artificial intelligence (AI) tool was mind-blowing. I had difficulty debugging a coding issue, and the AI's accuracy was magic. It solved the problem and came up with a solution that was so accurate, I thought I’d be using this tool forever. But after using it for a while, I noticed that the answers weren't as great as they used to be. They weren’t clear, and it made things even more confusing. Was I asking the wrong questions? Was the tool malfunctioning?

My search for answers led me to read many online resources on prompt engineering. I realized the issue wasn't the AI tool, but how I was using it. I was using the correct prompts but wasn't asking them in the best way. If your prompt is clear and organized, the AI will give you more accurate responses. If the prompts are subpar, you will end up with answers that are all over the place or don't make sense.

So, if you want these AI tools to work their best, you must know how to talk to them in a way they understand. But what makes a good prompt? Is it the words you use, the tone, or the context in which you instruct or ask the AI questions? Finding the right balance between all three factors is the key.

This article will discuss the top 10 prompt engineering best practices to help you get the most out of your AI. These tips will help you get more accurate responses, have better AI conversations, and save effort and time.

What is Prompt Engineering?

Prompt engineering connects humans and AI models (Pieces, ChatGPT) through effective communication. It is the art of creating accurate text prompts to get specific responses from an AI model. So, it involves you writing clear and readable prompts to help the AI understand what to do.

Think of prompt engineering as giving instructions or asking an AI model a question to get an answer. As you tell the AI model what to do, it follows your instructions. The better you explain what you want, the better it will perform your task.

It's good to note that prompts can be of different types, and each has its use cases. Below are some of the different kinds of prompts:

  • Questions: These are simple inquiries you ask to get specific information or explanations. Examples of questions include: “What are some ChatGPT prompt engineering best practices?”

  • Statements: Statements are like requesting the AI to do something to get an answer. It involves providing context or offering facts related to your requests. Examples of statements include: “HTML5 semantic elements help improve web accessibility. Describe the benefits of using each semantic component when designing web applications.”

  • Keywords: These are like single words or short phrases you type into the AI to get an answer. Examples of keywords include: "best practices prompt engineering."

  • Phrases: A phrase is an extension of a keyword. It gives your keyword more context and clarifies things for the AI, so it knows what you want. Examples of phrases include: “Explain some best practices for prompt engineering.”

In simple terms, every question is a prompt, but not every prompt is a question. Prompts are a wide range of inputs designed to get a reaction from the AI model.

Want to learn how to prompt beyond the typical guidelines of LLMs? Learn how to create novel AI prompts with Pieces Copilot.

Why Is Prompt Engineering Important?

Large language models perform at their best with prompt engineering. By writing good prompts, you can improve the quality of the answers you get from the AI. It is an important skill for developers and anyone working with AI to get the results they want.

Prompt engineering is important for the following reasons:

  • Creativity Spark: AI is more than a tool for finding easy answers. It also can be valuable when brainstorming if you ask the right questions. Prompt engineering allows you to be more creative with AI. It helps you think of new ideas or perspectives you never considered before.

  • Saves Time: A good prompt will make it easier for you to chat and cut to the chase of what you're looking for in no time. With one or two attempts, you can get the answer you want without chatting back and forth with the AI.

  • Improves Accuracy: A good prompt will help you get the right answers from the AI model. When the AI understands your request, it will give you the exact answers you need. It is essential when dealing with technical topics where accuracy is a must.

  • Facilitates Complex Tasks: It is possible for AI to handle both simple and complex tasks. A good prompt can guide the AI on what to do next during the task. It can structure the tasks into manageable chunks and provide context for them. You will find this very useful if you work in fields like data analysis.

10 Best Practices in Prompt Engineering to Improve Your AI Interactions

Writing good prompts is more than just throwing a bunch of words together. You have to understand how the AI works (and doesn't work) and figure out how to chat in a way that makes sense.

The following prompt engineering best practices will improve your AI interactions.

  1. Be Clear and Specific

When working with AI, clarity and specificity are very important. It's a fundamental technique in prompt engineering that can make or break how well you work with the AI. This practice helps the AI know exactly what you want and gives you the perfect results.

The following tips will help you write clear and specific prompts for an AI:

  • Define the Aim: Defining your aim is the first step to writing a clear prompt. It tells the AI what you're trying to do so it knows what you're aiming for.

  • Use Clear Words: Simple and clear words help the AI know exactly what you're talking about.

  • Provide Context: Providing context helps AI figure out what you are asking for. Context includes adding conditions, requirements, and background information to your prompt.

💡 Prompt Example:

  • Instead of Saying: Explain prompt engineering techniques.

  • Say: Write a 150-200-word summary of prompt engineering techniques for AI optimization. This summary should target AI developers and be technical and concise.

  1. Supply the AI with Relevant Examples

Supplying relevant examples to the AI is one awesome way to speed up AI learning and interaction. It is one of the most effective prompt engineering techniques for producing accurate answers. The process helps the AI understand what you want and gives you better answers. It is handy for complex tasks like generating HTML, CSS, or JavaScript code.

The examples you give to the AI must match the format, quality, and style you are trying to achieve. Keep your examples simple and easy to understand. If you need to, explain your examples so they are relevant to your question. It will help the AI copy your preferred format when giving you the desired answer.

💡 Prompt Example:

Create an HTML structure for a navigation menu. Here's an example of the structure I'm looking for:

<header>
<nav>

<ul>

<li><a href='#'>Home</a></li>

<li><a href='#'>About</a></li>

<li><a href='#'>Contact</a></li>

</ul>

</nav>

</header>

Create a similar structure for a menu with items: Products, Services, Blog, and FAQ. Style it with CSS to make it responsive and make sure it is compatible with various screen sizes.

  1. Give the AI Model a Persona or Frame of Reference

A context- and perspective-rich approach is important when working with AI models. This generated the "give the AI model a persona or frame of reference" technique. This technique helps the AI give intelligent responses that are relevant and logical. It is one of the best ways to help an AI model create better content.

A persona is a made-up character representing the target audience or user. It involves defining the characters' age, occupation, education, interests, and background. A frame of reference gives the AI context to help it understand a situation better. It includes industry or domain, historical events, time frame, social context, location, etc.

The following are steps to give the AI model a persona or frame of reference:

  • Give clear Instructions: Give the AI clear instructions to adopt a particular role. It can include an expert or a beginner role, etc.

  • Paint a Scenario: Paint a scenario that sets the stage for what the AI should do.

  • Define Skill Level: Define how skilled you want the AI to be.

  • Specify Tone: Instruct the AI to adopt a specific tone or emotional state. Examples of these tone and emotional states include formal, informal, happy, and sad.

  • Experiment with Different Personas: Try different personas to find the most effective one.

💡 Prompt Example:

“Imagine you are an artificial intelligence expert. Share your thoughts on what AI might look like in the years to come. Use a technical and informative tone.”

Remember, you can set the tone of the AI's responses to match whatever style you need. Whether you want it to be friendly, technical, formal, or informal, all you have to do is say it in your prompt.

When writing a persona or frame of reference prompt, use the "[persona/frame of reference]: [task/question] with [context/background Information]" prompt structure.

  1. Focus on Positive Instructions

The best approach when working with AI models is to focus on what you want them to do rather than avoid. The "focus on positive instructions" prompt engineering strategy helps the AI achieve this. It helps steer the AI on the right path and results in more creative and relevant results.

The following tips will help you write prompts focused on positive instructions:

  • Start your prompts with action-oriented verbs, e.g., generate, create, and provide.

  • Concentrate on key requirements you want in the result, e.g., accessible and engaging.

  • Don't use words or phrases that tell the AI what not to do, e.g., don't, not, never, and avoid.

  • Highlight the important conditions the AI must meet, e.g., secure and accessible.

💡 Prompt Example:

Let's say you want an AI to generate an article about why dogs are better than cats. Here's how you can apply the practice of focusing on positive instructions:

  • What Not to Do: Don't make it too negative about cats.

  • What to Do: Create an article that explains why dogs are better than cats. Focus on the positive traits of dogs, like loyalty and companionship. Mention that cats have advantages but stress that dogs are generally superior pets.

  1. Get Better Answers by Providing Data

Providing concrete data to the AI helps it give you the correct answers by being specific and detailed. These concrete data include numbers, names, dates, examples, and locations. It allows the AI to understand what is going on and the limits of the task to give more accurate results.

💡 Prompt Example:

  • Prompt: Write an article on artificial intelligence.

  • Concrete Data: Write an article discussing how AI improves healthcare. Discuss its effect on patient care and examples of AI tools for finding drugs, like NVIDIA's Clara platform.

  1. Try Chain of Thought Prompting

A chain of thought prompting technique helps AI models generate better responses. It guides an AI to break down a problem or question into smaller steps to give more accurate answers. This way, the AI goes into more detail to explain why it came up with that answer. It is great for tackling multiple-step problems or scenarios requiring thorough analysis.

Some of the steps involved in the chain of thought prompting are as follows:

  • Identify the Task: Decide what task you want the AI to do or what question you want it to answer.

  • Break Down the Task: Break the task into smaller, doable steps. Aim to make each step build upon the one before.

  • Connect the Steps: Highlight the connections between the different steps. Use transitional phrases like "next," "now," "then," or "after" to connect the steps.

  • Encourage Explanation: Ask the AI to explain its reasoning for you as it goes along each step.

💡 Prompt Example:

Prompt: You want to create a simple HTML page with a styled button.

  • Prompt: Let's create a basic HTML structure for a webpage. First, define the structure using HTML5 syntax.

  • AI Response: Creates a webpage using HTML5 syntax...

  • Prompt: Good. Now, let's add a button inside the body of the HTML. Don't forget to add some text on the button.

  • AI Response: Adds a button with a text...

  • Prompt: Great. Let's add some styling to this button. Can you write CSS that makes the button green with white text and add some padding?

  • AI Response: Styles the button with a green background color and white text...

  • Prompt: Perfect! Now, let's make sure that when the user hovers over the button, the background color changes to light green.

  • AI Response: Adds a hover effect to the button…

  1. Specify Your Desired Output

Getting the desired result from AI models depends heavily on how well you specify your goals. As a result, it is one of the most important best practices for prompt engineering. It helps the AI produce replies that adhere to your format, content, and style preferences.

The following are steps on how to specify your desired output to the AI:

  • Specify the format you want your answer, e.g. bullet points, lists, tables, and code snippets.

  • Outline the specific data points, examples, or elements you expect in your response. It could be how long you want the response, like saying, "Create a 2000-word article on ...." for example.

  • Let the AI know what style or tone you want, whether formal, casual, technical, or creative.

💡 Prompt Example:

Generate an article of 2000 words on how artificial intelligence is improving healthcare. The article should include:

  • An introduction talking about how AI is taking over healthcare.

  • A section on how machine learning is improving diagnostics.

  • A section on how AI is getting involved in personalized medicine.

  • A section listing the examples of AI tools for finding drugs, like NVIDIA's Clara platform.

  • Use Bullet points summarizing key benefits of AI in each section.

  • The tone should be formal, and the content should be technical.

  1. Take an Experimental Approach to Prompting

Developing creative prompts requires experimentation, one of the prompt engineering strategies. It involves testing various prompts to see which ones get the AI to give the best answers. Each test helps you get more accurate and creative results.

Instead of thinking of prompts as something you do once, think of them as a continuous process. It helps you to become more innovative and adaptable to make your AI interactions work better for you.

The following tips will help you experiment with various prompts:

  • Test new prompts and analyze the results. Try rewording or removing a phrase (prompt), and change the tone and format. Ask the same question in a few different ways to see what kinds of answers you get. Also, try out specific, open-ended prompts to see how much control you want to give the AI.

  • Compare the results from testing the various prompts to see which ones work the best for you.

  • Edit and improve your prompts based on the results of your experiments.

  • Get creative by thinking outside the box to spark some new ideas. Use comparisons or storytelling techniques to get more creative.

💡 Prompt Examples:

Ask the same question in a few different ways to see what answers you get:

  • Prompt 1: Explain how CSS grids work.

  • Prompt 2: Describe how to use CSS grids to center content.

  • Prompt 3: What's the best way to arrange elements in a web page using CSS grids?

Ask specific, open-ended prompts to see how much control you want to give the AI:

  • Open-ended Prompt: Design a log-in button.

  • Specific Prompt: Design a log-in button with a red background, white text, and a hover effect that changes the text color to black.

  1. Understand the AI Model’s Limitations

Knowing the limitations of the AI model is an important part of writing good prompts. It lets you tailor your prompts to work around those limits and get better responses.

Some common limitations of AI models are as follows:

  • Lack of Current Data: Most AI models can only access information up to a specific date (cut-off date). If you ask about current events and it's after the model's cut-off date, it won't have the most recent answer.

  • Overreliance on Patterns: Relying too much on patterns is a major downside of AI models. AI models come up with answers by picking up on patterns from their training data. It means that the results will be repetitive and not very detailed. So, you will keep receiving similar responses as it uses only the information it already has. It doesn't create new solutions for each situation. For example, if you ask an AI model to write an article introduction about "artificial intelligence," it might start with something like, "In today's fast-paced world of artificial intelligence..." since it has seen that pattern a lot in similar texts.

  • Biased Training Data: AI models may pick up biases from their training data. These biases come out as racial or ethnic stereotypes and more.

  • Inaccuracy: AI models are not perfect when delivering accurate information. They may hallucinate or come up with convincing but wrong information. It happens most times when asked about topics outside their training data. For example, the AI might create details about a historical event that never happened.

  • Limited Emotional Understanding: AI does not understand emotions the way humans do. It can imitate sympathetic reactions, but it lacks human complexity and nuance.

Knowing the limitations of AI is an important prompt engineering strategy. It helps you see any biases or mistakes that could happen and think of better prompts. Remember to use reliable sources to double-check any novel information you get from an AI.

  1. Consider Potential Biases and Ethical Implications

AI models pick up information from a ton of data from multiple sources like websites and articles. However, sometimes, this data might have some biases or unfair opinions. It is just like real life, where stereotypes and misinformation are everywhere. Due to this, the AI could end up producing biased or inaccurate responses by mistake.

Avoid biases when writing your prompts if you want the AI to be on point and fair with its results. These biases may manifest as racism, sexism, or classism, among other forms.

The following tips will help you write ethical prompts:

  • Use words that are inclusive, impartial, and free of bias. For example, instead of saying "suffers from a disability," say "a person with a disability."

  • Ask the AI to give a mix of opinions and viewpoints in its answers. This way, the response won't be one-sided or biased.

  • Don't write prompts that make assumptions about people based on gender, race, or age. For example, instead of saying, "Older people struggle using technology", say, "Some individuals might have a hard time with new technology, no matter how old they are."

  • Every time the AI responds, review it.

The Best Prompt Engineering Tools

Prompt engineering requires you to use the right tools. They help you give better instructions to the AI model for better results. The following are some of the best prompt engineering tools:

  • Large Language Models (LLMs): LLMs are the most powerful tools in the AI arsenal. They generate human-like text based on patterns learned from vast inputs of text data. Examples of LLMs include GPT-4o and Claude 3.5 Sonnet, which can both be used for free with Pieces.

  • AI Copilots: AI copilots combine all of the other mentioned tools in order to easily generate text, code, and images. Copilots like Pieces Copilot integrate with your existing tools so that you can use your workflow as context, creating automatically superior prompts and useful outputs.

  • Text Generation Tools: These tools use LLMs to create text based on your prompt. They offer pre-built templates for different use cases, e.g., blogs and social media posts, so you save time and make awesome content without too much work. Examples of these text-generating tools include Jasper AI, Writesonic, and Copy AI.

  • Prompt Optimization Tools: These tools aim to help you write better prompts. They allow you to tweak and improve your prompts to get better responses from AI copilots like Pieces. Examples of prompt optimization tools include FlowGPT, Promptly and PromptPerfect.

Choosing the right prompt engineering tool depends on what you need and prefer. Try out different tools until you find the best one for you.

Conclusion

Prompt engineering is the art of asking good questions to get accurate responses from AI. Prompt engineering best practices involve knowing the strengths of the AI and tweaking your prompts to get correct answers. You have to be creative, clear and specific with your prompts to get the answers you need.

Note that prompt engineering is a continuous learning process. It requires constant practice and experimentation to understand how it works. The more you practice, the better you become. The best way to learn prompt engineering? Study the best practices outlined in this article.