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
EasyGive the cafe's assistant a name, facts and a sign-off with a system prompt.
- The starter reads the assistant's name and a question.
CAFE_FACTSholds the facts. - Build the system prompt:
You are <name>, the assistant of Green Leaf Cafe., a space,CAFE_FACTS, a space andEnd every reply with "Have a green day!" - Send the question as the only message, with that system prompt,
model="claude-opus-5-5"andmax_tokens=200. - 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
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Calling Models From Code
1First Model Calls
Your First Model CallMessages and RolesSystem PromptsReading the ResponseRecap: Shop Help DeskPractice on your own: Online Python compiler