This article is a technical explanation and implementation example generated using AI. Although the provided code and procedures are based on primary sources, the author has not verified their operation on actual hardware. Behavior may vary depending on the environment and version.
Organizing Google Cloud Official Prompt Design Elements
The purpose of this document is to provide a safe and practical understanding of the basic concepts of prompt design introduced in Google Cloud's official documentation and the elements that constitute a prompt. Based on official information, we organize the main elements for appropriately constructing natural language requests to LLMs (Large Language Models) and how they affect the responses.
Basics of Prompt Design and Prompt Engineering
Prompt design is the process of creating prompts to elicit the desired response from a language model. Creating well-structured prompts is a key factor in ensuring accurate and high-quality responses. Furthermore, the iterative process of continuously updating prompts and evaluating model responses is called prompt engineering.
Gemini models tend to perform well on straightforward and simple tasks without requiring specialized prompt engineering. However, effective prompt engineering continues to play an important role when handling complex tasks.
flowchart TD
UserPrompt[ユーザーからのプロンプト] --> GeminiModel[Geminiモデル]
GeminiModel --> GenText[テキスト・コード等の生成]
Four Elements Composing a Prompt
A prompt can include any information deemed important to advance the task. Primary sources explain that prompt content is generally classified into one of the following components.
Task (Required)
System instructions (Optional)
Few-shot examples (Optional)
Contextual information (Optional)
We will examine the roles and specific examples of each element as indicated in the official information.
Role and Writing Method of Task
The task refers to the text itself for which you want the model to provide a response. Tasks are typically provided by the user and include questions or instructions on "what should be done."
An example of a question-format task is a question about the colors of a rainbow and the response to it. As stated in the primary source, a rainbow has seven colors determined by the refraction and dispersion of light, and can be remembered by the acronym "ROYGBIV."
Additionally, instruction-format tasks can request specific characters or the creation of poems. For example, an instruction to write a stanza of poetry about "Captain Barkswolomew," the most feared pirate dog of the seven seas, can be provided.
Control via System Instructions
System instructions are instructions passed to the model prior to the user input within the prompt. This is a dedicatedsystemInstructionIt can be configured by adding it to the parameters.
By using system instructions, you can define the style and tone of the model while imposing constraints on what it can and cannot discuss. The primary documentation provides an example of setting a 1700s pirate dog persona and constraints, ending every message with "woof!".
Customizing behavior with few-shot examples
Few-shot examples are instances included in the prompt to demonstrate what the expected output looks like. This element is considered particularly effective for defining the response style and tone and customizing model behavior.
In the official example, for the task of classifying wine names as "red wine" or "white wine", several classification examples (such as Chardonnay and Cabernet) are provided in advance using <examples> tags, followed by a new input (Riesling) to elicit the response "White wine".
Utilizing contextual information
Contextual information refers to data included in the prompt that the model uses or references when generating a response. It can be included in various formats, such as tables and text.
The official documentation provides an example of a prompt containing contextual information in a tabular format summarizing the colors and counts of marbles. It illustrates how, in response to the question "How many green marbles are there?", the model refers to the table and accurately responds "There are 17".
Safety and fallback response mechanisms
There are cases where the model fails to satisfy the user's request. In particular, if a prompt is entered that encourages responses inconsistent with Google's values and policies, the model may refuse the request and provide a fallback response. The primary documentation notes that refusals may occur in the following cases:
Hate Speech: Prompts containing negative or harmful content targeting identity or protected characteristics.
Harassment: Malicious, intimidating, bullying, or abusive prompts targeting other individuals.
Sexually Explicit: Prompts containing references to sexual acts or other obscene content.
Dangerous Content: Prompts that promote or facilitate access to harmful goods, services, or activities.
Conclusion
This article outlined the basic concepts and components of prompt design based on the official Google Cloud documentation. Points to check and considerations before execution are as follows:
A prompt consists of a mandatory "Task" and optional elements such as "System instructions", "Few-shot examples", and "Contextual information" added as needed.
For complex tasks, properly combining these elements allows you to control the model's style and output accuracy.
Content that violates Google's safety policies (such as hate speech, harassment, sexual content, and dangerous content) will be refused by the model.
All contents of this article are based on research and explanations from the official documentation, and do not represent code execution results on actual hardware.

