
Elements of a Prompt ๐งฉ
Understanding the four key components that make up an effective prompt: <Highlight>Instruction</Highlight>, <Highlight>Context</Highlight>, <Highlight>Input Data</Highlight>, and <Highlight>Output Indicator</Highlight>.
This content is adapted from Prompting Guide: Elements of a Prompt. It has been curated and organized for educational purposes on this portfolio. No copyright infringement is intended.
What Makes Up a Prompt?
As you build more complex applications with LLMs, you'll notice that effective prompts typically consist of several distinct elements. While you don't need all of them for every task, combining them correctly is the key to prompt engineering.
A prompt can contain any of the following four elements:
- Instruction: A specific task or instruction you want the model to perform.
- Context: External information or additional background that can steer the model to better responses.
- Input Data: The specific input or question we are interested in finding a response for.
- Output Indicator: The desired type or format of the output (e.g., JSON, a list, a single word).
Example: Text Classification
To demonstrate these elements, let's look at a simple prompt designed for sentiment classification:
Prompt
Classify the text into neutral, negative, or positive.
Text: I think the food was okay.
Sentiment:Breakdown of Elements:
- Instruction: "Classify the text into neutral, negative, or positive."
- Input Data: "I think the food was okay."
- Output Indicator: "Sentiment:"
- Context: In this basic example, no context is provided. However, you could add context by providing examples of previous classifications (few-shot prompting) to help the model better understand the nuances of your specific task.
Flexibility in Design
It's important to remember that you do not need all four elements for every prompt. The format depends entirely on the task at hand.
- For a simple Question Answering task, you might only need an Instruction and Input Data.
- For a Creative Writing task, you might rely heavily on Context and Instruction.
- For Data Extraction, the Output Indicator becomes critical to ensure the results are machine-readable.
We will explore more concrete examples and how these elements interact in the upcoming sections.