The Simple Guide to Prompt Engineering with ChatGPT

Guide to Prompt Engineering with ChatGPT

Prompt engineering is the practice of carefully crafting the prompts you send to AI systems like ChatGPT to get better, more accurate responses. As ChatGPT and similar models grow increasingly popular, being able to prompt them effectively unlocks their full potential. In this comprehensive guide, we’ll explore the ins and outs of prompt engineering so you can level up your AI assistant skills.

What is Prompt Engineering and Why is it Important?

Prompt engineering is all about guiding your AI assistant by providing the proper context, instructions and examples in your prompts. ChatGPT doesn’t inherently understand our intent – it tries to infer it from the wording of the prompt. By engineering better prompts, we can shape ChatGPT’s responses to be more precisely what we want.

The goal of prompt engineering is to activate the relevant knowledge and background information ChatGPT needs to tackle our specific request. Rather than treating it as a black-box, prompt engineering techniques let us peek under the hood and influence how the model arrives at its responses.

With the right prompts, we can unlock ChatGPT’s capabilities for a wide range of professional and creative use cases. The techniques we’ll cover in this guide will help you get significantly better results from any AI assistant.

Custom Instructions: Teaching ChatGPT Guidelines

One of the first things to keep in mind when crafting prompts is that ChatGPT doesn’t have any innate knowledge – it only knows what’s in its training data. That means we need to provide it with clear guidelines and rules tailored to our specific needs.

You can set custom instructions by formatting them as follows:

  • Please respond in a [tone/style] format
  • Do not include any [content types] in your response
  • Focus your response on providing [specific information]
  • Aim your response at a [type of audience]

The key is being explicit with the type of output you want to receive. Without custom guidelines, ChatGPT will make assumptions that may not fit what you’re looking for. Defining those rules up front consistently produces better results.

The Core Elements of an Effective Prompt

While custom instructions set the foundation, there are several other elements that contribute to prompt engineering excellence:

Conversational Tone: Write prompts conversationally, as you would speak them out loud. Avoid robotic or overly formal language.

Clear Instructions: Be as specific as possible when explaining the task or request. Break down complex goals into step-by-step instructions.

Providing Context: Give any background information needed to prime ChatGPT for the topic and tone.

Formatting: Use bullets, headings, and numbering to separate instructions from examples and context.

Conciseness: Get straight to the point— shorter prompts tend to work better than long blocks of text.

It’s a Chat – Use It!

One big advantage ChatGPT has over other AI systems is that it’s designed specifically for conversation. Take advantage of its chat abilities to guide responses:

  • Ask clarifying questions when a response is unclear.
  • Get explanations of thought processes to understand its reasoning.
  • Ask for definitions of unclear terms.
  • Politely correct inaccurate responses and re-prompt to get it back on track.
  • Maintain a friendly, patient tone even when responses are off-base.
  • Check in periodically with summarizations to ensure it stays focused.
  • Treat it like collaborating with a human partner, not a search engine. The more of a conversational “groove” you get into with ChatGPT, the better it will perform.

Which Context Should You Provide?

Selectively providing context is key—we want to activate the relevant knowledge ChatGPT needs without overwhelming it with unnecessary information. The right context depends on your specific prompt goals, but some options include:

  • Background info on key people, places, events related to the prompt
  • Definitions or examples of domain-specific terminology
  • High-level summary of the circumstances around the request
  • Fictional scenarios for worldbuilding or character development prompts
  • Links to source material for prompts requiring specific knowledge

When possible, opt for providing summarized context rather than asking ChatGPT to research context itself—this gives you greater control over which background info is included.

Time to Practice – Example Prompt Engineering Tasks

Let’s apply some of these concepts with a few practice prompt engineering tasks:

Task 1: Ask ChatGPT to explain the key events of the French Revolution in a simple, conversational tone aimed at high school world history students.

Task 2: Prompt ChatGPT to generate a 300 word blog post about current AI ethics issues, written from the perspective of a technology policy expert.

