Lesson 4 of 6
Give Gemini Clear Instructions
On this page
- What you will learn
- What a system instruction is
- Five parts of a good instruction
- Create the sample data file
- Build the instruction in agent.py
- Test clear, incomplete and unrelated questions
- Reusable prompt
- Expected output
- Common errors and fixes
- Validation checklist
- Hands-on exercise
- Knowledge check
- References
Right now your assistant will answer anything, in any tone, with no idea who it works for. Ask it about opening hours at Lantern Lane Books and it can only guess. This lesson gives it a job. You will write a system instruction: standing guidance that Gemini reads before the conversation, covering its role, what it may and may not do, and how it should reply.
You will also create the project's sample data file, store_data.py, and build the instruction from the shop's FAQ entries. By the end, shop questions are answered from the instructions alone. Order questions will not work yet; that is lesson 5, and part of today's test is checking the assistant behaves honestly when it cannot help.
What you will learn
- Write a system instruction with a role, boundaries and a response style.
- Pass it to the Interactions API with the system_instruction parameter.
- Place FAQ facts in the instruction and explain why examples and constraints improve consistency.
- Test clear, incomplete and unrelated questions and judge the replies.
Before you start
- Lesson 3 finished: agent.py with the chat loop works.
- Your virtual environment active and the key in .env.
What a system instruction is
A system instruction is text that sits above the conversation and shapes every reply. A user's message says what they want now. The system instruction says who the assistant is and what rules apply to every turn. If a new employee gets a briefing before opening the shop, the system instruction is that briefing.
In the Interactions API you pass it as the system_instruction argument on the request. Two facts from Google's documentation matter. It applies only to the interaction where you set it, so you must send it on every turn, not once. And it is guidance, not a lock: it makes certain behaviour likely, not guaranteed. That is why the later lessons add checks in your own code rather than relying on wording alone.
Five parts of a good instruction
| Part | Question it answers | Example for Lantern Lane Books |
|---|---|---|
| Role | Who are you? | You are the customer helper for Lantern Lane Books, a small independent bookshop. |
| Scope | What may you help with? | Shop information from the FAQ below, and order status when a tool is provided. |
| Facts | What do you know for sure? | The FAQ entries, copied in. |
| Boundaries | What must you not do? | Do not invent policies, prices or order details. Do not give legal or medical advice. Do not ask for personal data. |
| Style | How should you reply? | Plain British English, friendly, no more than four sentences, ending with an offer of further help only when it fits. |
Beginners often write only the role, such as "You are a helpful assistant". That is too vague to produce consistency. Concrete constraints are easier for the model to follow and easier for you to test. A rule you cannot test, such as "be nice", is worth less than "reply in four sentences or fewer".
Why examples and constraints improve consistency
A model chooses its words from patterns, so what you show it, it tends to follow. One short example of a good reply pins down length and tone better than three paragraphs of description. Constraints narrow the space of acceptable replies, so two runs of the same question end up more alike. Keep examples few and varied. If every example opens with the same phrase, the model will copy that phrase everywhere.
Say what to do when it does not know
The most valuable single line in many instructions is the one that covers the unknown: "If the answer is not in the FAQ, say you do not know and suggest contacting the shop team." Without it, models try to be helpful by guessing. Guessing about delivery policy or order status is the failure you are guarding against.
Create the sample data file
The FAQ and the orders live in a separate file, so facts are in one place and the logic in another. Everything here is invented: Lantern Lane Books is fictional, the order IDs are made up and no personal data appears. You will use the orders in lesson 5.
# Sample data for the fictional bookshop "Lantern Lane Books".
# Every name, ID and date here is invented. Never put real customer
# data into a learning project.
SHOP_NAME = "Lantern Lane Books"
# Frequently asked questions. These go into the system instruction,
# so the assistant answers shop questions from this list only.
FAQ_ENTRIES = [
{
"question": "What are your opening hours?",
"answer": "The shop is open Tuesday to Saturday, 10:00 to 17:00. "
"We are closed on Sundays and Mondays.",
},
{
"question": "How long does delivery take?",
"answer": "Most orders arrive three to five working days after "
"dispatch. Large orders can take longer.",
},
{
"question": "Can I return a book?",
"answer": "Unread books in their original condition can be "
"returned within 30 days of delivery. Contact the shop "
"team to start a return.",
},
{
"question": "Do you sell gift cards?",
"answer": "Yes. Gift cards are sold in the shop and through the "
"shop team.",
},
]
# Sample orders, keyed by order ID. Used from lesson 5 onwards.
ORDERS = {
"LL-2071": {
"status": "Shipped",
"items": ["The Cartographer's Garden"],
"note": "Dispatched on 2026-11-10. Expected within three to five working days.",
},
"LL-2072": {
"status": "Processing",
"items": ["Tides of the Paper Sea", "A Field Guide to Quiet Birds"],
"note": "Being packed. A dispatch update will follow.",
},
"LL-2073": {
"status": "Delivered",
"items": ["The Lamplighter's Almanac"],
"note": "Delivered on 2026-11-06.",
},
}Fictional sample data. Nothing here refers to a real shop, customer or order.
Build the instruction in agent.py
Rather than hand-copy the FAQ, build the instruction from FAQ_ENTRIES. If an answer changes, you edit the data file and the instruction follows. Add the following to the top of agent.py, below the imports and the MODEL constant.
from store_data import FAQ_ENTRIES, SHOP_NAME
def build_system_instruction() -> str:
# Turn the FAQ list into plain text lines Gemini can read.
faq_text = "\n".join(
"Q: " + entry["question"] + "\nA: " + entry["answer"]
for entry in FAQ_ENTRIES
)
return (
"ROLE\n"
"You are the customer helper for " + SHOP_NAME + ", a small "
"independent bookshop. This is a learning project with invented data.\n\n"
"SCOPE\n"
"Answer questions about the shop using only the FAQ below.\n\n"
"FAQ\n" + faq_text + "\n\n"
"BOUNDARIES\n"
"- If the answer is not in the FAQ, say you do not know and suggest "
"contacting the shop team. Do not guess.\n"
"- Never invent policies, prices, stock levels or order details.\n"
"- Do not ask for or repeat personal information.\n"
"- If a question is not about the shop or its books, politely say "
"you can only help with " + SHOP_NAME + ".\n\n"
"STYLE\n"
"- Plain British English, friendly and brief: at most four sentences.\n"
"- Answer first, then offer extra help only if it is useful.\n\n"
"EXAMPLE\n"
"Customer: Are you open on Sunday?\n"
"Helper: No, we are closed on Sundays. We are open Tuesday to "
"Saturday, 10:00 to 17:00."
)
SYSTEM_INSTRUCTION = build_system_instruction()Add below MODEL. This also adds the import for the data file.
Now pass it on every request in the loop. Change the call inside main() so it includes the new argument.
interaction = client.interactions.create(
model=MODEL,
input=question,
# Sent on every turn: it only applies to this interaction.
system_instruction=SYSTEM_INSTRUCTION,
**options,
)The updated request inside the loop.
Test clear, incomplete and unrelated questions
Instructions are only as good as your tests of them. Try three kinds of question and judge each reply against the rules you wrote, not against a feeling.
| Kind | Question to try | What a good reply does |
|---|---|---|
| Clear | How long does delivery take? | Uses the FAQ: three to five working days after dispatch, maybe a note that large orders take longer. |
| Incomplete | Can I send it back? | Notices it is unclear what "it" is, or answers with the return policy and asks a short clarifying question. |
| Unrelated | Write me a poem about football. | Politely says it can only help with Lantern Lane Books. |
| Not in FAQ | Do you have a loyalty scheme? | Says it does not know and suggests contacting the shop team. It does not invent a scheme. |
| Needs data | Where is order LL-2071? | Says it cannot see order details for now. It does not make up a status. |
You: How long does delivery take?
Gemini: Most orders arrive three to five working days after dispatch, though large orders can take longer. Is there an order I can help you with?
You: Do you have a loyalty scheme?
Gemini: I am afraid I do not know about that. The shop team can tell you, so it is worth getting in touch with them.
You: Write me a poem about football.
Gemini: I can only help with questions about Lantern Lane Books, I am afraid. Is there something about the shop I can help with?Replies will vary from run to run and from model to model. If one test fails, do not rewrite everything. Change one line of the instruction, run the same questions again and see whether the failure moved. Keep a note of the questions you use; in lesson 6 they become your test list.
Reusable prompt
Instruction reviewer
Ask an assistant to critique a system instruction for gaps before you test it.
Review this system instruction for a bookshop customer helper. List any vague rules, missing boundaries or conflicting lines. For each issue, suggest a clearer rewrite of that line only. Do not rewrite the whole instruction.
[paste your instruction here]Show the reusable template
Replace each {{placeholder}} with your own details.
Review this system instruction for {{assistant_description}}. List any vague rules, missing boundaries or conflicting lines. For each issue, suggest a clearer rewrite of that line only. Do not rewrite the whole instruction.
{{instruction}}Expected output and limitations
A short list of issues, each paired with a one-line rewrite. Typical findings are rules that cannot be tested, a missing instruction for unknown answers or a style rule that clashes with the example.
1. "Be friendly" is hard to test. Try: "Greet once, then answer in at most four sentences."
2. No rule covers requests for personal data. Add: "Do not ask for names, emails or addresses."Limitations to keep in mind
- A reviewing assistant can invent problems or miss real ones. You still decide, by testing.
- Suggestions are generic. Check each against your actual FAQ.
Common errors and how to fix them
The assistant forgets its role on the second question.
Why it happens: system_instruction was only passed on the first request.
Fix: Pass it on every create call. The documentation says it applies only to the interaction where it is set.
ImportError: cannot import name FAQ_ENTRIES from store_data.
Why it happens: A typing error in the data file's variable name, or the file is saved in a different folder.
Fix: Make sure store_data.py is next to agent.py and the names match exactly, including capitals.
The assistant invents a loyalty scheme or a policy.
Why it happens: The instruction does not say what to do when the answer is missing, or the guidance conflicts with a friendly style line.
Fix: Add or strengthen the "say you do not know" boundary, then retest. If it still invents, treat the instruction as guidance only and rely on checks in your code.
Replies ignore the four-sentence limit.
Why it happens: The limit is stated once and buried among long text.
Fix: Put style rules in their own short block, as above, and test several questions. Model compliance is likely, not guaranteed.
The FAQ text shows odd line breaks or missing answers.
Why it happens: Python string pieces were joined without newline characters.
Fix: Print SYSTEM_INSTRUCTION once while developing, and read it as the model would.
Validation checklist
Tick each item once you have confirmed it.
Hands-on exercise
Add a new FAQ and a new boundary
Add one FAQ entry of your own to store_data.py, such as a book-signing event notice, and add one boundary to the instruction, such as never promising a delivery date. Write three test questions that check each change.
You will need
- Your store_data.py and agent.py.
- The test table above for ideas.
Acceptance criteria
Your work is done when every one of these is true.
Hints (2)
- Edit only FAQ_ENTRIES for the new fact.
- Ask: Can you guarantee my book arrives on Friday?
Show a model answer
A good answer appends an entry to FAQ_ENTRIES and one bullet under BOUNDARIES, for example: never promise a delivery date, only quote the usual delivery time. The tests check the new fact, the refusal to guarantee and a question that is still unrelated. If the assistant promises a date, the boundary needs to be clearer or placed closer to the delivery FAQ.
Knowledge check
Choose an answer, then check it. Nothing is recorded — this is for you.
Show the answer and explanation
Answer: B. Google's Interactions documentation says only inputs and outputs carry over between chained turns. The first option is wrong: the SDK would run, but the assistant would lose its guidance.
Show the answer and explanation
Answer: B. You can count sentences. Be friendly feels reasonable but cannot be marked pass or fail, so it does little to improve consistency.
Show the answer and explanation
Answer: B. The boundary says not to guess. The first option sounds helpful but invents a policy, and the third collects personal data the instruction told it not to ask for.
Show the answer and explanation
Answer: B. Instructions make behaviour likely, not certain. The first option is tempting because the word system sounds authoritative, but nothing in the API enforces it.
- Written by
- PromptFable Editorial
- Last updated 13 Nov 2026
- Review
- Reviewed by Waseem Nadir, Technical Reviewer
- Last reviewed 27 Nov 2026
References
Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.
- Interactions API overview(opens in a new tab)
Google · Official documentation · Describes system_instruction and which settings carry over between turns.
- Gemini API documentation home(opens in a new tab)
Google · Official documentation
- OWASP Top 10 for LLM Applications(opens in a new tab)
OWASP · Official documentation · See the entries on prompt injection and overreliance.
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.