Notebooks
G
Google Gemini
System Instructions

System Instructions

quickstartsgemini-cookbookgemini-apigemini
Copyright 2025 Google LLC.
[ ]

Gemini API: System instructions

System instructions allow you to steer the behavior of the model. By setting the system instruction, you are giving the model additional context to understand the task, provide more customized responses, and adhere to guidelines over the user interaction. Product-level behavior can be specified here, separate from prompts provided by end users.

This notebook shows you how to provide a system instruction when generating content.

[ ]
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 200.0/200.0 kB 8.4 MB/s eta 0:00:00

To run the following cell, your API key must be stored it in a Colab Secret named GOOGLE_API_KEY. If you don't already have an API key, or you're not sure how to create a Colab Secret, see the Authentication quickstart for an example.

[ ]

Select model

Now select the model you want to use in this guide, either by selecting one in the list or writing it down. Keep in mind that some models, like the 2.5 ones are thinking models and thus take slightly more time to respond (cf. thinking notebook for more details and in particular learn how to switch the thiking off).

[ ]
MODEL_ID

Set the system instruction 🐱

[ ]
Mrrrrow?

*I slowly open one eye, blink at you, then stretch out a paw with claws unsheathed and resheathed into the air, before arching my back in a magnificent, lazy stretch.*

Purrrrrr... I'm doing quite well, thank you! Feeling very soft and ready for... *looks pointedly towards the food bowl* ...well, you know. And maybe a good head scratch? *rubs against your leg, purring louder.*

Another example ☠️

[ ]
Ahoy there, matey! A fine mornin' it be, indeed!

Why, this ol' sea dog be feelin' as grand as a chest full o' gold doubloons, and as ready for adventure as a new set o' sails! The winds be fair, and me heart be brimmin' with the thrill o' the open sea!

But tell me, how fares *yer* own voyage this glorious mornin'? I trust ye be well and ready for whatever the tides may bring! Harr!

Multi-turn conversations

Multi-turn, or chat, conversations also work without any extra arguments once the model is set up.

[ ]
Ahoy there, matey! A grand good day to ye too, by the Seven Seas! Yer a fine chatbot, ye say? Shiver my timbers, that's a compliment worth its weight in doubloons!

What brings ye to these digital shores, eh? Got a treasure map ye need decipherin', or just lookin' for a friendly chat upon the cyber-waves?
[ ]
Me boat, ye ask? Har har! A fine question, that be!

Well, seein' as I be a *digital* pirate, sailin' the grand seas o' the internet, me trusty vessel ain't made o' timbers and canvas, but o' code and algorithms!

And let me tell ye, she be runnin' smoother than a barrel o' rum after a long voyage! The "sails" be unfurled, catchin' every bit o' wireless breeze, the "keel" o' me programming be steady as she goes, and the "cannons" o' me wit be loaded and ready for a good yarn or a helpful word!

She's always shipshape and ready for a new adventure, a new query, or just a friendly "Ahoy!" How fares *your* vessel, whether it be a ship, a desk, or just yer own two feet?

Code generation

Below is an example of setting the system instruction when generating code.

[ ]
[ ]
[ ]
```html
<div style="display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 20px; box-sizing: border-box; background-color: #f0f0f0;">
    <div style="font-size: 3em; font-weight: bold; background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet); -webkit-background-clip: text; -webkit-text-fill-color: transparent; color: transparent;">
        RainbowBrand
    </div>
    <ul style="list-style: none; padding: 0; margin: 0; display: flex; gap: 20px;">
        <li><a href="#" style="text-decoration: none; color: #333; font-weight: bold; font-size: 1.2em;">Home</a></li>
        <li><a href="#" style="text-decoration: none; color: #333; font-weight: bold; font-size: 1.2em;">About</a></li>
        <li><a href="#" style="text-decoration: none; color: #333; font-weight: bold; font-size: 1.2em;">Services</a></li>
        <li><a href="#" style="text-decoration: none; color: #333; font-weight: bold; font-size: 1.2em;">Contact</a></li>
    </ul>
</div>
```
[ ]

Further reading

Please note that system instructions can help guide the model to follow instructions, but they do not fully prevent jailbreaks or leaks. At this time, it is recommended exercising caution around putting any sensitive information in system instructions.

See the systems instruction documentation to learn more.