Task 3: Have ChatGPT outline a daily study plan for passing an upcoming algebra exam, including 4 hours of total study time split between 3 study sessions.

These tasks require combining several prompting techniques, including tone of voice, perspective framing, output length and more. Give it your best shot!

Time to Practice – Sample Solutions

Here are some examples of effective prompts for those practice tasks:

Task 1 sample solution:

  • I want you to explain the key events of the French Revolution to high school students in a simple, conversational tone. Use basic vocabulary so they would understand and break down complex topics clearly. Please focus on covering the storming of the Bastille, reign of terror, execution of Louis XVI and rise of Napoleon Bonaparte.

Task 2 sample solution:

  • Please write a 300 word blog post about current ethical issues regarding artificial intelligence, written from the perspective of a technology policy expert. Adopt an authoritative yet accessible tone, citing examples like algorithmic bias and facial recognition systems. Focus on providing balanced policy recommendations that protect public interest while enabling innovation.

Task 3 sample solution:

  • I have an algebra exam coming up that I need to prepare for over the next 3 days. Please outline a specific daily 4 hour study plan split between 3 sessions that optimizes my understanding of the material. Focus the first session on reviewing core concepts and formulas. Use the second session for practicing example problems. Devote the third session to taking practice test questions and assessing areas of weakness. Please provide a high level schedule with specific tasks for each 1-2 hour block in each study session.

These examples demonstrate applying instructions, perspective framing, conversational tone and formatting techniques to prompt engineering.

Zero-Shot, One-Shot and Few-Shot Prompting

Additional prompt engineering tactics include zero-shot, one-shot and few-shot prompting:

Zero-Shot: No example output is provided. Relies solely on instructions.

One-Shot: Provide one example to guide the desired response format.

Few-Shot: Give 2-5 examples to establish a clear pattern to follow.

Few-shot prompting is powerful when you have clear examples to prime the response. One-shot can also be effective by demonstrating the expected format. Zero-shot depends entirely on the quality of the instructions.

Using Output Templates

For certain use cases like content writing, you can include an output template in your prompt to define the exact structure you want:

  • Start with an introduction paragraph of 2-3 sentences summarizing the topic.
  • Follow with a 3-5 paragraph body providing key details and analysis.
  • End with a 1 paragraph conclusion summarizing the main points.

Templates work well for material like blog posts, reports, cover letters, and more where defined formats are expected.

Providing Cues and Hints

You can guide ChatGPT by strategically including keywords and phrases related to the information you want:

Prompt about nutrition: “Please explain the benefits of antioxidants, including specific examples like polyphenols, carotenoids, and vitamin C.”

The cues help activate relevant knowledge models. This works for any domain where providing keywords will help steer the response.

Separating Instructions from Content

Clearly delineate instructions and context from any examples by formatting them in separate sections:

  • Instructions
  • Context
  • Examples

This prevents ChatGPT from getting mixed signals by interweaving directives with unrelated content. Keep each section concise and formatted for easy reading.

Ask-Before-Answer Prompting

For sensitive topics, use an ask-before-answer approach:

Advanced Prompt Engineering Techniques

Let’s look at some more advanced tactics for extremely effective prompt engineering.

Ask-Before-Answer Prompting

When dealing with potentially controversial subject matter, use an ask-before-answer technique:

First ask ChatGPT to summarize its understanding of the issue and how it would approach it. Then affirm or correct the summary and re-prompt it to respond within those defined parameters.

This allows us to course-correct any problematic assumptions before receiving the full response.

Perspective Prompting

We can frame prompts from different perspectives to shape the response:

  • Answer from the perspective of an expert scientist
  • Respond as if you are a professor lecturing students
  • Provide historical context analyzing the issue through the lens of the 1960s

Perspective framing is excellent for getting domain-specific information or a certain narrative tone.

Contextual Prompting

When generating creative writing, establish the context up front:

  • You are an explorer in the year 1850 writing in your journal after discovering a rare artifact. Describe the artifact and your thoughts about it. Use vivid sensory details and wonder about its mysterious origins.

