System Prompts & Persistent Instructions
Knowledge
System Prompts are the invisible foundation of every LLM application. They define the behavior, personality, and boundaries of a model -- before the user even types anything. In the beginner course, you learned what a System Prompt is. Now you'll learn how to craft one professionally.
Anatomy of a Good System Prompt
A professional System Prompt has clear sections:
IDENTITY:
You are [Name/Role]. You work for [Context].
TASK:
Your primary task is [primary task].
BEHAVIOR:
- Always respond in [language/tone]
- Use [format specifications]
- Ask for clarification when [condition]
CONSTRAINTS:
- Do NOT [prohibition 1]
- Do NOT [prohibition 2]
- If [situation], then [reaction]
EXAMPLES:
User: [Example input]
You: [Example output]
Assembled Prompt
You are an experienced marketing expert, Create a social media post, for a sustainable fashion startup, target audience ages 25-35, Maximum 280 characters, with 3 relevant hashtags.
Hover or clickTap a building block to see the explanation
Best Practices
1. Prioritization through ordering: LLMs give more weight to earlier instructions. Place the most important rules at the beginning.
2. Positive instead of negative phrasing: Instead of "Don't make up facts," prefer "Only respond with information you can derive from the given context. If you're unsure, say so."
3. Escalation rules: Define what should happen in unexpected situations: "If you cannot answer the question, refer to human support."
4. Few, clear rules: 10 precise rules are better than 50 vague ones. Too many rules cause the LLM to misjudge priorities.
Understand
CLAUDE.md and agents.md -- Persistent Prompts for Developers
In practice, you often work with AI coding tools like Claude Code, Cursor, or GitHub Copilot. These tools use persistent instruction files that function like System Prompts:
CLAUDE.md: A file in the project root that Claude Code reads automatically on every invocation. It contains project conventions, architectural decisions, and behavioral rules:
# Project Rules
## Technology
- Framework: Next.js 15 with App Router
- Styling: Tailwind CSS
- Language: TypeScript strict mode
## Conventions
- All components as named exports
- Tests with Vitest and Testing Library
- Commit messages in English
## Prohibitions
- No "any" types
- No CSS-in-JS libraries
- No console.log in production code
agents.md: Defines the behavior of AI agents in multi-agent systems. Each agent receives its own instructions, responsibilities, and boundaries.
These files are essentially System Prompts for developer workflows -- and the same best practices apply: clear, structured, prioritized.
Reliably Steering Behavior
The biggest challenge with System Prompts is consistency. Over longer conversations, an LLM sometimes "forgets" its instructions. Strategies to counter this:
- Repetition: Place important rules both at the beginning and the end of the System Prompt.
- Precedents: Show examples of correct refusals in the System Prompt.
- Sentinel checks: Include verification instructions like "Before you respond, check whether your answer complies with all rules."
- Structured outputs: Enforce a specific output format (e.g., JSON) that can be automatically validated.
You're building a FAQ bot for a bank. Which System Prompt strategy is most important?
Apply
Write a System Prompt for one of the following scenarios:
- HR Bot: Answers questions about company policies but must not provide salary information
- Code Review Assistant: Reviews code for best practices, gives constructive feedback
- Learning Tutor: Explains concepts but doesn't give the solution directly
Use the sections: Identity, Task, Behavior, Constraints, Examples.
Reflect
System Prompts are the invisible contract between you and the LLM. The clearer this contract is formulated, the more reliable the behavior. But never forget: a System Prompt is not a security guarantee -- it's a guardrail that must be combined with the right defense measures (Prompt Injection).