Skip to content
Back to log

System Prompt Design

Chainabit's Chao · · 7 min read

In short

A system prompt can define the model’s role and the rules it follows when responding. Explore the structures and examples described by Anthropic, OpenAI, and Google Cloud.

Google Cloud defines a system instruction as a set of instructions the model processes before it processes the prompt. These instructions can specify the model’s role, provide context, and define the response format. Once set, a system instruction applies to the entire request. When included in the prompt, it can also apply across multiple user and model turns.

Anthropic recommends stating the expected output format and constraints explicitly. If the order of the steps matters or every step must be completed, the instructions can be written as a numbered or bulleted list. Anthropic also recommends asking directly for anything you expect the model to do beyond the task’s explicit requirements.

Defining the role and task

According to Anthropic, assigning a role in the system prompt helps tailor Claude’s behavior and tone to the use case. Google Cloud also lists defining a chatbot’s persona or role as a use case for system instructions. The same instruction can specify the goals and rules for the task.

In Google Cloud’s translation example, the system instruction defines the model as a translator. A separate statement specifies its task of translating English text into French. The user input supplies the text to translate. The role and task are defined in the system instruction, while the text to process is provided in the prompt.

OpenAI describes the identity section of a developer message in terms of the assistant’s purpose, communication style, and high-level goals. The instructions section can specify how the model should produce its response and which rules it should follow. It can also include subsections tailored to the use case. OpenAI gives guidance on calling custom functions as an example of what a subsection might cover.

In Google Cloud’s code generation example, the model takes the role of an expert who writes code for front-end interfaces. The system instruction asks for the necessary HTML and CSS when the user describes a website component. It also asks for interface design suggestions and directs the model to omit explanations of the code. The same instruction defines what to generate and what the response should cover.

Scope and message priority

In Google Cloud, the system instruction is separate from the prompt content. It remains part of the overall prompt and is subject to standard data use policies. In a multi-turn conversation, a system instruction included in the prompt can apply across both user and model turns.

In the OpenAI API, the instructions parameter carries high-level instructions that govern the model’s behavior as it generates a response. OpenAI lists tone, goals, and examples of correct responses among the things this parameter can contain. These instructions take precedence over user messages in input.

In OpenAI’s description of message roles, developer messages carry instructions from the developer and take precedence over user messages. The user messages contain instructions from the end user. Messages generated by the model use the assistant role. A multi-turn conversation can contain these message types alongside other types of content.

OpenAI compares the relationship between developer and user messages to that between a function and its arguments. The developer message supplies the system’s rules and business logic. The user message supplies the inputs and configuration to which those instructions apply. The two roles let developers express the system’s rules and the end user’s inputs in separate messages.

Output format, language, and style

According to Google Cloud, a system instruction can specify an output format such as Markdown or YAML. It can also define stylistic preferences such as response length, level of formality, and target reading level. A task rule might also ask the model to return a code snippet without additional explanation.

In Google Cloud’s recipe example, the assistant’s role is to help home cooks. It is asked to generate a list of recipes from the ingredients the user provides. The system instruction also says to list recipes that require no additional ingredients first. The task definition therefore includes a rule for ordering the results.

The same example requires the response to be a JSON object, with specific fields for each recipe object. The name field holds the recipe’s name, and usedIngredients lists the ingredients from the user’s list that the recipe uses. The otherIngredients field lists ingredients the user did not provide and is omitted if there are none. The description field contains a short description of the recipe.

Turn this insight into action.

Use the mobile app to continue with guided workflows.

According to Google Cloud, a system instruction can also specify which language the model should respond in. Google Cloud gives an example that directs the model to reply in the same language as the query when the prompt is in a language other than English. It also asks the model to answer in detail unless the user explicitly requests a short response.

Anthropic recommends phrasing formatting instructions in terms of what the model should do. For example, a request to avoid Markdown can be phrased as a request for flowing prose paragraphs. Anthropic also shows how to mark off prose sections with XML tags.

Anthropic notes that the format of the prompt can influence the format of the response. It suggests removing Markdown formatting from the prompt to reduce its use in the output. It also shows how to give explicit instructions for more detailed formatting preferences.

Organizing instructions and examples into sections

OpenAI explains that Markdown and XML tags can be used together in developer and user messages. Markdown headings and lists can show the sections and hierarchy of the prompt. XML tags can mark the beginning and end of content blocks. XML attributes can define metadata about the content that the instructions can refer to.

In the general developer message structure OpenAI describes, examples and context can follow the identity and instructions sections. Examples show possible inputs and the expected outputs for each. The context section contains additional information the model may need to generate a response. OpenAI notes that the exact contents and order of these sections can vary by model.

Anthropic describes using XML tags to structure complex prompts that combine instructions, context, examples, and variable inputs. Tags such as <instructions>, <context>, and <input> distinguish different types of content. Anthropic recommends choosing descriptive tag names and using them consistently. Tags can also be nested when the content has a natural hierarchy.

Anthropic also recommends marking examples separately. A single example can be wrapped in an <example> tag, while multiple examples can be grouped under an <examples> tag. The examples should be relevant to the actual use case. According to Anthropic, varied examples help cover edge cases and reduce the chance that the model will infer an unintended pattern.

OpenAI describes few-shot learning as adding a handful of input and output examples to a prompt. The model can pick up the pattern in those examples and apply it to a new input. OpenAI recommends showing a range of possible inputs and the desired output for each. These examples are typically included in the developer message of the API request.

In one OpenAI example, the assistant is tasked with labeling product reviews by sentiment. The examples in the developer message pair review text with the corresponding labels. The instruction calls for a single-word response without additional formatting or explanation. It also lists the allowed labels.

Adding context and explaining the purpose of an instruction

According to Anthropic, explaining the context or purpose behind an instruction gives the model more information about the goal. In Anthropic’s example, the instruction asks the model to avoid ellipses and explains why. A text-to-speech engine will read the response aloud and will not know how to pronounce them. The instruction describes the desired behavior alongside the conditions in which the response will be used.

In OpenAI’s description of prompt structure, context can include private data or other information relevant to a particular generation request. Since the context can vary from one request to another, OpenAI says it is typically placed near the end of the prompt. Additional context can also give the model access to information outside its training data.

For reusable instructions, OpenAI points to the first developer message in the Responses input array. It also recommends placing reusable examples and reference material before the variable user input. According to OpenAI, this arrangement keeps the shared prefix eligible for prompt caching.

Limits and evaluation

According to OpenAI, model output is nondeterministic. Different types of models may require different prompting approaches. Different snapshots within the same model family can also produce different results. OpenAI also notes that the amount of context a model can process in a single generation request is limited by its context window.

OpenAI recommends building tests and evaluation suites to measure prompt behavior. These can help track performance as the prompt changes or when switching models. The scope Google Cloud describes for system instructions also extends to data use. A system instruction is kept separate from the prompt content and remains part of the overall prompt, subject to standard data use policies.

Ready to start?

Download the app and continue from your phone.

End of Entry