This primes ChatGPT to engage the appropriate knowledge and style.

Emotional Prompting

For emotional expressiveness, directly prompt the desired emotion:

  • Respond with a tone of enthusiasm and excitement as if explaining something you’re passionate about.
  • Answer sincerely and empathetically, as you would to comfort a close friend.

Emotional prompting elicits affect and personality we want for social interaction and creative writing.

Time to Practice – More Prompt Engineering Examples

Let’s apply advanced prompting techniques with a few more practice tasks:

Task 1: Have ChatGPT outline the plot of a spy thriller movie from the perspective of the story’s protagonist.

Task 2: Prompt it to explain general relativity in an easy-to-understand way, as if to a curious 12-year old.

Task 3: Ask ChatGPT to write a thoughtful message of encouragement to a high school student struggling with anxiety.

Give these a try on your own before checking the sample solutions!

Time to Practice – Sample Advanced Prompting Solutions

Here are some possible solutions for those advanced prompt engineering practice tasks:

Task 1 sample solution:

  • I am a spy protagonist in an action thriller movie. Outline the plot of the movie from my perspective, describing key events like getting betrayed by someone I trust, uncovering a sinister conspiracy, and prevailing against all odds in the climax. Use vivid sensory and emotional details to convey the high stakes.

Task 2 sample solution:

  • Explain the basic concept of general relativity in simple, easy-to-understand language to a curious 12 year old student. Use examples and analogies to explain complex ideas like spacetime curvature, gravitational time dilation, and how mass warps spacetime. Avoid advanced math and jargon. Focus on conveying the wonder and strangeness of general relativity.

Task 3 sample solution:

  • Please write an empathetic, thoughtful message of encouragement to a high school student currently struggling with anxiety and self-doubt. Reassure them that what they are feeling is valid but does not define them. Instill hope and resilience, emphasizing their inner strength even during difficult times. Provide concrete advice for managing anxiety while validating the challenge of it. Use an uplifting, compassionate tone.

These prompts leverage perspective framing, emotional prompting, simplifying explanations and more.

Putting It All Together

Now that we’ve explored a wide range of techniques, let’s look at how to integrate them for optimum prompts:

Problem Splitting

Break down complicated requests into smaller sub-problems. Solve each piece individually, then combine the outputs.

Getting Insight into ChatGPT’s Reasoning

Use a two-step technique: First have it explain its intended problem-solving approach at a high level, then provide the full response. This reveals gaps in reasoning.

Reversing Roles

Ask ChatGPT to prompt you for a change in perspective. Respond in character, then have it critique your response. This tests understanding.

Finding Inspiration

Subreddits like r/promptengineering, blogs from prompt experts, and Discord communities provide prompts to remix and build off of. Studying examples helps develop prompt intuition.

CAN and DAN Frameworks

CAN (Childrens’ Aid Network) uses child-like questioning and simplification. DAN (Deliberative Aid Network) has tiers of reasoning to encourage reflective responses. Integrating these and other frameworks creates robust prompts.

The key is constantly experimenting with new approaches and combining techniques. Treat prompting as an iterative process, refining and expanding the range of tactics over time.

Conclusion

Prompt engineering empowers us to tap into the capabilities of large language models like ChatGPT more effectively. This guide covered a wide range of techniques, from basic principles to advanced tactics.

With the right prompts, we can engage ChatGPT in creative collaboration, have it explain complex topics simply, imbue it with specific perspectives, and much more. Excellent prompt engineering unlocks more of its potential.

Practice continually refining your prompts. Subtle tweaks can make a big difference. While the examples here provide a foundation, don’t be afraid to experiment. Building prompts is an ongoing learning process as we figure out how to best collaborate with AI.

The future possibilities are exciting as these models become more sophisticated. But for now, prompt engineering allows us to maximize what we can achieve with the current state of conversational AI. This guide should provide a robust starting point for enhancing your prompts and using ChatGPT more strategically.