Systeemberichten voor gedragssturing

Introductie tot Claude-modellen

Nikhil Rangarajan

Data Scientist

Wat zijn systeemberichten?

  • Supportbot
  • Eisen:
    • Beleefd
    • Bondig
    • Eindig elk antwoord met "Is there anything else I can help you with today?"

Een bot

Introductie tot Claude-modellen

Wat zijn systeemberichten?

  • Systeemberichten zetten globale gedragsregels voor Claude
  • Gelden voor het hele gesprek, niet voor losse antwoorden
  • Sturen toon, constraints, outputformaat en persona

Een bot die vraagt: “Is there anything else I can help you with today?”

Introductie tot Claude-modellen

Effectieve systeemprompts schrijven

  • Wees specifiek over gedrag en constraints
  • Definieer de rol die Claude moet aannemen
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-6", max_tokens=150, system=system_msg, messages=messages)
Introductie tot Claude-modellen

Veelvoorkomende patronen voor systeemberichten

  • Rolgebaseerd: Bepaal wie Claude is

$$

  • Constraint-gebaseerd: Stel limieten aan lengte of formaat

$$

  • Toon-gebaseerd: Stuur emotionele stijl

$$

  • Taakspecifiek: Geef gespecialiseerde instructies
# 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."
Introductie tot Claude-modellen

Systeemberichten testen en itereren

  • Test met diverse invoer om edgecases te vinden
  • Monitor op ongewenste output of drift in gedrag
  • Verfijn taal waar nodig, wees specifieker
# 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 
Introductie tot Claude-modellen

Geavanceerde technieken voor systeemberichten

$$

  • Combineer instructies met duidelijke prioriteiten
  • Gebruik conditionele logica voor scenario’s
  • Voeg voorbeelden toe in het systeembericht
  • Stapel met 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]"}]
Introductie tot Claude-modellen

Laten we oefenen!

Introductie tot Claude-modellen

Preparing Video For Download...