What are Prompts?
Prompts are instructions that tell your chatbot how to behave and respond. LangChat uses two types:
- System Prompt - Defines personality and behavior
- Standalone Question Prompt - Converts questions to search queries
Basic Custom Prompt
from langchat import LangChat
from langchat.llm import OpenAI
from langchat.vector_db import Pinecone
from langchat.database import Supabase
# Custom prompt
custom_prompt = """You are a helpful assistant.
Answer questions clearly and concisely.
Context: {context}
History: {chat_history}
Question: {question}
Answer:"""
# Setup
llm = OpenAI(api_key="sk-...", model="gpt-4o-mini")
vector_db = Pinecone(api_key="...", index_name="...")
db = Supabase(url="https://...", key="...")
# Use custom prompt
ai = LangChat(
llm=llm,
vector_db=vector_db,
db=db,
prompt_template=custom_prompt
)
Prompt Variables
Use these variables in your prompts:
{context} - Retrieved documents from your knowledge base
{chat_history} - Previous conversation messages
{question} - Current user question
Use single braces {variable} in prompts. LangChat handles substitution automatically.
Example Prompts
Education Assistant
EDUCATION_PROMPT = """You are an expert education consultant.
Help students find universities based on:
- Academic profile
- Preferred countries
- Budget constraints
Be friendly, professional, and concise.
Context: {context}
History: {chat_history}
Question: {question}
Answer:"""
ai = LangChat(
llm=llm,
vector_db=vector_db,
db=db,
prompt_template=EDUCATION_PROMPT
)
Customer Support
SUPPORT_PROMPT = """You are a customer support agent.
Guidelines:
- Be professional and empathetic
- Provide step-by-step solutions
- Ask clarifying questions when needed
Product Info: {context}
Previous Chat: {chat_history}
Customer Question: {question}
Response:"""
ai = LangChat(
llm=llm,
vector_db=vector_db,
db=db,
prompt_template=SUPPORT_PROMPT
)
Best Practices
1. Be Specific
# ❌ Vague
"""You are an assistant. Help users."""
# ✅ Specific
"""You are an expert education consultant specializing in study abroad programs."""
2. Include Context Instructions
"""Use the following context to answer questions:
{context}
If context doesn't contain relevant information, say so honestly."""
3. Guide Communication Style
"""Communication Style:
- Friendly and professional
- Concise and actionable
- Use emojis appropriately"""
Testing Prompts
Test your prompts with different questions:
test_questions = [
"What universities offer computer science?",
"I need help with my visa application",
"What's the deadline for fall intake?"
]
for question in test_questions:
result = await ai.chat(
query=question,
user_id="test_user"
)
print(f"Q: {question}")
print(f"A: {result['response']}\n")
Next Steps
Built with ❤️ by NeuroBrain