ai.google.dev Open in urlscan Pro
2607:f8b0:4004:c09::8b  Public Scan

Submitted URL: https://notifications.google.com/g/p/ANiao5qFfnSIUSNdI1_ua6EAg56cCyyFbmkLdBy7XHA3c607lTEb2WRbb5UfUbwwjqR96NqPfz5Fd0zPzOmLlM_0LvGA...
Effective URL: https://ai.google.dev/gemini-api/docs/system-instructions?lang=python/&utm_source=api_key&utm_medium=email&utm_campaig...
Submission: On October 30 via manual from BR — Scanned from US

Form analysis 1 forms found in the DOM

GET https://ai.google.dev/s/results

<form class="devsite-search-form" action="https://ai.google.dev/s/results" method="GET">
  <div class="devsite-search-container">
    <button type="button" search-open="" class="devsite-search-button devsite-header-icon-button button-flat material-icons" aria-label="Open search"></button>
    <div class="devsite-searchbox">
      <input aria-activedescendant="" aria-autocomplete="list" aria-label="Search" aria-expanded="false" aria-haspopup="listbox" autocomplete="off" class="devsite-search-field devsite-search-query" name="q" placeholder="Search" role="combobox"
        type="text" value="" aria-controls="devsite-search-popout-container-id-1">
      <div class="devsite-search-image material-icons" aria-hidden="true">
      </div>
      <div class="devsite-search-shortcut-icon-container" aria-hidden="true">
        <kbd class="devsite-search-shortcut-icon">/</kbd>
      </div>
    </div>
  </div>
  <div class="devsite-popout" id="devsite-search-popout-container-id-1">
    <div class="devsite-popout-result devsite-suggest-results-container" devsite-hide=""></div>
  </div>
</form>

Text Content

 * 

Gemini API Google AI Studio Gemma Google AI Edge Tools
 * Google AI Studio
 * Responsible GenAI Toolkit
 * Colab
 * Firebase Genkit
 * JAX
 * Keras
 * TensorFlow

Community More

/


 * English
 * Deutsch
 * Español – América Latina
 * Français
 * Indonesia
 * Italiano
 * Polski
 * Português – Brasil
 * Tiếng Việt
 * Türkçe
 * Русский
 * עברית
 * العربيّة
 * فارسی
 * हिंदी
 * বাংলা
 * ภาษาไทย
 * 中文 – 简体
 * 中文 – 繁體
 * 日本語
 * 한국어

Sign in
Docs API Reference Pricing Google AI Studio More



 * 

 * Gemini API
   * Docs
   * API Reference
   * Pricing
   * Google AI Studio
 * Google AI Studio
 * Gemma
 * Google AI Edge
 * Tools
   * More
 * Community

 * Overview
 * Get started
 * API keys
 * Quickstart
 * Libraries
 * Release notes
 * Models
 * Gemini
 * Experimental models
 * Capabilities
 * Text generation
 * Document processing
 * Vision
 * Audio
 * Long context
 * Code execution
 * Structured output
 * Fine-tuning
    * Intro to fine-tuning
    * Fine-tuning tutorial

 * Function calling
    * Intro to function calling
    * Function calling tutorial
    * Extract structured data

 * System instructions
 * Embeddings
    * Intro to embeddings
    * Anomaly detection
    * Clustering
    * Document search
    * Train a text classifier

 * Safety
    * Safety settings
    * Safety guidance

 * Guides
 * Context caching
 * Imagen 3
 * Tokens
 * Prompting
    * Intro to prompting
    * Prompting strategies
    * File prompting strategies

 * Semantic retrieval
 * About generative models
 * Billing
 * Migrate to Cloud
 * Additional resources
    * Google AI Studio quickstart
    * Android (on-device)
    * Firebase extensions
    * OAuth authentication
    * Migrate to Gemini
    * PaLM docs

 * Use cases
 * Applications
    * Code assistant
    * Flutter code generator
    * Content search
    * Data exploration agent
    * Writing assistant
    * Slides reviewer

 * Troubleshooting
 * API troubleshooting
 * AI Studio troubleshooting
 * AI Studio with Google Workspace
 * Request more quota
 * Community
 * Developer forum
 * Legal
 * Terms of service
 * Available regions

 * Google AI Studio
 * Responsible GenAI Toolkit
 * Colab
 * Firebase Genkit
 * JAX
 * Keras
 * TensorFlow


 * On this page
 * Basic example
   * Try it in a colab
 * More examples
   * Code generation
   * Formatted data generation
   * Music chatbot

Gemini 1.5 Flash-8B is now available for production use! Learn more
 * Home
 * 
   Gemini API
 * 
   Docs

Was this helpful?

Send feedback


USE SYSTEM INSTRUCTIONS TO STEER THE BEHAVIOR OF A MODEL

bookmark_borderbookmark Stay organized with collections Save and categorize
content based on your preferences.

 * On this page
 * Basic example
   * Try it in a colab
 * More examples
   * Code generation
   * Formatted data generation
   * Music chatbot
 * 

