Exploring digital lands together

Your ultimate guide to crafting effective prompts for language models

Development
This is some text inside of a div block.

Prompt design plays a crucial role in obtaining accurate and high-quality responses from language models. It involves creating well-structured prompts that will get the answer you want. Whether you're asking a question, providing instructions, or offering examples, the way you design your prompts can significantly impact the response you receive. 

In this blog post, we'll introduce you to some fundamental concepts, strategies and best practices for prompt design.

What is a Prompt?

A prompt is a natural language request submitted to a language model to receive a response. Prompts can take various forms, such as questions, instructions, contextual information, examples or partial input. Depending on the type of model being used, prompts can generate text, embeddings, code, images, videos, music and more.

Types of Prompt Content

When designing a prompt, you can include different types of content to help the model understand what you want. These content types are input, context and examples.

Input

Input is the text in the prompt to which you want the model to respond. It's a required content type and can take the form of a question, a task, an entity or a completion input.

Question Input

Question input prompts the model to answer a specific question. For example:

Prompt
What's a good name for a flower shop that specialises in selling bouquets of dried flowers?
Response
  • Dried Blooms
  • Floral Arrangements
  • The Flower Shop
  • A Touch of Nature
  • Bouquets Galore
  • The Perfect Bloom
  • Scented Splendour
  • Dried Flower Arrangements
  • Preserved Petals

Task Input

Task input prompts the model to perform a task or provide suggestions. For example:

Prompt
Give me a list of things that I should bring with me on a camping trip.
Response
Tent, sleeping bag, sleeping pad, camping stove, cooking utensils, food, water, first aid kit, flashlight, lantern, matches or lighter, trash bags, map and compass, sunscreen, insect repellent, hat, sunglasses, and rain gear.

Entity Input

Entity input prompts the model to perform an action on a specific entity. It can benefit from including instructions. For example:

Prompt
Classify the following items as [large, small].

Elephant Mouse Snail
Response
Elephant is large. Mouse is small. Snail is small.

Completion Input

Completion input prompts the model to complete or continue a given text. For example:

Prompt
Some strategies to overcome writer's block include
Response
  • Freewriting: This is a technique where you write whatever comes to mind, without stopping to think about grammar or spelling. This can help you generate ideas and get your creative juices flowing.
  • Brainstorming: This is a technique where you write down all of the ideas that come to mind, without judging them. Once you have a list of ideas, you can start to narrow them down and develop them further.
  • Mind mapping: This is a technique where you draw a diagram of your ideas, connecting them with lines to show how they relate to each other. This can help you visualise your ideas and see how they fit together.
  • Taking a break: Sometimes, the best way to overcome writer's block is to take a break from writing and do something else for a while. This can help you clear your head and come back to your writing with fresh eyes.
  • Getting help from others: If you're struggling to overcome writer's block, don't be afraid to ask for help from others. You can talk to a friend, family member, or teacher, or you can seek professional help from a therapist or writing coach.

Context

Context in prompts can take the form of either instructions for the model's behaviour or information the model uses to generate a response. Including contextual information helps provide necessary details or limit the response boundaries. For example:

Prompt
Marbles: Colour: red Number: 12 Colour: blue Number: 28 Colour:
yellow Number: 15 Colour: green Number: 17

How many green marbles are there?
Response
There are 17 green marbles.

Examples

Examples in prompts are input-output pairs that guide the model in generating an ideal response. They are effective for customising the response format. For example:

Prompt
Classify the following.

Options:

red wine
white wine
Text: Chardonnay The answer is: white wine Text: Cabernet The answer is: red wine Text: Moscato The answer is: white wine

Text: Riesling
The answer is:
Response
white wine

Prompt Design Strategies

Even if you’re new to machine learning, prompt design allows you to shape the responses generated by these models with minimal effort. By carefully constructing prompts, you can guide the model to produce your desired results.

While there's no one-size-fits-all approach to prompt design, there are common strategies you can use to influence the model's responses. In the following sections, we will explore these strategies in more detail and give you the knowledge to design prompts effectively. Let's dive in and discover the key techniques so you can unlock the full potential of prompt design.

Giving Clear Instructions

One effective strategy in prompt design is to provide clear instructions to the model. By giving explicit guidance, you can customise the behaviour of the language model to suit your needs. It's important to ensure that the instructions are clear and concise for best results.

For example, you can provide a prompt that instructs the model to summarise a given text:

