Lesson 1

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.

How System Prompt Changes Behavior

🎭 System prompt is a "role" for AI. Same question, but different answers depending on the setting!

Choose a role:
System Prompt

(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.
Key Insight

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.

Frequently asked questions

What is a system prompt in LLMs?

A system prompt is an instruction block sent before the user's message that defines the AI's role, personality, constraints, and output format. It acts as persistent configuration that shapes every response the model generates.

What are best practices for writing system prompts?

Key best practices: be specific about the role and tone, set explicit constraints (what NOT to do), define output format upfront, include examples of ideal responses, and keep instructions concise — models follow shorter, clearer prompts more reliably.

Can you give examples of effective system prompts?

Common patterns include: role-based ('You are a senior Python developer reviewing code'), constrained ('Respond only in JSON with fields: answer, confidence, sources'), and behavioral ('Never make up facts. If unsure, say so. Cite sources when possible').

Try it yourself

Interactive demo of this technique

Technique Comparison
Demo Mode
Pre-recorded responses
TaskBeginnerWriting

Write a welcome email to a customer — with and without a system prompt

Without technique
Without technique
Prompt
Write a welcome email for a new online store customer.
Response

Dear customer! Welcome to our store. We offer a wide range of products. We hope you enjoy shopping with us. Best regards, Store Team.

Tokens:18/42
Time:280ms
Quality:
With Context Engineering
With technique
Prompt
[SYSTEM] You are a brand copywriter for "SuperShop". Tone: friendly, casual, with light humor. Use first-name basis. Include emojis. Sign off as: "Lena from SuperShop". Always mention promo code WELCOME10 for first purchase. [USER] Write a welcome email for a new online store customer.
Response

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

👁️System prompt sets the role, tone, and required elements
🧠Without context the model generates generic boilerplate text
Result matches the brand: tone, signature, and promo code are all present
Tokens:72/68
Time:340ms
Quality:
Why this works

The system prompt is the "DNA" of the response. It sets personality, tone, and rules, transforming boilerplate into a branded message.

1 / 2

Lesson Quiz

1 of 3

1.What is the primary role of a system prompt in an LLM conversation?

Practice Challenges

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