Pesan sistem untuk mengontrol perilaku

Pengantar Model Claude

Nikhil Rangarajan

Data Scientist

Apa itu pesan sistem?

  • Bot dukungan
  • Ketentuan:
    • Sopan
    • Ringkas
    • Akhiri tiap balasan dengan "Is there anything else I can help you with today?"

Sebuah bot

Pengantar Model Claude

Apa itu pesan sistem?

  • Pesan sistem menetapkan aturan perilaku global untuk Claude
  • Berlaku untuk seluruh percakapan, bukan satu respons saja
  • Mengatur nada, batasan, format output, dan persona

Sebuah bot bertanya “Is there anything else I can help you with today?”

Pengantar Model Claude

Menulis system prompt yang efektif

  • Spesifikkan perilaku dan batasan
  • Tentukan peran yang harus diadopsi Claude
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)
Pengantar Model Claude

Pola umum pesan sistem

  • Berbasis peran: Tentukan peran Claude

$$

  • Berbasis batasan: Atur panjang atau format

$$

  • Berbasis nada: Kendalikan gaya emosional

$$

  • Spesifik tugas: Beri instruksi khusus
# 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."
Pengantar Model Claude

Menguji dan mengiterasi pesan sistem

  • Uji dengan beragam input untuk temukan edge case
  • Pantau output tak diinginkan atau drift perilaku
  • Perjelas bahasa saat perlu lebih spesifik
# 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 
Pengantar Model Claude

Teknik lanjutan untuk pesan sistem

$$

  • Gabungkan instruksi dengan prioritas jelas
  • Gunakan logika kondisional untuk skenario
  • Sertakan contoh di pesan sistem
  • Lapisi dengan 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]"}]
Pengantar Model Claude

Ayo berlatih!

Pengantar Model Claude

Preparing Video For Download...