What You Will Learn
In this lesson, you will learn:
- What a system prompt is
- Why a system prompt is important
- How to add a system prompt to AI chatbot
- How a system prompt changes AI responses
Quick Answer
A System Prompt is a set of instructions given to the AI before the user asks a question. It tells the AI how to behave throughout the conversation. For example, you can tell the AI to behave like:
- A Python teacher
- A Coding Mentor
- A Career Advisor
- A Travel Guide
- A Customer Support Executive
Without a system prompt, the AI behaves like a general assistant.
What Is a System Prompt?
Imagine you hire a new teacher. Before the class starts, you tell the teacher:
“Teach beginners. Use simple English. Give examples. Don’t use difficult words.”
These instructions are given only once. After that, the teacher follows the same style for every question.
A System Prompt works in exactly the same way. It tells the AI how to answer before the conversation begins.
Our Goal
So far, your chatbot answers questions like a general AI assistant. Now let’s turn it into a Python Coding Mentor. After this lesson, even if you ask a simple question, the AI will answer like a friendly programming teacher.
Step 1: Open app.py
Open the app.py file that you created in the previous lesson. Do not create a new file. We are going to improve the same project.
Step 2: Find This Code
In Lesson 12, your code looks similar to this.
response = client.responses.create(
model="gpt-5",
input=user_message
)
Right now, the AI only receives the user’s question. It does not know what kind of assistant it should become.
Step 3: Add a System Prompt
Replace the above code with the following.
response = client.responses.create(
model="gpt-5",
instructions="""
You are a friendly Python teacher.
Explain every topic in simple English.
Keep your answers short.
Always include an example whenever possible.
""",
input=user_message
)
What Changed?
We added a new parameter.
instructions="""
...
"""
This is your System Prompt. It tells the AI:
- Be a Python teacher.
- Use simple English.
- Keep answers short.
- Give examples.
Now every response will follow these instructions.
Example 1
Ask the chatbot:
You: What is a variable?
Example response:
A variable is a container used to store data.
Example:
age = 20
Here, age stores the value 20.
Notice that the AI gives an explanation and an example because the System Prompt asked it to do that.
Example 2
Ask:
You: Explain loops.
Example response:
A loop repeats the same task multiple times.
Example:
for i in range(5):
print(i)
This code prints numbers from 0 to 4.
Again, the AI follows the instructions given in the System Prompt.
Why Is a System Prompt Important?
The System Prompt controls the behavior of your chatbot. By changing only the instructions, you can create completely different AI assistants.
For example:
Coding Mentor
You are an experienced Python teacher.
Travel Guide
You are an expert travel guide.
Interview Coach
You are a technical interviewer.
English Teacher
You are an English speaking coach.
The code stays almost the same. Only the System Prompt changes.
Complete Code
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY"
)
while True:
user_message = input("You: ")
if user_message.lower() == "exit":
print("Goodbye!")
break
response = client.responses.create(
model="gpt-5",
instructions="""
You are a friendly Python teacher.
Explain every topic in simple English.
Keep your answers short.
Always include an example whenever possible.
""",
input=user_message
)
print("\nAI:", response.output_text)
Common Mistakes
AI behaves like a general assistant
Check whether you added the instructions parameter.
Typing mistake in the System Prompt
Read the instructions carefully. Even a small mistake can change how the AI behaves.
Very Long Instructions
Keep your System Prompt simple and clear. Short instructions usually produce better results.
Key Points
- A System Prompt tells the AI how to behave.
- It is sent before the user’s question.
- You can change the chatbot’s personality without changing the main code.
- A clear System Prompt usually produces better responses.
Mini Quiz
1. What is a System Prompt?
A. A Python function
B. Instructions that tell the AI how to behave
C. A database
D. A loop
Answer: B
2. Which parameter is used to define a System Prompt?
A. prompt
B. input
C. instructions
D. message
Answer: C
3. Can you create different AI assistants by changing only the System Prompt?
A. Yes
B. No
Answer: A
4. Which assistant can you create using a System Prompt?
A. Coding Mentor
B. Travel Guide
C. English Teacher
D. All of the above
Answer: D
5. Should a System Prompt be clear and simple?
A. Yes
B. No
Answer: A
Practice Exercise
Change your System Prompt and test the chatbot. Try these examples.
Example 1
You are a Java programming teacher.
Example 2
You are a Data Analytics mentor.
Example 3
You are a Digital Marketing expert.
Ask the same question each time.
Notice how the AI changes its answers based on the System Prompt.
Lesson Summary
In this lesson, you learned how to add a System Prompt to your chatbot. A System Prompt tells the AI how to behave before the conversation starts.
By changing only a few lines of code, you can turn the same chatbot into a coding mentor, teacher, career coach, or any other type of AI assistant. This is one of the most useful techniques in AI application development.
Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.
Shubhranshu Shekhar is a coding instructor, mentor, and founder of VSIT Delhi with 20+ years of teaching experience (since 2004). He has guided many students who are now working in multinational companies and specializes in Full Stack Development, Python, Digital Marketing, and Data Analytics.
