Systems Library / Customer Service / How to Build an AI Product Recommendation Chatbot
Customer Service chatbots

How to Build an AI Product Recommendation Chatbot

Create a chatbot that recommends products based on customer needs.

Jay Banlasan

Jay Banlasan

The AI Systems Guy

An ai product recommendation chatbot for ecommerce acts like your best salesperson, available 24/7. I build these for stores where customers struggle to pick from a large catalog. The bot asks a few questions, understands the need, and suggests the right products with reasons why.

This is not a basic filter. The AI understands context. "Something for my dad who golfs and hates the cold" returns heated golf gloves, not just random golf gear.

What You Need Before Starting

Step 1: Structure Your Product Catalog

Load your catalog into a format the AI can reference:

import json

def load_catalog():
    with open("products.json") as f:
        return json.load(f)

# Example product structure
# {
#   "id": "SKU-001",
#   "name": "Heated Golf Gloves",
#   "category": "golf-accessories",
#   "price": 89.99,
#   "description": "Battery-powered heated gloves for cold weather golf.",
#   "tags": ["golf", "winter", "heated", "accessories"],
#   "rating": 4.7,
#   "url": "/products/heated-golf-gloves"
# }

Step 2: Build the Recommendation Engine

Use the AI model with your catalog as context and tool use for lookups:

import anthropic

client = anthropic.Anthropic()

SYSTEM_PROMPT = """You are a product recommendation assistant for [Store Name].
Your job is to understand what the customer needs and recommend 2-3 products that fit.

For each recommendation, include:
- Product name and price
- One sentence explaining WHY it fits their need
- The product URL

Ask clarifying questions if the request is vague. Keep it conversational.
Never recommend products not in the catalog.

PRODUCT CATALOG:
{catalog}"""

def get_recommendations(messages, catalog):
    response = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=600,
        system=SYSTEM_PROMPT.format(catalog=json.dumps(catalog[:100])),
        messages=messages
    )
    return response.content[0].text

Step 3: Add Guided Discovery Questions

For vague requests, the bot should ask smart narrowing questions:

DISCOVERY_PROMPT = """When a customer gives a vague request, ask ONE clarifying question.
Good examples:
- "Is this for yourself or a gift?"
- "What is your budget range?"
- "Do they prefer practical gifts or fun ones?"

Never ask more than one question at a time. Never list all options.
Pick the one question that narrows it down the most."""

Step 4: Track Recommendation Performance

Log what gets recommended and what gets clicked:

import sqlite3
from datetime import datetime

def log_recommendation(session_id, product_ids, clicked_id=None):
    conn = sqlite3.connect("recommendations.db")
    conn.execute("""
        INSERT INTO recommendation_log (session_id, products_shown, product_clicked, created_at)
        VALUES (?, ?, ?, ?)
    """, (session_id, json.dumps(product_ids), clicked_id, datetime.now().isoformat()))
    conn.commit()

Step 5: Handle Large Catalogs

If your catalog has thousands of products, pre-filter before passing to the AI:

def filter_catalog(query, catalog, max_results=20):
    """Pre-filter catalog by keyword matching before AI selection."""
    query_words = set(query.lower().split())
    scored = []
    for product in catalog:
        product_text = f"{product['name']} {product['description']} {' '.join(product['tags'])}".lower()
        score = sum(1 for word in query_words if word in product_text)
        if score > 0:
            scored.append((score, product))
    scored.sort(key=lambda x: x[0], reverse=True)
    return [p for _, p in scored[:max_results]]

What to Build Next

Connect recommendation data back to your sales analytics. Track which bot-recommended products convert to purchases. Use that data to refine the system prompt and improve recommendation quality over time.

Related Reading

Want this system built for your business?

Get a free assessment. We will map every system your business needs and show you the ROI.

Get Your Free Assessment

Related Systems