AI Prompting Guide
This is a brief "getting started" guide on how to get the most out of AI Assistants through effective "prompt engineering".
You can find an easy-to-reference simple guide with a downloadable poster here.
What is "Prompt Engineering"?
"Prompt Engineering" is the practice of crafting instructions (prompts) to guide generative AI models towards producing the desired output.
Prompt engineering is like giving directions to a helpful but unfamiliar visitor.
Just as clear directions help someone navigate to the right destination, well-crafted prompts guide AI assistants to produce the results you want.
The better your directions, the more likely you'll get exactly what you're looking for.
What makes a good prompt?
A good prompt will be clear and concise. It will provide relevant background context, describe the action you want it to take, state the format you want the response to be in, and will often contain examples or references.
One of my favourite quotes was from Amanda Askell in a YouTube video on prompt engineering. Here's a rough paraphrasing of what she said:
Imagine you've hired a temporary worker for a task.
They're skilled and knowledgeable about your industry, but they've just arrived and know nothing about your specific situation.
They ask, "I'm here to help - what would you like me to do?"
What instructions would you give this person to get the job done correctly?
What is a useful prompt structure?
To help remember this we can use the mnemonic "CAFE":
Context
Action
Format
Examples
Remember, once you have a response you can iterate on the output with the AI Assistant.
CAFE Framework
Let's go through each of the elements of the CAFE framework. The order of the elements doesn't matter. The important things are clarity and simplicity: prompts should be clear and concise, using normal, natural language and sticking to relevant information.
Context
Provide background information relevant to the action you want to AI Assistant to perform.
This could include context such as the intended audience, your skills, where you are located, or what equipment you have access to.
Let's have a look at a bad example of a prompt without context, then a better one with context.
Bad Example
Make a dinner party menu.
Better Example
I am hosting a Saturday evening dinner party for 12 people. I would like to prepare as much as possible in advance so I have time to socialise. Make a dinner party menu.
Action
Describe in detail the action you want to be completed by the AI Assistant.
Action Verbs
Use action verbs to describe the task you want completing.
Here are some examples as provided by Prompt Engineering by Lee Boonstra:
- Act
- Analyse
- Categorise
- Classify
- Contrast
- Compare
- Create
- Describe
- Define
- Evaluate
- Extract
- Find
- Generate
- Identify
- List
- Measure
- Organise
- Parse
- Pick
- Predict
- Provide
- Rank
- Recommend
- Return
- Retrieve
- Rewrite
- Select
- Show
- Sort
- Summarise
- Translate
- Write
Provide positive criteria over negative constraints
As a general rule, tell the AI Assistant what to do rather than what not to do. That is to say, focus on positive criteria rather than negative constraints.
For example, a positive criteria could be "use vegan-friendly, plant-based ingredients", whereas a negative constraint could be "do not use meat, fish, eggs, or dairy".
For another example, a positive criteria could be "be concise and use clear section headings and subheadings for easy referencing", as opposed to negative constraints such as "do not use long sentences and large blocks of text".
Bad Example
I need a dinner party menu. Don't include meat, fish, eggs, or dairy. Don't use ingredients which are difficult to find.
Better Example
Create a dinner party menu using plant-based ingredients suitable for vegans. The ingredients should be easily available in Britain.
Format
The more specific you can be about the output format the better.
This can include information such as:
- tone (eg. humorous or formal)
- length (eg. in-depth or fit on one side of A4 paper)
- medium (eg. PowerPoint presentation slides or easy to reference note)
- layout (eg. bullet points or descriptive paragraphs)
Example
The menu should be concise and easy to reference, making use of clear sections headed by the time the different elements need attention.
Examples
Providing examples can be key to getting a good output. The sweet spot is around two to five examples in what is called "few shot" prompting. By contrast providing one example is called "one shot" prompting, and no examples is called "zero shot" prompting.
Example
On two previous occasions, the meals I cooked went down really well with guests. The first was a dish based around crispy sesame tofu with a peanut sauce; and the second was a red wine mushroom bourguignon.
Formatting examples
It is important to make it clear that the examples are examples. Most of the time it should eb quite clear, however you can make it really specific by using XML tags. For example:
Here are examples of previous menu items which have been popular:
<example>Vegan Scallops with Paprika Sauce</example>
<example>Potato Cream with Caramelised Leek & Saffron</example>
<example>Broccoli with Black Garlic & Olive Dressing</example>
Putting it all together
Dinner party prompt
We started with a basic bad example prompt of "make a dinner party menu". Using the CAFE framework we could engineer our prompt to provide a much better output.
I am hosting a Saturday evening dinner party for 12 people. I would like to prepare as much as possible in advance so I have time to socialise.
Create a dinner party menu using plant-based ingredients suitable for vegans. The ingredients should be easily available in Britain.
The menu should be concise and easy to reference, making use of clear sections headed by the time the different elements need attention.
On two previous occasions, the meals I cooked went down really well with guests. The first was a dish based around crispy sesame tofu with a peanut sauce; and the second was a red wine mushroom bourguignon.
Book recommendation prompt
For another example, here's a prompt I used recently to find new books to read at bedtime.
I'm looking for some book recommendations, in particular ones which I can read before going to bed.
For this I would prefer shorter novels, or short stories.
I particularly enjoy books which make me think a bit about deeper subjects like philosophy, politics, ethics, religion, and culture.
Recently I have enjoyed Ishmael by Daniel Quinn as a bedtime read. Other books I have enjoyed, though not for bedtime reading, have been the Dune novels, Project Hail Mary, Philip Pullman's His Dark Materials books, Ken Follett's Kingsbridge novels, and the Three Body Problem trilogy. Provide me with 10 book suggestions, each with a one line description of why you think the suggestion fits.
Iterate
Once you have entered your initial prompt and received a response, evaluate it to see if the response meets your requirements. Hopefully your initial prompt will be good enough that you can follow up, if not then some re-writing of the prompt might be required.
Following up
If the response is close to meeting your requirements, you can discuss the response with the AI Assistant. This might be requesting a change, clarifying what you meant, or asking for further information.
Example
That plan looks good in general, however one of the guests has a severe allergy to tomatoes. Can you update the menu to account for that?
Could you also suggest some wine and other drinks which would pair well?
Re-writing
If the response is quite far off what you would like, you can try rewriting the prompt using one or more of the following techniques:
- ensure the CAFE framework is followed, in particular by adding better examples or including more positive criteria
- break the prompt down into smaller tasks, following up with each smaller task after the first response from the AI Assistant
- changing to an analogous or synonymous task by rephrasing in a different context
Examples
Revisiting the CAFE framework
That looks good, however some of those ingredients will be difficult to find. Can you update the menu to include ingredients easily available from standard British supermarkets, such as Tesco and ASDA?
Breaking the prompt down into smaller tasks
- I am hosting a Saturday evening dinner party for 12 people. I would like to prepare as much as possible in advance so I have time to socialise.
Create a main course recipe using plant-based ingredients suitable for vegans. The ingredients should be easily available in Britain.
The recipe should be concise and easy to reference, making use of clear sections headed by the time the different elements need attention.
On two previous occasions, the meals I cooked went down really well with guests. The first was a dish based around crispy sesame tofu with a peanut sauce; and the second was a red wine mushroom bourguignon. - Can you now create a vegan starter that would go well before this main.
- Could you now create a vegan dessert that would finish off the meal nicely?
Changing to an analogous or synonymous task
I would like you to take on the role of an diligent and respectful dinner party host who is hosting a Saturday evening dinner party for 12 people. In this role you would want to spend as much time in the company of the guests, and prepare food suitable for all.
The food should use ingredients easily available in the United Kingdom, and be suitable for vegans.
The menu should be concise and easy to reference, making use of clear sections headed by the time the different elements need attention.
Past successful dinner parties included on the menu: a dish based around crispy sesame tofu with a peanut sauce; and a red wine mushroom bourguignon.