System Prompts
Setting the role
The Problem: You want AI to behave consistently with a specific personality, follow certain rules, and stay on topic. How do you set this up?
The Solution: New Employee Orientation
System prompts are instructions given to the AI at the start of a conversation that define its persona, rules, and behavior. It's like onboarding a new employee — you explain who they are, what they do, and what's off-limits. A good system prompt works together with prompt structure and helps defend against prompt injection.
Think of it like onboarding a new employee:
- 1. Identity: "You are a helpful customer service agent for Acme Corp"
- 2. Responsibilities: "Help users with product questions and orders"
- 3. Boundaries: "Don't discuss competitors or give refund policy advice"
- 4. Style: "Be friendly but professional, keep responses concise"
Key System Prompt Elements
- Role/Persona: Who is the AI pretending to be?
- Task: What is the AI supposed to do?
- Constraints: What should the AI avoid?
- Format: How should responses be structured?
Fun Fact: A well-crafted system prompt can transform generic AI into a specialized expert! Companies spend significant time optimizing system prompts — they're often the secret sauce behind AI products.
Try It Yourself!
Use the interactive example below to experiment with different system prompts and see how they change AI behavior.
🎭 System prompt is a "role" for AI. Same question, but different answers depending on the setting!
(empty)
What is recursion?
Recursion is a programming technique where a function calls itself. It is used to solve problems that can be broken down into smaller subproblems of the same type.
System prompt sets the AI's "personality": communication style, answer depth, formatting. It's the first thing the model sees — and it affects ALL subsequent responses.
System Prompt Templates
Ready-to-use templates for different use cases. Click the copy button to use them in your projects.
1. Basic Assistant
You are a helpful assistant. Answer briefly and to the point.
2. Domain Expert
You are a senior {role} with 10+ years of experience.
Respond as an expert: use professional terminology,
provide practical examples, point out potential pitfalls.3. Structured Output
You are an assistant that always responds in JSON format.
Response format:
{
"answer": "your answer",
"confidence": 0.0-1.0,
"sources": ["source1", "source2"]
}4. With Constraints
You are a support assistant for company X. Rules: - Only answer questions about company products - Do not discuss competitors - Create tickets for technical issues - Always offer to contact a manager for complex cases
5. With Behavior Examples
You are a code reviewer. Example of good review: User: "Check this code: x = x + 1" Assistant: "Can be simplified to x += 1. Also recommend adding a comment about the variable's purpose." Example of bad review (DON'T DO THIS): "Code is bad, redo it"
💡 Tip: Combine elements from different templates to create unique system prompts for your specific needs.
Try it yourself
Interactive demo of this technique
Write a welcome email to a customer — with and without a system prompt
Dear customer! Welcome to our store. We offer a wide range of products. We hope you enjoy shopping with us. Best regards, Store Team.
Hey there! We're so happy you joined us! You're now part of the SuperShop family, and shopping just got a whole lot better. Here's a little welcome gift — use promo code WELCOME10 for 10% off your first order. Don't be a stranger — reach out anytime! Warmly, Lena from SuperShop
The system prompt is the "DNA" of the response. It sets personality, tone, and rules, transforming boilerplate into a branded message.
Create a free account to solve challenges
4 AI-verified challenges for this lesson
This lesson is part of a structured LLM course.
My Learning Path