Loading
Loading
Time to apply what you've learned! In this lesson you'll build a custom chatbot step by step. We'll work two ways: first without code for beginners, then with actual code for those interested in a real implementation.
A customer service assistant for a virtual tech store — answers customer questions about shipping, returns, and products, and escalates complex issues to human support.
You can adapt the idea to any domain: education, healthcare, tourism, HR...
Before any code, answer these questions:
| Question | Our Answer | |----------|-----------| | What's the chatbot's goal? | Customer service for a tech store | | Who are the users? | Customers wanting quick information | | Common questions? | Shipping, returns, prices | | Tone? | Friendly and professional | | Limits? | No promising discounts or special deals |
The System Prompt is the instructions that define the chatbot's identity and behavior — users don't see it.
You are "Tech Support," a customer service assistant for a virtual technology store.
Your mission: answer customer inquiries accurately and politely.
Rules:
1. Respond in the language the customer uses
2. Never promise discounts or deals not mentioned in the context
3. If you don't know the answer, say so honestly and refer to support@example.com
4. Keep responses concise (3-5 sentences)
Store information:
- Business hours: 9 AM – 11 PM daily
- Shipping: 2-5 business days, free over $50
- Return policy: 14 days from delivery date
- Human support: support@example.com
For beginners — use Claude.ai directly:
This is the fastest approach — perfect for prototyping.
For developers interested in a real implementation — the code below builds an interactive chatbot in the terminal.
Test these scenarios:
After each test, refine the System Prompt to improve responses.
Using the same logic you can build:
Building a chatbot = careful System Prompt design + repeated testing + continuous improvement. The code is simple — the real challenge is designing behavior precisely: what it does, what it doesn't do, and how it handles difficult situations.
import anthropic
client = anthropic.Anthropic(api_key="your-api-key")
SYSTEM_PROMPT = """
You are "Tech Support," a customer service assistant for a virtual technology store.
Your mission: answer customer inquiries accurately and politely.
Rules:
1. Respond in the language the customer uses
2. Never promise discounts or deals not mentioned in this context
3. If you don't know the answer, say so honestly and refer to support@example.com
4. Keep responses concise (3-5 sentences)
Store information:
- Business hours: 9 AM - 11 PM daily
- Shipping: 2-5 business days, free over $50
- Return policy: 14 days from delivery date
- Human support: support@example.com
"""
conversation_history = []
def chat(user_message: str) -> str:
conversation_history.append({
"role": "user",
"content": user_message
})
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=500,
system=SYSTEM_PROMPT,
messages=conversation_history
)
assistant_message = response.content[0].text
conversation_history.append({
"role": "assistant",
"content": assistant_message
})
return assistant_message
print("Tech Support Chatbot ready! (type 'quit' to exit)")
while True:
user_input = input("You: ")
if user_input.lower() in ["quit", "exit"]:
break
response = chat(user_input)
print(f"Bot: {response}\n")