As we cover more and more examples and potential applications with prompt engineering, you will notice that there are certain elements that make up a prompt.
A prompt may contain any of the following components:
Instruction - a specific task or instruction you want the model to carry out.
Context - may involve external information or additional context that can guide the model toward better responses.
Input Data - this is the input or question we are interested in finding an answer for.
Output Indicator - indicates the type or format of the output.
Not all components are required for a prompt, and the format depends on the task at hand. We will cover more concrete examples in upcoming guides.
TIP:
Start Simple
When beginning to create prompts, you should keep in mind that it is truly an iterative process that requires a lot of experimentation to achieve the best results. Using a simple playground like OpenAI or Cohere’s is a good starting point.
You can start with simple prompts and continue adding more elements and context as you seek better results. Version control of your prompt along the way is vital for this reason. As you read the guide, you will see many examples where specificity, simplicity, and conciseness often yield better results.
When you have a large task that involves many different subtasks, you might try breaking the task down into simpler subtasks and keep increasing complexity as you get better results. This prevents adding too much complexity to the prompt design process initially.
In addition to understanding the elements that make up a prompt, we have separated some tips to make your prompt even better!
The Instruction
You can create effective prompts for various simple tasks using commands to instruct the model on what you want to achieve, such as "Write," "Classify," "Summarize," "Translate," "Sort," etc.
Keep in mind that you also need to experiment a lot to see what works best. Try different instructions with different keywords, contexts, and inputs to see what works best for your specific use case and task. Generally, the more specific and relevant the context is to the task you are trying to execute, the better. We will address the importance of sampling and adding more context in upcoming guides.
Others recommend placing the instructions at the beginning of the prompt. It is also recommended to use a clear separator like "###" to separate the instruction and the context.
For example:
Prompt:
### Instruction ###
Translate the text below into Spanish:
Text: "hello!"
Output:
¡Hola!
Specificity
Be very specific about the instruction and the task you want the model to perform. The more descriptive and detailed the prompt is, the better the results will be. This is particularly important when you have a desired outcome or generation style that you are looking for. There are no specific tokens or keywords that lead to better results. It is more important to have a good format and a descriptive prompt. In fact, providing examples in the prompt is very effective for obtaining the desired output in specific formats.
When creating prompts, you should also keep in mind the size of the prompt, as there are limitations on how large it can be. Thinking about how specific and detailed you should be is something to consider. Including too many unnecessary details is not necessarily a good approach. The details should be relevant and contribute to the task at hand. This is something you will need to experiment with a lot. We encourage much experimentation and iteration to optimize your application prompts.
As an example, let’s try a simple prompt to extract specific information from a text.
Prompt:
Extract the names of places from the following text.
Desired format: Location: <list_of_place_names_separated_by_commas>
Input: "Although these developments are encouraging for researchers, much is still a mystery.
“Often we have a black box between the brain and the effect we see on the periphery,” says Henrique Veiga-Fernandes, neuroimmunologist at the Champalimaud Center for the Unknown in Lisbon.
“If we want to use it in a therapeutic context, we really need to understand the mechanism."
Output:
Location: Champalimaud Center for the Unknown, Lisbon
The input text is obtained from this article in Nature(opens in a new tab).
Avoid Ambiguities
Given the tips above on how to be detailed and improve the format, it’s easy to fall into the trap of wanting to be too clever with prompts and potentially creating imprecise descriptions. It is generally better to be specific and straightforward. The analogy here is very similar to effective communication - the more straightforward it is, the more effective the message is conveyed.
For example, you might be interested in learning the concept of prompt engineering. You might try something like:
Explain the concept of prompt engineering. Keep the explanation short, just a few sentences, and don't be too descriptive.
It is not clear in the prompt above how many sentences to use and what style. You may still get a good response with the above prompt, but a better prompt would be one that is very specific, concise, and to the point. Something like:
Use 2 to 3 sentences to explain the concept of prompt engineering to a high school student.
Do or Don’t?
Another common tip when creating prompts is to avoid saying what not to do, but rather say what to do. This encourages more specificity and concentrates on the details that lead to good model responses.
Here’s an example of a movie recommendation chatbot failing exactly at what I do not want it to do because of how I wrote the instruction — focusing on what not to do.
Prompt:
The following agent recommends movies for a customer. DO NOT ASK FOR INTERESTS. DO NOT ASK FOR PERSONAL INFORMATION.Customer: Please recommend a movie based on my interests.Agent:
Output:
Sure, I can recommend a movie based on your interests. What kind of movie would you like to watch? Do you prefer action, comedy, romance, or something else?
Here’s a better prompt:
Prompt:
The following agent recommends movies for a customer. The agent is responsible for recommending a movie from the top trending global films. It should refrain from asking users about their preferences and avoid requesting personal information. If the agent does not have a movie to recommend, it must respond "Sorry, I couldn't find a movie to recommend today."Customer: Please recommend a movie based on my interests.Agent:
Output:
Sorry, I have no information about your interests. However, here is a list of the top trending global films right now: [list of films]. I hope you find something you like!