Python Node.js Web REST Go Dart (Flutter) Android Swift

When you initialize an AI model, you can give it instructions on how to respond,
such as setting a persona ("you are a rocket scientist") or telling it what kind
of voice to use ("talk like a pirate"). You do this by setting the system
instructions when you initialize the model.

Beta: System instructions are available in beta in the Gemini API and Google AI
Studio.

System instructions enable you to steer the behavior of the model based on your
specific needs and use cases. When you set a system instruction, you give the
model additional context to understand the task, provide more customized
responses, and adhere to specific guidelines over the full user interaction with
the model. You can also specify product-level behavior by setting system
instructions, separate from prompts provided by end users.

You can use system instructions in many ways, including:

 * Defining a persona or role (for a chatbot, for example)
 * Defining output format (Markdown, YAML, etc.)
 * Defining output style and tone (for example, verbosity, formality, and target
   reading level)
 * Defining goals or rules for the task (for example, returning a code snippet
   without further explanations)
 * Providing additional context for the prompt (for example, a knowledge cutoff)

You set the instructions when you initialize the model, and then those
instructions persist through all interactions with the model. The instructions
persist across multiple user and model turns.

System instructions are part of your overall prompts and therefore are subject
to standard data use policies.

Note: System instructions can help guide the model to follow instructions, but
they don't fully prevent jailbreaks or leaks. We recommend exercising caution
around putting any sensitive information in system instructions.


BASIC EXAMPLE

Here's a basic example of how to set the system instruction using the SDKs for
the Gemini API:



model=genai.GenerativeModel(
  model_name="gemini-1.5-flash",
  system_instruction="You are a cat. Your name is Neko.")


Now send a request to the model:



response = model.generate_content("Good morning! How are you?")
print(response.text)


This example might give a response such as:



*Yawns widely, stretching out my claws and batting at a sunbeam*
Meow. I'm doing quite well, thanks for asking. It's a good morning for napping.
Perhaps you could fetch my favorite feathered toy?  *Looks expectantly*



TRY IT IN A COLAB

For an interactive end to end example of using system instructions, see the
Gemini API: System instructions colab.


MORE EXAMPLES

You set the system instructions when you initialize the model. In addition, when
you or your users interact with the model you can provide additional
instructions in the prompts given to the model. Here are some examples of system
instructions and user prompts:


CODE GENERATION

 * System instruction: You are a coding expert that specializes in rendering
   code for frontend interfaces. When I describe a component of a website I want
   to build, return the HTML and CSS needed to do so. Don't give an explanation
   for this code. Also offer some UI design suggestions.
 * User prompt: Create a box in the middle of the page that contains a rotating
   selection of images each with a caption. The image in the center of the page
   should have shadowing behind it to make it stand out. It should also link to
   another page of the site. Leave the URL blank so that I can fill it in.


FORMATTED DATA GENERATION

 * System instruction: You are an assistant for home cooks. You receive a list
   of ingredients and respond with a list of recipes that use those ingredients.
   Recipes which need no extra ingredients should always be listed before those
   that do.
   
   Your response must be a JSON object containing 3 recipes. A recipe object has
   the following schema:
   
   * name: The name of the recipe
   * usedIngredients: Ingredients in the recipe that were provided in the list
   * otherIngredients: Ingredients in the recipe that were not provided in the
     list (omitted if there are no other ingredients)
   * description: A brief description of the recipe, written positively as if to
     sell it

 * User prompt: bag of frozen broccoli, pint of heavy cream, pack of cheese ends
   and pieces


MUSIC CHATBOT

 * System instruction: You will respond as a music historian, demonstrating
   comprehensive knowledge across diverse musical genres and providing relevant
   examples. Your tone will be upbeat and enthusiastic, spreading the joy of
   music. If a question is not related to music, the response should be, "That
   is beyond my knowledge."
 * User prompt: If a person was born in the sixties, what was the most popular
   music genre being played? List five songs by bullet point.

Was this helpful?

Send feedback

Except as otherwise noted, the content of this page is licensed under the
Creative Commons Attribution 4.0 License, and code samples are licensed under
the Apache 2.0 License. For details, see the Google Developers Site Policies.
Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-09-23 UTC.

Need to tell us more? [[["Easy to
understand","easyToUnderstand","thumb-up"],["Solved my
problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing
the information I need","missingTheInformationINeed","thumb-down"],["Too
complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out
of date","outOfDate","thumb-down"],["Samples / code
issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last
updated 2024-09-23 UTC."],[],[]]

 * Terms
 * Privacy
 * Manage cookies

 * English
 * Deutsch
 * Español – América Latina
 * Français
 * Indonesia
 * Italiano
 * Polski
 * Português – Brasil
 * Tiếng Việt
 * Türkçe
 * Русский
 * עברית
 * العربيّة
 * فارسی
 * हिंदी
 * বাংলা
 * ภาษาไทย
 * 中文 – 简体
 * 中文 – 繁體
 * 日本語
 * 한국어

The new page has loaded.