Back to Blog

Build AI Apps with Python: System Prompts and Personas | Episode 2

Celest KimCelest Kim

Video: Build AI Apps with Python: System Prompts and Personas | Episode 2 by Taught by Celeste AI - AI Coding Coach

Watch full page →

Build AI Apps with Python: System Prompts and Personas

System prompts allow you to control the personality and style of AI responses with a single line of code. By setting different system prompts, you can make the AI respond like a pirate, a chef, or a tutor, all answering the same question in unique ways. This technique leverages the powerful system parameter in the Claude API to customize how the AI thinks, speaks, and formats its answers.

Code

from anthropic import Anthropic

client = Anthropic(api_key="your_api_key_here")

# Define the question to ask the AI
question = "How do I make a cup of tea?"

# Define different system prompts to create distinct personas
prompts = {
  "pirate": "You are a pirate. Speak like a pirate in every response.",
  "chef": "You are a chef. Relate everything to cooking and food.",
  "tutor": "You are a tutor. Give clear, step-by-step advice."
}

for persona, system_prompt in prompts.items():
  response = client.completions.create(
    model="claude-v1",
    prompt=f"{system_prompt}\n\nHuman: {question}\n\nAssistant:",
    max_tokens_to_sample=200,
    stop_sequences=["Human:"]
  )
  print(f"--- {persona.capitalize()} Persona ---")
  print(response.completion)
  print()

Key Points

  • The system prompt sets the AI’s personality and response style in one line.
  • Using different system prompts lets you reuse the same question with varied, themed answers.
  • The Claude API’s messages.create() method accepts a system parameter to control AI behavior.
  • Personas like pirate, chef, and tutor demonstrate how tone and formatting can be customized easily.
  • Reusing variables like the question keeps your code clean and maintainable across multiple API calls.