Home » AI Databases » Chatbot Database

How to Connect Your Chatbot to Your Product Database

Connecting your chatbot to your product database lets customers ask questions about pricing, availability, specifications, and inventory, and get real-time answers pulled directly from your data. Instead of relying only on static training documents, the chatbot can look up live information in your MySQL or PostgreSQL database every time someone asks.

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

Step 1: Connect your database.
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.
Step 2: Set up your chatbot.
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).
Step 3: Enable database access in the chatbot.
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.
Step 4: Add context about your data structure.
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."
Step 5: Test with real customer questions.
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

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.

Security: The chatbot only queries tables you explicitly allow. Customer-facing chatbots should never have access to tables containing passwords, payment details, or internal business data. Use a read-only database user restricted to product-related tables.

Give your chatbot real-time access to your product data. Customers get accurate answers instantly.

Get Started Free