How to Connect Your Chatbot to Your Product Database
Why Connect a Chatbot to Your Database
A chatbot trained on static documents can answer general questions about your business, but it cannot tell a customer whether a specific product is in stock right now or what the current price is. That information changes constantly, and retraining the chatbot every time a price or inventory count changes is impractical.
By connecting the chatbot to your database, it can run queries in real time. A customer asks "do you have the blue widget in stock" and the chatbot queries your inventory table, finds the current count, and answers accurately. It can also look up order status, shipping estimates, return policies tied to specific products, and anything else stored in your database.
Step-by-Step Setup
Set up the MySQL or PostgreSQL connection. The chatbot will use the same database connection to run queries. Make sure the database user has at least SELECT access to the product-related tables.
Create or configure a chatbot in the Chatbot app. Write a system prompt that explains the chatbot's role as a product assistant. Include instructions about what kinds of questions to answer and how to format product information (pricing, availability, features).
In the chatbot configuration, enable the database lookup feature and select which database connection to use. Specify which tables the chatbot should be able to query, for example, products, inventory, pricing, and categories. This limits the chatbot to relevant tables and prevents it from accessing sensitive data like payment records.
In the chatbot's system prompt, describe your product data structure so the AI knows how to interpret results. For example: "Products are in the products table with columns: name, sku, price, category, description. Inventory is in the inventory table joined by product_id. Stock levels are in the quantity column."
Ask the chatbot questions that require database lookups: "How much does the premium plan cost?" or "Is the 32GB model available?" Verify that it queries the right tables and returns accurate, current information. Refine the system prompt if the chatbot misinterprets certain questions.
What Customers Can Ask
- Product details: "What sizes does this shirt come in?" or "What are the specs of the Pro model?"
- Pricing: "How much is the annual subscription?" or "Do you offer bulk pricing?"
- Availability: "Is this item in stock?" or "When will the blue version be available again?"
- Comparisons: "What is the difference between the Standard and Premium plans?"
- Categories: "Show me all products under $50" or "What wireless headphones do you sell?"
Combining Database Lookups With Knowledge Base
The most effective product chatbots use both approaches. The knowledge base (RAG with embeddings) handles general questions about your company, policies, and how-to guides. The database connection handles real-time data lookups for pricing, availability, and specifications. The AI decides which source to use based on the question.
For example, "what is your return policy" pulls from the knowledge base, while "is the XL size in stock" queries the database. "Tell me about the Premium widget and if it is available" might use both: knowledge base for the product description and database for the current stock level.
Give your chatbot real-time access to your product data. Customers get accurate answers instantly.
Get Started Free