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

System instructions are supported by all Gemini models.

[Jump to code samples](https://firebase.google.com/docs/ai-logic/system-instructions.md.txt#set-si)

<br />

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 specify
product-level behavior in system instructions, separate from prompts provided by
end 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 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)

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

> [!NOTE]
> **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.

## Set system instructions

|---|
| *Click your Gemini API provider to view provider-specific content and code on this page.* <button value="dev" default="">Gemini Developer API</button> <button value="vertex">Agent Platform Gemini API</button> |

> [!NOTE]
> **Note:** For the majority of use cases when accessing a Gemini model, you set system instructions when creating the `GenerativeModel` instance. However, if you're [setting system instructions when using the Gemini Live API](https://firebase.google.com/docs/ai-logic/system-instructions.md.txt#si-gemini-live-api), you set them when creating the `LiveModel` instance.

### Set system instructions for general use cases

### Swift

You specify
[`systemInstruction`](https://firebase.google.com/docs/reference/swift/firebaseailogic/api/reference/Classes/FirebaseAI.md.txt)
when you create a `GenerativeModel` instance.

```swift

import FirebaseAILogic

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

```

### Kotlin

You specify
[`systemInstruction`](https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/FirebaseVertexAI#generativeModel(kotlin.String,com.google.firebase.vertexai.type.GenerationConfig,kotlin.collections.List,kotlin.collections.List,com.google.firebase.vertexai.type.ToolConfig,com.google.firebase.vertexai.type.Content,com.google.firebase.vertexai.type.RequestOptions))
when you create a `GenerativeModel` instance.

```kotlin

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

```

### Java

You specify
[`systemInstruction`](https://firebase.google.com/docs/reference/android/com/google/firebase/ai/FirebaseVertexAI#generativeModel(kotlin.String,com.google.firebase.vertexai.type.GenerationConfig,kotlin.collections.List,kotlin.collections.List,com.google.firebase.vertexai.type.ToolConfig,com.google.firebase.vertexai.type.Content,com.google.firebase.vertexai.type.RequestOptions))
when you create a `GenerativeModel` instance.

```java

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

GenerativeModelFutures model = GenerativeModelFutures.from(ai);

```

### Web

You specify
[`systemInstruction`](https://firebase.google.com/docs/reference/js/ai.generativemodel.md.txt#generativemodelsysteminstruction)
when you create a `GenerativeModel` instance.

```javascript

// ...

const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

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

```

### Dart

You specify
[`systemInstruction`](https://pub.dev/documentation/firebase_ai/latest/firebase_ai/FirebaseVertexAI/generativeModel.html)
when you create a `GenerativeModel` instance.

```dart

// ...

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

// ...

```

### Unity

You specify
[`systemInstruction`](https://firebase.google.com/docs/reference/unity/class/firebase/a-i/firebase-a-i.md.txt#getgenerativemodel)
when you create a `GenerativeModel` instance.

```c#

// ...

var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());

// Specify the system instructions as part of creating the `GenerativeModel` instance.
var model = ai.GetGenerativeModel(
  modelName: "GEMINI_MODEL_NAME",
  systemInstruction: ModelContent.Text("You are a cat. Your name is Neko.")
);

```

### Set system instructions for the Gemini Live API

### Swift

You specify
[`systemInstruction`](https://firebase.google.com/docs/reference/swift/firebaseailogic/api/reference/Classes/FirebaseAI.md.txt#parameters_3)
when you create a `LiveModel` instance.

```swift

// ...

// Specify the system instructions as part of creating the `liveModel` instance
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
  modelName: "GEMINI_LIVE_MODEL_NAME",
  systemInstruction: ModelContent(role: "system", parts: "You are a cat. Your name is Neko."),
  // ...
)

// ...

```

### Kotlin

You specify
[`systemInstruction`](https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/FirebaseVertexAI#liveModel(kotlin.String,com.google.firebase.vertexai.type.LiveGenerationConfig,kotlin.collections.List,com.google.firebase.vertexai.type.Content,com.google.firebase.vertexai.type.RequestOptions))
when you create a `LiveModel` instance.

```kotlin

// ...

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

// ...

```

### Java

You specify
[`systemInstruction`](https://firebase.google.com/docs/reference/android/com/google/firebase/ai/FirebaseVertexAI#liveModel(kotlin.String,com.google.firebase.vertexai.type.LiveGenerationConfig,kotlin.collections.List,com.google.firebase.vertexai.type.Content,com.google.firebase.vertexai.type.RequestOptions))
when you create a `LiveModel` instance.

```java

// ...

// Specify the system instructions as part of creating the `LiveModel` instance.
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
          /* modelName */ "GEMINI_LIVE_MODEL_NAME",
          /* systemInstruction (optional) */ new Content.Builder().addText("You are a cat. Your name is Neko.").build()
          // ...
);

LiveModelFutures liveModel = LiveModelFutures.from(lm);

// ...

```

### Web

You specify
[`systemInstruction`](https://firebase.google.com/docs/reference/js/ai.livegenerativemodel.md.txt#livegenerativemodelsysteminstruction)
when you create a `LiveGenerativeModel` instance.

```javascript

// ...

const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Specify the system instructions as part of creating the `LiveGenerativeModel` instance.
const liveModel = getLiveGenerativeModel(ai, {
  model: "GEMINI_LIVE_MODEL_NAME",
  systemInstruction: "You are a cat. Your name is Neko.",
  // ...
});

// ...

```

### Dart

You specify
[`systemInstruction`](https://pub.dev/documentation/firebase_ai/latest/firebase_ai/FirebaseVertexAI/liveGenerativeModel.html)
when you create a `LiveGenerativeModel` instance.

```dart

// ...

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

// ...

```

### Unity

You specify
[`systemInstruction`](https://firebase.google.com/docs/reference/unity/class/firebase/a-i/firebase-a-i.md.txt#getlivemodel)
when you create a `LiveModel` instance.

```c#

// ...

// Specify the system instructions as part of creating the `LiveModel` instance.
var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
  modelName: "GEMINI_LIVE_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 expected
behavior of the model. Some examples also show an example prompt for which the
system instruction would be helpful.

### 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, please
  return the HTML and CSS needed to do so. Do not 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.

### 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.

### Formatted data generation

> [!NOTE]
> **Note:** If you want more control and consistency for the generation of structured content (like JSON output), we recommend providing a `responseSchema` in your request. Learn more about [generating structured output](https://firebase.google.com/docs/ai-logic/generate-structured-output.md.txt).

- **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:**

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

## Other options to control content generation

- Learn more about [prompt design](https://firebase.google.com/docs/ai-logic/prompt-design.md.txt) so that you can influence the model to generate output specific to your needs.
- Configure [model parameters](https://firebase.google.com/docs/ai-logic/model-parameters.md.txt) to control how the model generates a response, like max output tokens, the probability of repeated output tokens, etc.
- Use [safety settings](https://firebase.google.com/docs/ai-logic/safety-settings.md.txt) to adjust the likelihood of getting responses that may be considered harmful, including hate speech and sexually explicit content.
- Pass a [*response schema*](https://firebase.google.com/docs/ai-logic/generate-structured-output.md.txt) along with the prompt to specify a specific output schema. This feature is most commonly used when [generating JSON output](https://firebase.google.com/docs/ai-logic/generate-structured-output.md.txt#generate-json-basic), but it can also be used for [classification tasks](https://firebase.google.com/docs/ai-logic/generate-structured-output.md.txt#generate-enum-basic) (like when you want the model to use specific labels or tags).