Basics of Prompting

Learn about prompting guidelines with example prompts.

Prompt formatting is crucial for effective interaction with ChatGPT. A well-structured prompt provides explicit instructions, context, input data, and output indicators, enabling the model to generate accurate and desired responses.

Press + to interact

To write a well-formatted prompt, we need to follow the principles of prompting.

  • Write clear and specific instructions.
  • Give the model time to think.

In this lesson, we’ll delve into prompt formatting, explore the components of a well-structured prompt—namely focusing on instructions, context, input data, and output indicators—and provide practical guidelines for crafting effective prompts following the principles of prompting.

Instructions

A specific directive or guidance is given to the model with the prompt for generating the desired output. Instructions can be explicit statements or guidelines that tell the model how to approach the task. They provide specific rules or constraints for the model to follow during the generation process.

Instructions form the foundation of a prompt. They convey the specific task or behavior we expect from the model. To create clear instructions:

  • Be explicit: Clearly state what we want the model to do or generate. Avoid ambiguity or open-ended instructions.
  • Specify desired format or actions: Provide guidance on the structure or type of response we expect. For example, ask the model to list advantages or generate a dialogue.
  • Include constraints or limitations: If necessary, define any constraints or limitations to guide the model’s response. For instance, ask the model to answer in a specific context or provide a response within a certain character limit.


Prompt: You are creating a chatbot for a pizza delivery service. Your task is to generate a response to a customer inquiry about ordering a pizza. Be explicit about the available toppings, specify the desired format for the order, and include the constraint that the customer can only choose a maximum of three toppings.

Response:

Customer: "I'd like to order a pizza."

ChatGPT: "Sure! We offer a variety of toppings for your pizza. You can choose from options like pepperoni, mushrooms, onions, green peppers, and more. Please specify the size and type of crust you prefer. Also, keep in mind that you can select up to three toppings for your pizza. How would you like to proceed?"

In this example, the rules are applied as follows:

  • We can be explicit by providing a detailed list of available toppings.

  • We can specify the desired format or actions by asking the customer to specify the size and type of crust.

  • We can include constraints or limitations by informing the customer about the maximum limit of three toppings.

Following these rules, the generated response addresses all the specific aspects mentioned in the instructions, resulting in a clear and actionable message for the customer.

Context

Context refers to the initial conversation or information that provides additional background and context with the prompt for the model to generate a response. It includes the conversation history or relevant information preceding the current query or instruction.

Context provides the necessary information for the model to understand the desired scenario. To provide effective context:

  • Set the scene: Introduce the task’s relevant background, scenario, or context. This helps the model generate responses that align with the desired context.
  • Include relevant details: Specify any relevant information that may influence the model’s understanding of the prompt. This could include prior conversation history, specific user preferences, or situational details.


Prompt: I am in a foreign country and need to ask for directions to the nearest train station. How do I ask for directions in French?

Output: Excusez-moi, pourriez-vous me dire comment aller à la gare la plus proche?

This translates to: Excuse me, could you tell me how to get to the nearest train station?

Explanation:

  • The context sets the scene by mentioning being in a foreign country and needing to ask for directions to the nearest train station.

  • The prompt translates the response sentence to French, implying that the response should provide the translated version.

By following these rules, the prompt establishes the context of being in a foreign country and needing directions to the nearest train station. It also specifies the task of translating an English sentence into French. This helps generate a response that accurately translates the given sentence into French, which aligns with the intended purpose of the prompt.

Input data

Input data gives the model-specific information or examples to generate accurate responses. To incorporate input data effectively:

  • Provide examples or references: Supply concrete examples or references related to the task to guide the model’s understanding. This can be in structured data, text snippets, or specific input format instructions.
  • Ensure data relevance: Ensure the input data is relevant and aligned with the prompt’s objective. It should assist the model in generating contextually appropriate responses.


Prompt: Summarize the following article:

Input Data: Article Title: The Benefits of Regular Exercise

.

.

.

Article Summary: This article discusses the numerous benefits of incorporating regular exercise into one's lifestyle, including improved physical health, mental well-being, and increased longevity.

Explanation

  • In this prompt, the input data is explicitly mentioned in the article “The Benefits of Regular Exercise.” This serves as a reference for the task, ensuring the summary is based on the specific article mentioned.

  • The prompt summarizes the given article, indicating the importance of including relevant information in the summary. Limiting the scope to the provided article, it ensures that the summary captures the key points and main ideas presented in the original content.

Output indicators

Output indicators help shape the desired format or structure of the model’s response. To utilize output indicators effectively:

  • Specify output requirements: Indicate the expected format or structure of the response. This could involve using placeholders, specifying the desired order of information, or providing template-based instructions.
  • Guide the model’s response: Use output indicators to instruct the model to generate specific types of content, such as providing a definition, answering a question, or completing a given statement.


Prompt: Fill in the missing information in the following template:

Output Indicator: The [noun] jumped over the [noun].

Ouput: The cat jumped over the fence.

Here's a quick breakdown of the example given above:

  • Specify output requirements: “Fill in the missing information in the following template.”

  • Guide the model's response: “Output Indicator: The [noun] jumped over the [noun].”

Guidelines for formatting prompts

Here are a few guidelines to keep in mind while prompting:

  • Be clear and specific about the task or question.
  • Provide sufficient context to help the model understand the prompt.
  • Use explicit examples or input data to guide the model’s understanding.
  • Control response length by defining boundaries or experimenting with token counts.
  • Utilize system-level instructions to set tone or behavior (temperature or top-k and top-p values).
  • Iterate and refine prompts based on feedback and results.

Prompt formatting is a crucial aspect of interacting with language models effectively. By structuring prompts with clear instructions, relevant context, input data, and output indicators, we can guide the model to generate accurate and contextually appropriate responses. Following the guidelines for prompt formatting will help us achieve the desired outcomes when working with language models like ChatGPT.