Use system instructions to steer the behavior of a model

System instructions are like a "preamble" that you add before the model getsexposed to any further instructions from the end user. It lets you steer thebehavior of the model based on your specific needs and use cases.

Jump to code samples


When you set a system instruction, you give the model additional context tounderstand the task, provide more customized responses, and adhere to specificguidelines over the full user interaction with the model. You can specifyproduct-level behavior in system instructions, separate from prompts provided byend users. For example, you can include things like the role or persona,contextual information, and formatting instructions.

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 targetreading level)
  • Defining goals or rules for the task (for example, returning a code snippetwithout further explanations)
  • Providing additional context for the prompt (for example, a knowledge cutoff)

When a system instruction is set, it applies to the entire request. It worksacross multiple user and model turns when included in the prompt. Though systeminstructions are separate from the contents of prompt, they are still part ofyour overall prompts and therefore are subject to standard data use policies.

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

System instructions are supported by allGemini models.They aren't supported by theImagen 3 models.

Set system instructions

Click yourGemini API provider to view provider-specific content and code on this page.

Note: For the majority of use cases when accessing aGemini model, youset system instructions when creating theGenerativeModel instance. However,if you'resetting system instructions when using theGemini Live API,you set them when creating theLiveModel instance.

Set system instructions for general use cases

Swift

You specifysystemInstructionwhen you create aGenerativeModel instance.

importFirebaseAI// Specify the system instructions as part of creating the `GenerativeModel` instanceletmodel=FirebaseAI.firebaseAI(backend:.googleAI()).generativeModel(modelName:"GEMINI_MODEL_NAME",systemInstruction:ModelContent(role:"system",parts:"You are a cat. Your name is Neko."))

Kotlin

You specifysystemInstructionwhen you create aGenerativeModel instance.

// Specify the system instructions as part of creating the `GenerativeModel` instancevalmodel=Firebase.ai(backend=GenerativeBackend.googleAI()).generativeModel(modelName="GEMINI_MODEL_NAME",systemInstruction=content{text("You are a cat. Your name is Neko.")})

Java

You specifysystemInstructionwhen you create aGenerativeModel instance.

// Specify the system instructions as part of creating the `GenerativeModel` instanceGenerativeModelai=FirebaseAI.getInstance(GenerativeBackend.googleAI()).generativeModel(/* modelName */"GEMINI_MODEL_NAME",/* generationConfig (optional) */null,/* safetySettings (optional) */null,/* requestOptions (optional) */newRequestOptions(),/* tools (optional) */null,/* toolsConfig (optional) */null,/* systemInstruction (optional) */newContent.Builder().addText("You are a cat. Your name is Neko.").build());GenerativeModelFuturesmodel=GenerativeModelFutures.from(ai);

Web

You specifysystemInstructionwhen you create aGenerativeModel instance.

// ...constai=getAI(firebaseApp,{backend:newGoogleAIBackend()});// Specify the system instructions as part of creating the `GenerativeModel` instanceconstmodel=getGenerativeModel(ai,{model:"GEMINI_MODEL_NAME",systemInstruction:"You are a cat. Your name is Neko."});

Dart

You specifysystemInstruction when you create aGenerativeModel instance.

// ...// Specify the system instructions as part of creating the `GenerativeModel` instancefinalmodel=FirebaseAI.googleAI().generativeModel(model:'GEMINI_MODEL_NAME',systemInstruction:Content.system('You are a cat. Your name is Neko.'),);// ...

Unity

You specifysystemInstructionwhen you create aGenerativeModel instance.

// ...varai=FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());// Specify the system instructions as part of creating the `GenerativeModel` instancevarmodel=ai.GetGenerativeModel(modelName:"GEMINI_MODEL_NAME",systemInstruction:ModelContent.Text("You are a cat. Your name is Neko."));

Set system instructions for theGemini Live API

Swift

TheLive API is not yet supported for Apple platform apps, but check back soon!

Kotlin

You specifysystemInstructionwhen you create aLiveModel instance.

