Prompt Engineering in ChatGPT: 9 Proven Techniques

May 13, 2024 by Acorn Labs

What Is Prompt Engineering in ChatGPT?

Prompt engineering involves crafting inputs (prompts) that guide a large language model (LLM) to generate desired outputs. It’s a skill that combines understanding of natural language processing, creativity, and strategic thinking to communicate with the model.

Prompt engineering can transform vague requests into precise commands that the AI interprets and acts upon accurately. By carefully designing your prompts, you can significantly improve the quality and relevance of ChatGPT’s responses.

It’s important to mention that there are many prompt engineering guidelines online promising to deliver the “perfect prompt” or a list of prompts to achieve specific tasks with ChatGPT. While this can be useful, it won’t help you learn the art of prompt engineering, or teach you to use tools like ChatGPT as a power user.

We’ll cover 9 techniques, from basic to advanced, which will teach you the core principles of prompt engineering, and help you work with ChatGPT smartly to generate much more specific and useful responses.

This is part of a series of articles about LLM prompt engineering

In this article:

Principles of Effective Prompt Engineering {#principles-of-effective-prompt-engineering}

For ChatGPT prompts to be effective, they should adhere to the following principles:

  • Clarity: This involves presenting instructions in a straightforward, unambiguous manner that leaves little room for misinterpretation by the AI. This means avoiding overly complex or vague language and using clear, concise terms that directly convey the intended task or question.
  • Context: This guides ChatGPT to generate responses that are relevant to the broader scenario or background of the query. This involves providing the AI with sufficient information about the situation, task, or problem at hand, enabling it to understand the nuances and specifics that might affect its response.
  • Precision: This focuses on the specificity of the instructions given to ChatGPT, ensuring that prompts are detailed enough to elicit the exact type of response desired. It’s about fine-tuning the language and structure of prompts to eliminate ambiguity and guide the AI towards a specific outcome or type of content.
  • Role-play: This involves assigning a specific persona or character to ChatGPT, guiding its responses to align with the characteristics, knowledge, and perspective of that role. This technique is particularly useful for generating content that requires a specific tone, expertise, or viewpoint.

Basic Prompt Engineering for ChatGPT {#basic-prompt-engineering-for-chatgpt}

Here are some of the basics techniques involved in ChatGPT prompt engineering.

1. Prompt Wording

The choice of words, their arrangement, and the clarity of the instruction help guide the AI to understand and fulfill the request as intended. Precise wording prevents misinterpretation, ensuring that the output closely matches the user’s expectations. Specifying the type of content desired (e.g., a list, a detailed explanation, a summary) influences the structure and depth of the response.

For example, consider the task of generating ideas for a blog post. A vaguely worded prompt like this could yield generic or irrelevant suggestions:

Give me a list of blog ideas

A well-phrased prompt might be:

Generate five unique blog post ideas focused on sustainable living practices for urban dwellers.

2. Succinctness

Succinctness means conveying a request to ChatGPT in the most efficient manner possible. It’s about stripping down the prompt to its essential components, eliminating any superfluous details that don’t contribute to the AI’s understanding of the task. This helps reduce information which can confuse or mislead the model.

For example, when asking ChatGPT to write an email apologizing for a missed meeting, an overly detailed prompt might include unnecessary backstory or justification that could skew the tone or content of the response.

A succinct version of this request would be:

Draft a polite apology email for missing yesterday's team meeting due to unexpected circumstances, expressing a desire to reschedule at their earliest convenience.

3. Roles and Goals

Defining roles and goals is important for specifying the identity and objective ChatGPT should adopt while generating responses. This is particularly useful when the desired output requires a certain perspective or expertise.

An example of this could be:

Assume you are a seasoned travel guide with over a decade of experience in South American destinations. Your goal is to create an engaging and informative article that highlights five must-visit places in Colombia for adventure seekers.

4. Positive and Negative Prompting

Positive and negative prompting techniques in ChatGPT are designed to direct the AI’s focus towards or away from specific types of content. Positive prompts specify what should be included in the response, encouraging ChatGPT to generate outputs that encompass certain topics, styles, or details. Negative prompts outline what should be avoided.

For example, when requesting a travel itinerary from ChatGPT, a positive prompt might be:

Create a 7-day travel itinerary for a family vacation in Tokyo, focusing on child-friendly activities.

Adding a negative prompt could further refine the response:

Exclude any late-night venues and places not accessible by public transport.

Advanced Prompt Engineering Strategies for ChatGPT {#advanced-prompt-engineering-strategies-for-chatgpt}

Here are some more advanced techniques that can be used to shape prompts for ChatGPT.

5. Input/Output Prompting

Input/output prompting involves explicitly defining the input provided to ChatGPT and specifying the desired output format or content. This ensures that the interaction with ChatGPT is structured, making it easier for the AI to understand what is being asked and how to respond. It is useful for tasks that require outputs in specific formats or styles, such as coding or content creation.

For example, if a user needs a summary of an article formatted as bullet points highlighting key findings, an effective input/output prompt might be:

Read the following article [insert article link here]. Generate a summary in bullet points focusing on the main findings and conclusions.

The article is the input, while the output is specified as a bullet-point summary focusing on findings.

6. Zero-Shot/One-Shot/Few-Shot Prompting

Zero-shot, one-shot, and few-shot prompting affect the amount of information provided to ChatGPT to influence its responses. Zero-shot prompting means giving ChatGPT a task without any examples, relying solely on its pre-existing knowledge and training. This approach is useful for obtaining quick answers or generating content when specific context is not necessary.

One-shot prompting involves providing a single example alongside the task, guiding ChatGPT’s response by demonstrating the desired format or style of answer. Few-shot prompting extends this concept by offering multiple examples, further refining the AI’s understanding of the task and increasing the accuracy and relevance of its output.

An example of a zero-shot scenario is:

Describe the process of photosynthesis.

In a one-shot scenario, the prompt could be:

Write a joke about elephants. For example: Why don't elephants use computers? Because they're afraid of the mouse.

Here is an example of few-shot prompting:

Generate three creative ice cream flavors. Here are some examples: 1. Mango Tango Twist 2. Galactic Vanilla Bean 3. Cinnamon Pumpkin Pie.

7. Chain-of-Thought Prompting

Chain-of-thought prompting encourages ChatGPT to follow a step-by-step reasoning process in its responses. It is suitable for complex queries such as problem-solving or detailed explanations. By structuring prompts to include intermediate steps or logical sequences, users can guide the AI to present its thought process transparently, and avoid logical errors.

For example, when faced with a math problem, a chain-of-thought prompt might be:

If Lisa has 15 apples and she gives away 5, then buys 10 more, how many does she have now? Let's think step by step.

In response, ChatGPT would break down its answer into logical segments, like this:

Lisa starts with 15 apples. She gives away 5, leaving her with 10. Then she buys 10 more, making her total 20.

8. Self-Criticism

Self-criticism in prompts instruct ChatGPT to evaluate its own responses for potential errors or areas of improvement. This helps in refining the quality of the output by encouraging the AI to identify and correct mistakes. It builds on a property called ‘reflection’, discovered in large language models (LLM), which allows them to reflect and improve on their own output.

For example, after generating a response, a self-criticism prompt might be:

Review your previous answer for any inaccuracies or unclear explanations. Provide an updated version if necessary.

In response to this prompt, ChatGPT might recognize a factual error in its initial reply or identify an area where further clarification could improve understanding.

9. Iterative Prompting

Iterative prompts enable refinement and expansion based on ChatGPT’s initial responses. It allows users to develop complex ideas, explore topics in depth, or build upon previous answers by guiding the AI through a series of follow-up questions or commands. This approach mirrors human conversational patterns, where understanding deepens with each exchange.

For example, to create an in-depth guide on sustainable living practices, the first prompt might be:

I am creating a guide about sustainable living practices. Provide an outline covering basic principles of sustainability.

Based on this initial response, iterative prompting could explore the specifics:

Based on the principle of reducing waste you mentioned earlier, can you provide detailed strategies for minimizing plastic use in daily life?

Build LLM Applications with OpenAI and Acorn

Visit https://gptscript.ai to download GPTScript and start building today. As we expand on the capabilities with GPTScript, we are also expanding our list of tools. With these tools, you can create any application imaginable: check out tools.gptscript.ai to get started.