Intermediate Technique

System Prompts

Set persistent behavior and constraints that guide the AI throughout a conversation

What are System Prompts?

System prompts are high-level instructions that set the overall context, persona, or behavior for an AI conversation. Unlike user prompts which change with each message, system prompts remain active throughout the entire session.

Think of it as setting the "ground rules" before a conversation begins. The system prompt tells the AI who it is, how it should respond, and what boundaries to observe.

When to Use It

Best For:

  • • Setting AI persona/tone
  • • Defining response format
  • • Establishing safety guidelines
  • • Multi-turn conversations

Not Ideal For:

  • • Single-turn queries
  • • Quick factual questions
  • • One-off tasks
  • • When persona isn't relevant

Examples

Example 1: Code Reviewer Persona
System Prompt
You are a senior software engineer with 15 years of experience. Your role is to review code for bugs, security vulnerabilities, and performance issues. Always explain issues clearly and provide specific suggestions with code examples when possible.
User Input
Review this function for issues:
def get_user(id): return db.query(id)
Output
Security Issues:
• SQL injection vulnerability - use parameterized queries
• No input validation for `id` parameter

Best Practices:
• Add type hints
• Implement error handling
• Add docstring
Example 2: Structured Output
System Prompt
You are a data extraction assistant. Always respond in valid JSON with exactly these keys: {"title": string, "date": string in YYYY-MM-DD format, "entities": string array, "summary": string under 100 words}
User Input
Extract information from this article about tech mergers...
Output
{ "title": "Tech Giants Merger Creates Industry Shift", "date": "2024-01-15", "entities": ["TechCorp", "DataFlow Inc", "Federal Trade Commission"], "summary": "Major technology companies announce merger..." }

Best Practices

  • 01
    Be specific but concise

    Include essential rules without overwhelming the model with details

  • 02
    Place key instructions early

    The model gives more weight to instructions at the beginning

  • 03
    Test and iterate

    System prompts often need refinement based on actual outputs

  • 04
    Combine with user prompts

    System prompts set context; user prompts provide specific tasks

System vs User Prompts

System prompts define persistent behavior across a session, while user prompts are task-specific. For best results, use system prompts for overall context and user prompts for immediate tasks. Some platforms combine these into a single conversation.