Constraint based prompting

The information and exercises here draw on material developed for Module 2 of Arizona State University’s online undergraduate course on prompt engineering using ChatGPT.

Constraint based prompting involves adding constraints or conditions to your prompts, helping the language model focus on specific aspects or requirements when generating a response. You will explore various types of constraints, such as limiting response length, specifying response structure, or providing explicit instructions. By understanding how to incorporate constraints effectively, you can create prompts that generate more focused and tailored outputs.

The exercises below are designed to help develop your constraint based prompting skills. They work best if using the paid ChatGPT Plus service from Open AI and GPT-4.

 

Overview

Ambiguity reduction, constraint-based prompting, and comparative prompt engineering, are all methods that can help improve the effectiveness of prompts, leading to more accurate, relevant, and useful responses from language models like ChatGPT.

By learning about ambiguity reduction, constraint-based prompting, and comparative prompt engineering, you will gain valuable insights into the art of prompt engineering. These techniques will empower you to create more effective prompts that elicit accurate, relevant, and useful responses from language models across various tasks and domains.

The exercises below specifically focus on constraint based prompting.

Constraint based prompting involves adding constraints or conditions to your prompts, helping the language model focus on specific aspects or requirements when generating a response. You will explore various types of constraints, such as limiting response length, specifying response structure, or providing explicit instructions. By understanding how to incorporate constraints effectively, you can create prompts that generate more focused and tailored outputs.

They are split into three parts: First you will explore the nature and purpose of constraint based prompting with ChatGPT. Next you will carry out an exercise called “Creative Expansion and Reduction” that helps you develop your constraint-based prompting skills. And thirdly you will develop your own example of a constrained prompt based on the previous exercises.

Exercise: Exploring Constraint Based Prompting

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

2. Explain to ChatGPT that you are in a course on prompt engineering and that you are studying constraint-based prompting using ChatGPT. Have a conversation with ChatGPT about what constraint-based prompting is and explore examples of constraint-based prompts.

3. Use this session to learn as much as possible about constraint-based prompting. Remember, ChatGPT is not always reliable, so think about how you will evaluate the responses you get to ensure that they are reasonable.

At the end of this exercise you should have a clearer sense of what constraint based prompting is and how to use it.

Exercise: Creative expansion and reduction

This is an exercise in developing and expanding your understanding of constraint-based prompting. It was developed by ChatGPT!

1. Open a ChatGPT session. Make sure you are in GPT-4 mode.

2. Select a source text: Choose a passage from a favorite book, article, or any other written work. This will be the base text for the exercise. Keep this to less than 300 – 500 words.

3. Apply the first constraint – Summary: Ask ChatGPT to generate a summary of the selected text. You should craft a prompt that guides the AI model to provide a concise summary of the source text. Consider using a word limit.

4. Apply the second constraint – Expansion: Next, you should ask ChatGPT to generate an expanded version of the source text by crafting a prompt that encourages ChatGPT to provide additional details, context, or explanations. You may consider also using a word limit here. Pay attention to how closely ChatGPT sticks to the constraints.

5. Apply the third constraint – Change of perspective: In this step, you will ask ChatGPT rewrite the source text from a different perspective. They should create a prompt that guides ChatGPT to rewrite the text from a first-person, second-person, or third-person point of view, depending on the original perspective.

6. Apply the fourth constraint – Genre or voice transformation: You should now craft a prompt that guides ChatGPT to transform the source text into a different genre (such as sci-fi, fantasy, or mystery) or voice (such as a historic or fictional character). This will help you understand how constraints can be used to generate diverse outputs.

At the end of this exercise you should have a clearer understanding of how adding constraints to prompts help guide the output from ChatGPT in useful ways.

Exercise: Constraint-based prompt formulation

This exercise builds on the previous two to furthere explore constraint based prompting

1. Open a ChatGPT session. Make sure you are in GPT-4 mode.

2. Demonstrate your understanding of constraint-based prompt formulation by crafting a prompt that demonstrates the effective use of constraints in determining the output. Be creative in your use of constraints.

At the end of this exercise you should be comfortable in improving your prompts by adding constraints to them.

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