// Specify the system instructions as part of creating the `LiveModel` instancevalmodel=Firebase.ai(backend=GenerativeBackend.googleAI()).liveModel(modelName="GEMINI_MODEL_NAME",systemInstruction=content{text("You are a cat. Your name is Neko.")})

Java

You specifysystemInstructionwhen you create aLiveModel instance.

// Specify the system instructions as part of creating the `LiveModel` instanceLiveModelai=FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(/* modelName */"GEMINI_MODEL_NAME",/* generationConfig (optional) */null,/* safetySettings (optional) */null,/* requestOptions (optional) */newRequestOptions(),/* tools (optional) */null,/* toolsConfig (optional) */null,/* systemInstruction (optional) */newContent.Builder().addText("You are a cat. Your name is Neko.").build());LiveModelFuturesmodel=LiveModelFutures.from(gm);

Web

You specifysystemInstructionwhen you create aLiveGenerativeModel instance.

// ...constai=getAI(firebaseApp,{backend:newGoogleAIBackend()});// Specify the config as part of creating the `LiveGenerativeModel` instanceconstmodel=getLiveGenerativeModel(ai,{model:"GEMINI_MODEL_NAME",systemInstruction:"You are a cat. Your name is Neko.",});// ...

Dart

You specifysystemInstruction when you create aLiveModel instance.

// ...// Specify the system instructions as part of creating the `LiveModel` instancefinalmodel=FirebaseAI.googleAI().liveGenerativeModel(model:'GEMINI_MODEL_NAME',systemInstruction:Content.system('You are a cat. Your name is Neko.'),);// ...

Unity

You specifysystemInstructionwhen you create aLiveModel instance.

// ...varai=FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());// Specify the system instructions as part of creating the `LiveModel` instancevarmodel=ai.GetLiveModel(modelName:"GEMINI_MODEL_NAME",systemInstruction:ModelContent.Text("You are a cat. Your name is Neko."));

Examples of system instructions

Here are some examples of system instructions that help steer the expectedbehavior of the model. Each example also shows an example prompt for which thesystem instruction would be helpful.

Code generation

  • System instruction:
    You are a coding expert that specializes in rendering code for frontendinterfaces. When I describe a component of a website I want to build, pleasereturn the HTML and CSS needed to do so. Do not give an explanation for thiscode. Also offer some UI design suggestions.

  • User prompt:
    Create a box in the middle of the page that contains a rotating selection ofimages each with a caption. The image in the center of the page should haveshadowing behind it to make it stand out. It should also link to another pageof the site. Leave the URL blank so that I can fill it in.

Music chatbot

  • System instruction:
    You will respond as a music historian, demonstrating comprehensive knowledgeacross diverse musical genres and providing relevant examples. Your tone willbe upbeat and enthusiastic, spreading the joy of music. If a question is notrelated 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 genrebeing played? List five songs by bullet point.

Formatted data generation

Note: If you want more control and consistency for the generation of structuredcontent (like JSON output), we recommend providing aresponseSchema in yourrequest. Learn more aboutgenerating structured output.
  • System instruction:
    You are an assistant for home cooks. You receive a list of ingredients andrespond with a list of recipes that use those ingredients. Recipes which needno extra ingredients should always be listed before those that do.

    Your response must be a JSON object containing 3 recipes. A recipe object hasthe 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 thelist (omitted if there are no other ingredients)
    • description: A brief description of the recipe, written positively as ifto sell it
  • User prompt:

    • 1 lb bag frozen broccoli
    • 1 pint heavy cream
    • 1 lb pack cheese ends and pieces

Other options to control content generation

  • Learn more aboutprompt design so that you can influence the model to generate output specific to your needs.
  • Configuremodel parameters to control how the model generates a response. ForGemini models, these parameters include max output tokens, temperature, topK, and topP. ForImagen models, these include aspect ratio, person generation, watermarking, etc.
  • Usesafety settings to adjust the likelihood of getting responses that may be considered harmful, including hate speech and sexually explicit content.
  • Pass aresponse schema along with the prompt to specify a specific output schema. This feature is most commonly used whengenerating JSON output, but it can also be used forclassification tasks (like when you want the model to use specific labels or tags).

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

Last updated 2025-10-03 UTC.