System messages for behavior control

Introduction to Claude Models

Nikhil Rangarajan

Data Scientist

What are system messages?

  • Support bot
  • Requirements:
    • Polite
    • Concise
    • End every reply with "Is there anything else I can help you with today?"

A bot

Introduction to Claude Models

What are system messages?

  • System messages set global behavior rules for Claude
  • Applied to entire conversation, not just single responses
  • Control tone, constraints, output format, and persona

A bot asking “Is there anything else I can help you with today?”

Introduction to Claude Models

Writing effective system prompts

  • Be specific about behavior and constraints
  • Define the role Claude should adopt
system_msg = "Be helpful." # Weak

system_msg = "You are a technical writer. Use active voice, under 100 words, actionable advice only." # Strong
messages = [{"role": "user", "content": "How do I improve documentation?"}] response = client.messages.create(model="claude-sonnet-4-20250514", max_tokens=150, system=system_msg, messages=messages)
Introduction to Claude Models

Common system message patterns

  • Role-based: Define who Claude should be

$$

  • Constraint-based: Set limits on length or format

$$

  • Tone-based: Control emotional style

$$

  • Task-specific: Give specialized instructions
# Role-based
"You are a customer service rep."

# Constraint-based  
"Respond in exactly 3 bullet points,
max 50 words."

# Tone-based
"Use enthusiastic, encouraging tone."

# Task-specific
"Debug Python code. Always ask for 
error messages first."
Introduction to Claude Models

Testing and iterating system messages

  • Test with diverse user inputs to find edge cases
  • Monitor for undesired outputs or behavior drift
  • Refine language to be more specific when needed
# System message causing issues
"Be concise and helpful."

# Problem: Responses too short, 
# missing context
"Provide helpful responses in 2-3 
sentences. Include relevant context 
but avoid unnecessary details."

# Test with various prompts 
Introduction to Claude Models

Advanced system message techniques

$$

  • Combine instructions with clear priorities
  • Use conditional logic for scenarios
  • Include examples in system message
  • Layer with few-shot prompting
system_msg = """Code reviewer. 
Priority: 1) Security 2) Performance 
3) Style
If no issues: "Code looks good" 
+ suggest improvement
Example: "Security: No issues. 
Performance: Consider caching here."
"""

messages = [{"role": "system", 
             "content": system_msg},
    {"role": "user", 
     "content": "Review: [code]"}]
Introduction to Claude Models

Let's practice!

Introduction to Claude Models

Preparing Video For Download...