AI / Google Antigravity Gemini Fundamentals Interview Questions
What is the Gemini API's system instruction and how does it differ from a user prompt?
The system instruction (equivalent to a system prompt) sets the model's persona, behaviour, constraints, and context before any user interaction begins. It differs from a user prompt in that it is processed separately and takes precedence in shaping the model's overall behaviour.
from google import genai from google.genai import types client = genai.Client() # generateContent with system instruction: response = client.models.generate_content( model="gemini-3.5-flash", contents="Explain recursion.", # user input config=types.GenerateContentConfig( system_instruction="You are a Python tutor for beginners. Always give examples in Python. Keep explanations under 200 words. Never use jargon without explaining it first.", ) ) print(response.text) # Interactions API with system instruction: interaction = client.interactions.create( model="gemini-3.5-flash", input="Explain recursion.", system_instruction="You are a Python tutor for beginners...", ) # Effective system instruction principles: EFFECTIVE_SYSTEM_INSTRUCTION = """ Role: You are a senior Python code reviewer at a fintech company. Constraints: - Always check for security vulnerabilities first - Flag any use of eval() or exec() as critical risk - Use Decimal for financial calculations, never float - Output in this format: Risk Level, Issues, Recommendations Tone: Professional, direct, constructive """ # System instruction vs user prompt: # System instruction: stable per session; shapes all responses; cached efficiently # User prompt: changes per turn; the actual task or question
Caching system instructions: since system instructions are typically long and repeated across many requests, they are the primary candidate for context caching. A well-structured system instruction placed in a cache can reduce per-request costs significantly for production deployments with high request volumes.
More Related questions...