Developing and using prompt templates with ChatGPT

The information and exercises here draw on material developed for Module 3 of Arizona State University’s online undergraduate course on prompt engineering using ChatGPT. The module focuses on developing reusable prompt templates, an essential component of prompt engineering. It will equip you with the knowledge and skills necessary to create versatile and adaptable prompts that perform well across a variety of tasks and domains.

The exercises here work best if using the paid ChatGPT Plus service from Open AI and GPT-4.

Introduction

This is the introduction to module 3 in ASU’s introduction to prompt engineering using ChatGPT — even outside that context though, it’s a useful introduction to prompt templates.

 

Overview

Prompt templates are pre-defined structures or formats that can be filled with specific content, allowing for efficient generation of new prompts. By developing reusable templates, you can quickly create a large number of related prompts with minimal effort. This is particularly useful when addressing a family of related tasks.

To create effective prompt templates, you will need to:

1. Analyze the task: Understand the core requirements of the task and identify the key components that need to be addressed in the prompt.

2. Design the structure: Develop a general structure for the prompt that can accommodate different inputs or situations. This may include creating placeholders for specific information or using conditional statements to adjust the prompt based on the context.

3. Test and refine: Continuously test the prompt template with various inputs and scenarios to ensure that it remains effective across a wide range of use cases. Make necessary adjustments and refinements based on the observed performance.

By mastering prompt templates, you will be able to create versatile and efficient prompts that can be adapted to a wide range of tasks and applications.

The exercises in this model assue you have access to ChatGPT Plus from Open AI. However, they are adaptable to other AI chatbot platforms.

Exercise: Prompt template exploration

This exercise is designed to allow you to explore the concept of prompt templates by playing and experimenting with ChatGPT.

1. Open a chat session with ChatGPT, making sure that you are in GPT-4 mode.

2. Have a conversation with ChatGPT about prompt templates. You may want to ask what they are, how they can be used, and good examples of their use. You may even want to work with ChatGPT on developing and testing your own skills here.

3. Be creative in the conversation you have.

At the end of this exercise you should have a clearer understanding of the usefulness and nature of prompt templates.

Exercise: Exploring an example prompt template

This exercise uses a simple yet powerful example of a reusable prompt template to help you understand the structure and format of a successful template.

The template you will use was suggested by Siqi Chen (@blader on Twitter):

“Teach me how [anything] works by asking questions about my level of understanding of necessary concepts. With each response, fill in gaps in my understanding, then recursively ask me more questions to check my understanding.”

The prompt template consists of:

A domain: This is the area that the template is designed to address. In this case the domain is things the user wants to learn about

A task: This is the think that the prompt template is designed to do. In this case it is getting ChatGPT to help the user to learn more about a specific topic

A process: This is how the template determines that ChatGPT will complete the task. A process that ChatGPT will use to execute the prompt.

An input: A new piece of information that is provided by the user each time the template is used. In this case it is the thing the user wants to learn about. A prompt template may have more than one inputs.

This isn’t the only prompt template structure, but it is a useful one.

Exercise:

1. Open a new session of ChatGPT using GPT-4