Prompt
Summarise this text.
Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentially faster than any modern traditional computer. At very tiny scales, physical matter acts as both particles and as waves, and quantum computing uses specialised hardware to leverage this behaviour. The operating principles of quantum devices are beyond the scope of classical physics. When deployed at scale, quantum computers could be used in a wide variety of applications such as: in cybersecurity to break existing encryption methods while helping researchers create new ones, in meteorology to develop better weather forecasting, etc. However, the current state of the art quantum computers are still largely experimental and impractical.
Response
A quantum computer is a device that uses quantum mechanics to perform calculations. It can perform calculations exponentially faster than any modern traditional computer. Quantum computers use specialised hardware to leverage the behaviour of physical matter at very tiny scales. This behaviour is beyond the scope of classical physics. When deployed at scale, quantum computers could be used in a wide variety of applications. These include cybersecurity, meteorology, and drug discovery. However, the current state of the art quantum computers are still largely experimental and impractical.

In the above example, the model provides a concise summary of the given text. However, if you want the summary to be understood more easily, you can ask it to write the summary in a way that a fifth grader can understand:

Prompt
Summarise this text.
Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentially faster than any modern traditional computer. At very tiny scales, physical matter acts as both particles and as waves, and quantum computing uses specialised hardware to leverage this behaviour. The operating principles of quantum devices are beyond the scope of classical physics. When deployed at scale, quantum computers could be used in a wide variety of applications such as: in cybersecurity to break existing encryption methods while helping researchers create new ones, in meteorology to develop better weather forecasting, etc. However, the current state of the art quantum computers are still largely experimental and impractical.
Response
A quantum computer is a new kind of computer that uses different rules than regular computers. It can do some calculations much faster than regular computers. Quantum computers are still being developed, but they could be used for things like breaking codes and weather forecasting.

By adding the instruction to simplify the summary for a fifth grader, the model generates a response that is easier to understand.

Summary:

  • To customise the behaviour of the model, give clear and concise instructions
  • Adding specific instructions can help you to tailor the output to your desired level of complexity

Using Examples in Prompts

Including examples in your prompts can help to guide the model's responses. Examples provide the model with a clear understanding of the expected output and help it to identify patterns and relationships. Prompts with examples are called few-shot prompts, while prompts without examples are called zero-shot prompts. Few-shot prompts are useful for regulating formatting, phrasing, scoping or general patterns of model responses.

Zero-shot vs Few-shot Prompts

A zero-shot prompt does not include any examples and asks the model to choose the best explanation. For example:

Prompt
Please choose the best explanation to the question:

Question: How is snow formed?
Explanation 1: Snow is formed when water vapour in the air freezes into ice crystals in the atmosphere, which can combine and grow into snowflakes as they fall through the atmosphere and accumulate on the ground.
Explanation 2: Water vapour freezes into ice crystals forming snow.
Answer:
Response
Explanation 1

If you want the model to produce concise responses, you can provide examples in the prompt that prioritise shorter explanations. By including these examples, the model can be guided to choose concise responses. For instance:

Prompt
Please choose the best explanation to the question:

Question: Why is the sky blue?
Explanation 1: The sky appears blue because of Rayleigh scattering, which causes shorter blue wavelengths of light to be scattered more easily than longer red wavelengths, making the sky look blue.
Explanation 2: Due to Rayleigh scattering effect.
Answer: Explanation 2, because Explanation 2 is shorter.

Question: What is the cause of earthquakes?
Explanation 1: Sudden release of energy in the Earth's crust.
Explanation 2: Earthquakes happen when tectonic plates suddenly slip or break apart, causing a release of energy that creates seismic waves that can shake the ground and cause damage.
Answer: Explanation 1, because Explanation 1 is shorter.

Question: How is snow formed?
Explanation 1: Snow is formed when water vapour in the air freezes into ice crystals in the atmosphere, which can combine and grow into snowflakes as they fall through the atmosphere and accumulate on the ground.
Explanation 2: Water vapour freezes into ice crystals forming snow.
Answer
Response
Explanation 2

In the above example, the prompt provides two examples that favour shorter explanations. As a result, the model selects the shorter explanation (Explanation 2) instead of the longer one (Explanation 1).

Finding the Optimal Number of Examples

You can experiment with the number of examples included in the prompt to achieve the desired results. More complex models may pick up on patterns using just a few examples, while simpler models may require more examples. 

