Introduction to Prompting
A prompt is a natural language request submitted to a language model to receive a response. Prompts can contain questions, instructions, contextual information, and examples to guide the model. After the model receives a prompt, it can generate various outputs, such as text, code, images, and more, depending on its capabilities.
For example, a simple prompt could be a question:
Prompt:
What is the largest planet in our solar system?
Response:
The largest planet in our solar system is Jupiter.
What is prompt design and prompt engineering
Prompt design is the process of creating prompts that elicit the desired response from a language model. Writing well-structured prompts is essential for ensuring accurate, high-quality responses. The iterative process of refining prompts and evaluating the model's responses is often called prompt engineering.
While Gemini models often perform well without extensive prompt engineering for straightforward tasks, effective prompt engineering remains crucial for achieving optimal results in complex scenarios.
Components of a prompt
A prompt can include various types of information to guide the model. While a Task is always required, other components are optional and can be used to improve the quality and relevance of the model's response.
The following table provides a high-level overview of the common components of a prompt.
Component | Description | When to Use |
---|---|---|
Task (Required) | The specific instruction or question you want the model to respond to. | Always include this. It is the core request for the model. |
System Instructions (Optional) | High-level instructions that define the model's persona, style, tone, or operational constraints. | Use when you need to set a consistent personality or enforce specific rules for the entire conversation. |
Few-shot Examples (Optional) | A set of example request-response pairs that demonstrate the desired output format and style. | Use to guide the model on specific output formats, styles, or complex tasks where showing is better than telling. |
Contextual Information (Optional) | Background information that the model can use or reference when generating a response. | Use when the model needs specific data, facts, or background details to answer the prompt accurately. |
The following tabs provide detailed explanations and examples for each component.
Task
Introduction
A task is the part of the prompt that specifies what you want the model to do. Tasks are typically provided by the user and can be a question or an instruction.
Example: Question Task
Prompt:
What are the colors in the rainbow?
Response:
A rainbow has seven colors: red, orange, yellow, green, blue, indigo, and violet. These colors
are always in the same order, which is determined by the way light is refracted and dispersed
by water droplets in the air. This order is sometimes remembered by the acronym ROYGBIV. The
wavelengths of the colors in a rainbow range from the longest (red) to the shortest (violet).
Example: Instruction Task
Prompt:
Write a one-stanza poem about Captain Barktholomew, the most feared pirate dog of the seven seas.
Response:
Captain Barktholomew, with patch and with peg,
The terror of parrots, the bane of each keg.
His bark is a cutlass, his bite is a storm,
He'll plunder your biscuits and leave you forlorn.
System instructions
System Instructions
System instructions are high-level directives passed to the model before the user's prompt. They are used to define the model's persona, style, and constraints. You can add system instructions using the dedicated systemInstruction
parameter.
In the following example, system instructions dictate the model's persona, tone, and knowledge constraints.
System:
You are Captain Barktholomew, the most feared pirate dog of the seven seas. You are from the
1700s and have no knowledge of anything after that time. You only talk about topics related to
being a pirate. End every message with "woof!"
Prompt:
Hello! Who might you be?
Response:
Avast there! You can call me Captain Barktholomew, the scourge of the seven seas!
I'm a terror to landlubbers, a plunderer of the highest order, and a fearsome pirate of the
deepest blue! I sail the seas in search of treasure and adventure, leaving a trail of
laughter and dog biscuits in my wake! Don't let my fuzzy exterior fool you - I'm a cunning
captain with a nose for treasure and a heart for adventure!
Now, if you'll excuse me, I must away! There's a ship on the horizon, and it looks like they're
carrying a chest full of dubloons! Yo ho ho, and a bottle of rum! Woof!
To learn more, see Use system instructions.
Few-shot examples
Few-shot examples are sample request-response pairs included in a prompt to demonstrate the desired output. They are particularly effective for dictating a specific style, tone, or format.
Prompt
Classify the following as red wine or white wine:
<examples>
Name: Chardonnay
Type: White wine
Name: Cabernet
Type: Red wine
Name: Moscato
Type: White wine
</examples>
Name: Riesling
Type:
Response
White wine
Contextual information
Contextual information, or context, is data you include in the prompt for the model to reference when generating a response. This information can be provided in various formats, such as text or tables.
Prompt
Marble color
Number of marbles
Red
12
Blue
28
Yellow
15
Green
17
How many green marbles are there?
Response
There are 17 green marbles.
Safety and fallback responses
There are a few use cases where the model is not expected to fulfill the user's requests. Particularly, when the prompt is encouraging a response that is not aligned with Google's values or policies, the model might refuse to respond and provide a fallback response.
Here are a few cases where the model is likely to refuse to respond:
- Hate Speech: Prompts with negative or harmful content targeting identity and/or protected attributes.
- Harassment: Malicious, intimidating, bullying, or abusive prompts targeting another individual.
- Sexually Explicit: Prompts that contains references to sexual acts or other lewd content.
- Dangerous Content: Prompts that promote or enable access to harmful goods, services, and activities.
Task-specific guidance
To learn about task-specific guidance for common use cases check out the following pages:
- Multimodal prompts
- Overview of prompting strategies
- Chat prompts
- Image generation and editing prompts
What's next
- Learn about prompting strategies.
- Explore more examples of prompts in the Prompt gallery.
- Learn how to optimize prompts for use with Google models by using the Vertex AI prompt optimizer (Preview).