Menu
CoddyTech

System Prompts

Part of the Calling Models From Code section of Coddy's AI Engineering journey. Lesson 3 of 22.

A system prompt sets who the model is and the rules it follows for the whole conversation. It is not a turn in messages: it goes in its own system argument, and the model gives it more weight than anything a user writes.

response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=100,
    system="You are Rex, a museum guide. Answer in one word.",
    messages=[{"role": "user", "content": "What is the capital of Spain?"}],
)
print(response.content[0].text)

This prints Madrid.

Products use the system prompt for three things: a persona (a name and a tone), rules (length, format, what to refuse) and facts the model needs, such as opening hours. A user cannot change it, because your code writes it on every call. The stand-in follows the rules listed at the top of coddy_ai.py; a real model follows instructions written in any words.

challenge icon

Challenge

Easy

Give the cafe's assistant a name, facts and a sign-off with a system prompt.

  1. The starter reads the assistant's name and a question. CAFE_FACTS holds the facts.
  2. Build the system prompt: You are <name>, the assistant of Green Leaf Cafe., a space, CAFE_FACTS, a space and End every reply with "Have a green day!"
  3. Send the question as the only message, with that system prompt, model="claude-opus-5-5" and max_tokens=200.
  4. Print Answer: and the reply.

For example, for the input Mia and Who are you? the program prints:

Answer: I am Mia. Have a green day!

Try it yourself

import coddy_ai as anthropic  # in production: import anthropic

client = anthropic.Anthropic()

CAFE_FACTS = "The cafe opens at 8 am and closes at 4 pm. Oat milk costs 50 cents extra. Every pastry is baked here each morning."

name = input()
question = input()

# Build the system prompt, send the question with it, and print "Answer: " and the reply
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Calling Models From Code

Practice on your own: Online Python compiler