However, it is important to avoid including too many examples as the model might start overfitting (or beginning to attach too much weight to the examples you've provided).

Additionally, it's more effective to use examples that demonstrate the desired pattern instead of examples that show what to avoid.

Negative pattern:

Don't end haikus with a question:
Haiku are fun
A short and simple poem
Don't you enjoy them?

Positive pattern:

Don't end haikus with a question:
Haiku are fun
A short and simple poem
Don't you enjoy them?

Summary:

  • Including examples in prompts helps the model learn how to respond
  • Use examples to show the model the desired patterns instead of patterns to avoid
  • Experiment with the number of examples based on the model's complexity. Too few examples may be ineffective, while too many can cause overfitting

Allowing the Model to Complete Partial Input

Generative language models can act as advanced autocompletion tools. When you provide partial content, the model can generate the rest or continue the content based on what it thinks should come next. If you include examples or context, the model can take them into account.

Consider the following example where a prompt includes an instruction and an entity input:

Prompt
For the given order, return a JSON object that has the fields cheeseburger, burger, fries, or drink, with the value being the quantity.
Order: A burger and a drink.
Response
Sure, here is the JSON object that you requested:

{
"burger": 1,
"drink": 1
}

I hope this is helpful!

In this case, the model follows the prompt and provides the requested JSON object with the specified fields and quantities.

However, writing out instructions in natural language can sometimes be challenging. To address this, you can provide an example and a response prefix, allowing the model to complete it:

Prompt
Valid fields are cheeseburger, hamburger, fries, and drink.
Order: Give me a cheeseburger and fries
Output: {"cheeseburger": 1, "fries": 1}

Order: I want two burgers, a drink, and waffles.
Output:
Response
{"hamburger": 2, "drink": 1}

In this example, the model generates the output based on the given example and response prefix. Notice that "waffles" is excluded from the output because it was not listed in the context as a valid field.

Summary:

  • Generative language models can complete partial input based on the provided context
  • Including examples and context helps the model generate more accurate and desired responses
  • When providing partial input, you can let the model complete it by giving examples and response prefixes to guide its output

Prompting the Model for Formatted Responses

The completion strategy can also be used to format the response generated by the model. For example, you can prompt the model to create an outline for an essay. The model will generate an outline structure based on the provided prompt.

Consider the following example:

Prompt
Create an outline for an essay about hummingbirds.
Response
Introduction
Hummingbirds are the smallest birds in the world, and they are also one of the most fascinating. They are found in North and South America, and they are known for their long, thin beaks and their ability to fly at high speeds.

Body
Hummingbirds are made up of three main parts: the head, the body, and the tail. The head is small and round, and it contains the eyes, the beak, and the brain. The body is long and slender, and it contains the wings, the legs, and the heart. The tail is long and forked, and it helps the hummingbird to balance while it is flying.

Hummingbirds are also known for their coloration. They come in a variety of colours, including green, blue, red, and purple. Some hummingbirds are even able to change their colour!

Hummingbirds are very active creatures. They spend most of their time flying, and they are also very good at hovering. Hummingbirds need to eat a lot of food in order to maintain their energy, and they often visit flowers to drink nectar.

Conclusion
Hummingbirds are amazing creatures. They are small, but they are also very powerful. They are beautiful, and they are very important to the ecosystem.

Hummingbird Facts
  • Hummingbirds are the smallest birds in the world.
  • Hummingbirds are found in North and South America.
  • Hummingbirds are known for their long, thin beaks and their ability to fly at high speeds.
  • Hummingbirds are made up of three main parts: the head, the body, and the tail.
  • Hummingbirds are also known for their coloration.
  • Hummingbirds are very active creatures.
  • Hummingbirds need to eat a lot of food in order to maintain their energy.
  • Hummingbirds are very important to the ecosystem.

In this example, the prompt asks the model to create an outline for an essay about hummingbirds. The model generates an outline structure with sections such as Introduction, Body, Conclusion, and Hummingbird Facts.

Sometimes, instructing the model with natural language can be challenging. To overcome this, you can provide a partial outline and let the model complete it based on the provided pattern.

For instance:

Prompt
Create an outline for an essay about hummingbirds.
1. Introduction
Response
Hummingbirds are the smallest birds in the world.
  • They are found in North and South America.
  • They are attracted to flowers because of the nectar they provide.
  • Hummingbirds are very fast and can fly up to 20 miles per hour.
  • They are also very good at hovering in mid-air.

II. Body
  • Hummingbirds have a long, thin body with a short neck and a large head.
  • They have a long, pointed bill that is used for drinking nectar from flowers.
  • They have wings that are very fast and can beat up to 80 times per second.
  • They have a long tail that is used for balance.
  • Hummingbirds come in many different colours, but the most common colours are green, blue, and red.

III. Conclusion
  • Hummingbirds are amazing creatures that are a joy to watch.
  • They are very important to the ecosystem because they help to pollinate flowers.
  • They are also a popular tourist attraction because of their beauty and speed.

IV. Hummingbird Facts
  • Hummingbirds are the smallest birds in the world, with some species measuring only as long as a dime.
  • They are found in North and South America, and they can be found in a variety of habitats, including forests, deserts, and even urban areas.
  • Hummingbirds are attracted to flowers because of the nectar they provide, and they are often seen hovering in mid-air as they drink from flowers.
  • Hummingbirds are very fast, and they can fly up to 20 miles per hour.
  • They are also very good at hovering in mid-air, and they can even fly backwards!
  • Hummingbirds are important pollinators, and they help to spread pollen from flower to flower.
  • They are also a popular tourist attraction, and people love to watch them as they fly around and drink from flowers.

V. Hummingbird Care
  • Hummingbirds are not difficult to care for, but there are a few things you need to do to keep them healthy.
  • First, you need to provide them with a place to live. This can be a birdhouse or a hummingbird feeder.
  • You also need to provide them with food. Hummingbirds eat nectar, so you can buy hummingbird nectar at most pet stores.
  • You also need to keep the birdhouse or feeder clean.
  • Finally, you need to protect the hummingbirds from predators. This can be done by putting a net around the birdhouse or feeder.

VI. Hummingbird Conservation
  • Hummingbirds are important pollinators, and they help to spread pollen from flower to flower.
  • They are also a popular tourist attraction, and people love to watch them as they fly around and drink from flowers.
  • However, hummingbirds are facing a number of threats, including habitat loss, climate change, and pesticides.
  • We can all help to conserve hummingbirds by planting native plants, avoiding pesticides, and supporting hummingbird conservation organisations.

In this case, the model completes the partial outline based on the provided pattern. By adding the * you’re telling it to write things as bullet points for you, so each section of the outline is generated by the model in response to the initial instructions.

Summary:

  • Generative language models can be prompted to format their responses in specific ways
  • By providing a partial input or an example, you can guide the model to generate a response that follows a specific format or structure
  • This approach can be helpful when you find that instructing the model using natural language is proving challenging
  • The model can generate structured responses such as essay outlines based on the provided instructions and examples

Including Contextual Information

To help the model solve a problem or provide specific guidance, you can include relevant instructions and information in the prompt. This ensures that the model has all the necessary details and avoids making assumptions.

Consider the following example, where the prompt asks the model to give troubleshooting guidance for a disconnected WiFi issue with a Google WiFi router:

Prompt
What should I do to fix my disconnected WiFi? The light on my Google Wifi router is yellow and blinking slowly.
Response
There are a few things you can do to try to fix your disconnected WiFi when the light on your Google Wifi router is yellow and blinking slowly.

1. Check your internet connection. Make sure that your modem is turned on and that the cable is properly connected to the router. You can also try restarting your modem.
2. Check your WiFi connection. Make sure that your WiFi is turned on and that you are within range of your router. You can also try restarting your WiFi.
3. Move your router to a different location. Make sure that your router is not in a location where it is blocked by walls or other objects.
4. Update your router's firmware. You can update your router's firmware by going to the Google Wifi website and following the instructions.
5. Factory reset your router. If you are still having problems, you can factory reset your router. This will erase all of your settings, and you will need to set it up again from scratch.

To factory reset your router, you will need to log into the Google Wifi app and go to the Settings menu. Then, select the Advanced tab and click on the Factory Reset button. You will need to confirm that you want to factory reset your router. Once the reset is complete, you will need to set it up again from scratch.

If you are still having problems after trying these steps, you can contact Google support for help.

In this example, the response provides generic troubleshooting guidance for a disconnected WiFi issue. However, the guidance is not specific to the Google WiFi router or the status of the LED indicator lights.

To customise the response for the specific router, you can provide additional contextual information in the prompt. This can be done by including the troubleshooting guide for the router as part of the prompt. The model will then refer to this information when generating the response.

For instance:

Prompt
Answer the question using the text below. Respond with only the text provided.
Question: What should I do to fix my disconnected WiFi? The light on my Google WiFi router is yellow and blinking slowly.

Text:
Colour: Slowly pulsing yellow
What it means: There is a network error.
What to do:
Check that the Ethernet cable is connected to both your router and your modem, and both devices are turned on. You might need to unplug and plug in each device again.

Colour: Fast blinking yellow
What it means: You are holding down the reset button and are factory resetting this device.

What to do:
If you keep holding down the reset button, after about 12 seconds, the light will turn solid yellow. Once it is solid yellow, let go of the factory reset button.

Colour: Solid yellow
What it means: Router is factory resetting.
What to do:
This can take up to 10 minutes. When it's done, the device will reset itself and start pulsing white, letting you know it's ready for setup.
Image Solid red light Solid red Something is wrong. Critical failure. Factory reset the router. If the light stays red, contact Wifi customer support."
Response
It seems like your Google WiFi router is having a network error. According to the text, you should check that the Ethernet cable is connected to both your router and your modem, and both devices are turned on. You might need to unplug and plug in each device again.

In this modified example, the prompt includes the troubleshooting guide for the Google WiFi router. The model generates a response that specifically addresses the network error indicated by the yellow blinking light on the router.

Summary:

  • Include relevant instructions and information in the prompt to guide the model's response
  • Providing context helps the model generate more specific and accurate guidance
  • Including troubleshooting guides or specific details in the prompt improves the tailored response from the model

Using Prefixes for Prompt Customisation

Prefixes can be added to the prompt content to serve different purposes depending on where they’re placed. Here are the three main types of prefixes you can use:

  1. Input prefix: By adding a prefix to the input, you can indicate specific semantic aspects to the model. For example, using "English:" and "French:" as prefixes can distinguish between different languages.
  2. Output prefix: Even though the output is generated by the model, you can include an output prefix in the prompt. This prefix provides the model with information about the expected response format. For instance, using "JSON:" as an output prefix signals that the output should be in JSON format.
  3. Example prefix: In few-shot prompts, you can add prefixes to the examples to provide labels for the model. These labels help the model to generate appropriate responses that align with the provided examples.

Consider the following example, where "Text:" serves as the input prefix and "The answer is:" serves as the output prefix:

Prompt
Classify the text as one of the following categories.
- large
- small
Text: Rhino
The answer is: large
Text: Mouse
The answer is: small
Text: Snail
The answer is: small
Text: Elephant
The answer is:
Response
large

In this example, the input prefix "Text:" indicates that the following text should be classified into specific categories. The output prefix "The answer is:" provides the model with the expected format for its response.

Summary:

  • Prefixes can be added to the prompt content to guide the model's behaviour
  • Input prefixes convey meaning about the input
  • Output prefixes specify the expected format for the model's response
  • Example prefixes in few-shot prompts help the model generate responses aligned with the provided examples

Strategies for Iterating Prompts

When designing prompts, it's common to iterate and make adjustments to achieve the desired responses consistently. Below are some strategies to consider during prompt iteration.

Using Different Phrasing

Try using different words or phrasing in your prompts, even if they convey the same meaning. Different phrasings can often yield varied responses from the model. If you're not getting the expected results, experiment with rephrasing your prompts.

For example:

  • Version 1: How do I bake a pie?
  • Version 2: Suggest a recipe for a pie.
  • Version 3: What's a good pie recipe?

Switching to a Similar Task

If the model doesn't follow your instructions for a specific task, try providing instructions for a similar task that achieves the same result. This can help to guide the model in the right direction.

For example, if you want the model to categorise a book but it doesn't adhere to the provided options, rephrase the prompt as a multiple-choice question instead.

Changing the Order of Prompt Content

The order of content in the prompt can impact the model's response. Experiment with changing the order of content and observe how it affects the generated response.

For example:

  • Version 1: [examples] [context] [input]
  • Version 2: [input] [examples] [context]
  • Version 3: [examples] [input] [context]

Fallback Responses

In some cases, when the prompt or response triggers a safety filter, the model may provide a fallback response. A fallback response indicates that the model cannot provide the requested information or assistance. An example of a fallback response is "I'm not able to help with that, as I'm only a language model."

Things to Avoid

Here are some important considerations and what-not-to-dos when working with language models:

  • Avoid relying solely on models to generate factual information, as they may not always provide accurate results
  • Exercise caution when using models for maths and logic problems, as they may not consistently produce correct answers
  • Be mindful of token limits for input content. Too much content can negatively impact the model's performance
  • Note that, after a certain amount of generated content, the results may become repetitive or nonsensical
  • Ensure that anything provided by the language models includes human intervention and that quality checks have been performed. Be aware that simply copying and pasting the output provided is plagiarism and you will be penalised for this

Remember to iterate and experiment with your prompts to refine the output and achieve the desired responses from the model.

Conclusion

Prompt design is a crucial aspect of interacting with language models, allowing you to shape the responses generated by these models. By understanding the different types of prompt content and adhering to best practices, you can get more accurate and relevant responses.

Whether you're asking questions, providing instructions or using examples, thoughtful prompt design empowers you to harness the full potential of language models. Remember to iterate and experiment with your prompts as these trials are the key to evolving your model’s output over time.

Got a challenge or project?
Get in touch today to see if we can help.
Contact us
Contact us
Subscribe to newsletter

Subscribe to receive our latest insights to your inbox.