2. Type in the prompt above with [anything] replaced by “prompt templates in ChatGPT” (you may want to also change the following “works” to “work”.

3. Have a conversation with ChatGPT over 3 – 4 responses, and think about what you can learn about the original prompt from this.

4. Experiment with the same prompt template using another domain. How effective is this prompt at opening up the power of ChatGPT?

At the end of this exercise you should have a clearer understanding of the how prompt templates can be useful.

Exercise: Developing your own prompt template

In this exercise you will create a reusable prompt template. This will be designed for use within a specific domain.

You can be creative here. For instance, science, history and literature are all great domains, but so are food, animals, climate change, AI, hobbies, and even Pokémon! You will test the template with ChatGPT and analyze the results, making any necessary adjustments to improve its effectiveness.

While following the exercise you should be aware that there are different types of questions that you can ask ChatGPT to respond to in a prompt template. These include factual questions, comparative questions, and hypothetical questions, although there are others.

For instance, you might select the domain of science fiction, and chose the question types of “factual” (e.g. what was x’s first book?), comparative (e.g. how does x compare to y?) and hypothetical (e.g. if the characters in x knew of y how would this affect the plot?).

You are free to use one of these, or develop your own unique type of question.

IMPORTANT: Remember that a template is something that can be used repeatedly by inserting different key pieces of information to get different responses. This means that there must be some component of the template that can be replaced with different information every time it’s run. For example, “How do I make a cherry cake” is not a prompt template. However, “How do I make a [type of fruit] cake” is.

Tip: You can use delimiters and placeholders in your prompt template. For instance, using the example from the previous exercise:

Teach me how [anything] works by asking questions about my level of understanding of necessary concepts. With each response, fill in gaps in my understanding, then recursively ask me more questions to check my understanding.

[anything]: (this is where you put what you want to learn about)

In this example you don’t have to substitute placeholder text in the prompt – you simply add the variable text after the “[anything]:” placeholder.

EXERCISE

1. Domain selection and exploration

1.1 Choose a domain that interests you. Be creative!

1.2 Think about and identify key topics, concepts, and types of questions that are commonly asked within this domain, or that you would like to ask.

1.3 Think about specific challenges that might occur when asking ChatGPT questions about this domain, such as ambiguity and context-dependency.

1.4 Make a note of your domain, the key topics, and any challenges you have identified, in question 1 below.

2. Designing a simple template

2.1 Design a simple template for the domain and topics you identified in the previous step. Make sure that the prompt is sufficiently general that it gives different and useful responses when supplied with different inputs. each question type, including placeholders for context and specific details. For example, if your domain is science fiction, a template may look like “If the characters in [book or movie] knew about [science or technology breakthrough] how would the story be different?”

2.2 Test your template with ChatGPT (with GPT-4) using specific examples, and tweak the template so that the results are as useful as possible when using different inputs.

3. Using your template

3.1 When you are happy with the results of your template, experiment with a range of inputs to see how effective it is.

On completing this exercise you should have a deeper uderstanding of how to develop and use prompt templates.

Exercise: Training ChatGPT to use your template

One of the more powerful features of ChatGPT is that it can infer how to respond to questions from the information you provide it. This is called “systematic generalization” when developing LLMs and chatbots like ChatGPT. 

In this exercise you will first train ChatGPT to respond using a prompt template so that you don’t need to type in the whole template each time. An example of this is:

User: How do I make a [key ingredient] cake? [key ingredient] = cherry
ChatGPT: (Instructions on how to make cherry cake)
User: Apple
ChatGPT: (Instructions on how to make apple cake)
User: Date and walnut
ChatGPT: (Instructions on how to make date and walnut cake)

Once ChatGPT knows what you are looking for, it infers how to interpret subsequent prompts.

Next, you’ll train ChatGPT how you specifically want it to respond. An example of this is:

User: Q: How do I make a [key ingredient] cake? A: This is how Mary berry would do it …   [key ingredient] = cherry
ChatGPT: (Instructions on how to make a Mary Berry inspired cherry cake)
User: Apple
ChatGPT: (Instructions on how to make a Mary Berry-inspired apple cake)

Note that you will find that if you continue a conversation like this over several prompts, you may need to remind ChatGPT what the original template was.

EXERCISE:

1. Open a new session with ChatGPT using GPT-4

2. Either use the prompt template from the previous exercise or create a new one. Following the example above, provide ChatGPT with different variables for the prompt template, without typing in the whole template each time.

3. Next, in the same ChatGPT session, type in the original prompt template, but also provide guidance on what the answer should look like. This can be similar to the example above, or you get creative. 

4. As above, provide ChatGPT with different variables for the template, without typing in the whole template each time.

By the end of this exercise you should be able to train a ChatGPT session with a template and then use it multiple times without typing the template out each time.

Exercise: Multi-step task template

One useful extension of the prompt template is the mult-step prompt template. This is a template that consists of multiple steps, where only the first step includes a template variable.

For example:

User: I would like to visit [destination] for a vacation. I’m traveling from [starting point]. What time of year should I go? [destination] = London; [starting point] = New York
ChatGPT: (response)
User: What’s the best way to travel between my starting point and the destination?
ChatGPT: (response)
User: How long should I stay to have the best experience?
ChatGPT: (response)
User: What are three things I must do while there?
ChatGPT: (response)
User: Please develop a detailed itinerary for me

The user responses form a multi-step template that can be used for different destinations and starting points in this case, with only the first prompt requiring new information each time.

The benefits of such a multi-step prompt template is that the depth, utility and quality of the information returned can be far more useful than that from a single step prompt template.

In this exercise you will develop a template for a task that consist of multiple steps.

EXERCISE:

1. Select a task that can be broken into multiple steps. This may be something like developing a meal plan or a recipe (like the example above), or developing a travel itinerary, or outlining an essay, or developing a health or fitness regime, or even setting up a business.

2. Develop a series of between 4 – 8 sequential prompts for this task. Remember to think about a sequence that can usefully be used multiple times, rather than just once. 

IMPORTANT: Only your first prompt should contain variables. Each time you run the multi-step template, every subsequent prompt should remain the same.

3. Open a new session with ChatGPT using GPT-4

4. Iteratively work with ChatGPT to test and refine your prompt sequence.

5. Once you are happy with your multi-step task template, start a new ChatGPT session and run it.

By the end of this exercise you should have a better understanding of how to develop and use multi-step prompt templates for ChatGPT.

 

Exercise: Chain of Thought template

This is a clever trick that you can use with ChatGPT to not only create general prompts, but to also tap into an intriguing property of ChatGPT called “chain of thought” reasoning.

Chain of thought prompts enable ChatGPT (and other AI Chatbots) to break down complex tasks into smaller steps based on logical reasoning. The most common way to achieve this is to end a prompt with the phrase “Let’s think step by step”

This can be combined with a simple template to provide a powerful ChatGPT prompt template for problem solving

For instance:

How would I [task]
[task] = balance a jug of water, an orange, and an egg on top of each other
Let’s think step by step.

In the example above, you can replace “task” with almost anything.

In this exercise, you have a choice of either exploring the prompt above, or creating your own chain of thought prompt template.

Note: The example above is called a “zero shot Chain of Thought” prompt, or zero shot CoT prompt, because yo are asking ChatGPT to logically think through a problem without providing any additional context or examples for how it should proceed.

EXERCISE

1. Open a new ChatGPT session, making sure you are in GPT-4 mode

2. Experiment with the prompt above, trying out a number of different tasks

3. Create your own zero shot CoT prompt

At the end of this exercise you should have a better understanding of how to craft and use a Chain of Thought prompt template.

Exercise: Testing your understanding of prompt templates

1. Open a new session with ChatGPT using GPT-4

2. Enter the following prompt:

“Hi ChatGPT. My name is [enter full name] and I am completing a course assignment on prompt templates using ChatGPT. This is for a basic introduction to using ChatGPT as part of an undergraduate course. The assignment has the following learning objectives: ‘At the end of this module you will be able to: Explain the usefulness of prompt templates when using ChatGPT; Develop simple prompt templates that you can use across different situations and domains; Develop multi-step prompt templates’ Please ask me five simple questions on prompt templates with ChatGPT based on these objectives. After each question, please wait until I have answered before asking the next one. When I have answered all five questions, provide me with an assessment of my answers and a grade from A to C. In your assessment, consider the length and detail I provide in my answers.”

3. Complete the quiz. You can repeat this as many times as you like, but do start each version of the quiz in a new ChatGPT session.

 

 

Subscribe to Andrew on Substack for the latest thinking on technology, society, the future, and more …