HomeBlogHow to Build a Custom AI...

Engineering Guide · 8 min read · October 26, 2026

How to Build a Custom AI Chatbot for Your Business Website

Generic website chat widgets either irritate visitors with rigid decision trees or hallucinate fake pricing when left ungrounded. Here is how to build a custom AI chatbot backed by your own verified pages, pgvector search, deterministic lead handoff, and abuse controls.

Author
Smit Desai
Published
October 26, 2026
Read time
8 min read
Topic
AI & Agents
Services
Custom Web · Mobile Apps · All Services

Visitors land on a business website with specific questions: Do you support HIPAA compliance? What is the minimum order quantity? Can your platform integrate with our ERP? When they cannot find an immediate answer, they leave—or open a live chat widget that traps them in a five-step form before saying nobody is online.

At the same time, slapping an ungrounded ChatGPT wrapper onto your site creates a bigger headache: a bot that confidently quotes an outdated discount or invents a service tier you do not offer. A production business chatbot has one job—answer accurately from your verified facts and hand qualified buyers cleanly to your sales or support team.

Here is how to architect a custom, grounded AI chatbot for your business website without unnecessary third-party bloat.


Off-the-Shelf Chat Widget vs. Custom Grounded Chatbot

Before writing code, confirm that a custom build fits your operational needs better than a plug-and-play widget:

Criterion Off-the-Shelf Widget Custom Website AI Chatbot
Knowledge Sync Periodic sitemap crawl (often stale) Webhook-triggered re-indexing on CMS/product updates
Live Data Lookups Limited or requires brittle Zapier chains Direct read-only queries to pricing, stock, or booking slots
Lead Handoff Trapped in vendor inbox or basic email forward Direct write to your CRM + full transcript + intent tags
Cost at Scale Per-seat + per-resolution SaaS markups Raw LLM token cost + existing server compute
Security & Privacy Third-party script & data residency Full control over PII stripping, rate limits, and logs

If your site only needs a static FAQ popup, an off-the-shelf tool may suffice. The moment you need live catalog answers, CRM lead routing, or strict brand control, a custom implementation pays for itself.


Step 1: Curate and Chunk Verified Source Content

A chatbot is only as reliable as the text you feed it. Never blindly scrape every URL on your domain—old blog drafts, expired promotions, and legal boilerplate pollute retrieval quality.

Maintain an explicit allowlist of canonical sources (service pages, pricing tables, technical docs, approved PDFs), strip navigation chrome, and split content into 350–500 token chunks preserving section headings so each chunk carries context. Keeping source pages accurate and genuinely useful also aligns with Google's helpful content fundamentals—clean documentation serves both search visitors and retrieval pipelines.

Storing Chunks and Embeddings in PostgreSQL (pgvector)

For most business websites, spinning up a separate vector database adds operational overhead you do not need. PostgreSQL with pgvector keeps embeddings alongside canonical URLs and update timestamps:

CREATE EXTENSION IF NOT EXISTS vector;

CREATE TABLE knowledge_chunks (
    id BIGSERIAL PRIMARY KEY,
    source_url TEXT NOT NULL,
    section_title TEXT NOT NULL,
    content TEXT NOT NULL,
    content_hash CHAR(64) NOT NULL,
    embedding VECTOR(1536) NOT NULL,
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_knowledge_embedding
    ON knowledge_chunks USING hnsw (embedding vector_cosine_ops);

Storing content_hash ensures your ingestion script only re-embeds pages that actually changed, cutting indexing costs to near zero.


Step 2: Hybrid Retrieval and Strict Citation Rules

Semantic vector search alone sometimes misses exact SKUs, error codes, or brand acronyms. Combine cosine similarity with PostgreSQL full-text search (tsvector), retrieve the top 4–6 chunks, and pass them to the LLM with explicit grounding rules:

  1. Answer only using facts present in the retrieved source blocks.
  2. Include the matching source_url for claims about pricing, timelines, or specifications.
  3. If the context does not contain the answer, state clearly what is missing and offer a direct handoff option—never guess.
SELECT
    source_url,
    section_title,
    content,
    1 - (embedding <=> $1::vector) AS similarity
FROM knowledge_chunks
WHERE 1 - (embedding <=> $1::vector) > 0.72
ORDER BY embedding <=> $1::vector
LIMIT 5;

Enforcing a minimum similarity threshold (such as 0.72, calibrated against your own test queries) stops unrelated chunks from sneaking into the prompt when a visitor asks something completely off-topic.


Step 3: Deterministic Lead Capture and Human Handoff

Visitors rarely want to repeat their entire question to a human after chatting with a bot. Give the assistant a structured tool—validated via JSON Schema—to submit a clean lead or support escalation payload straight into your CRM or Slack channel when intent is detected:

{
  "intent": "project_inquiry",
  "visitor_name": "Sample Buyer",
  "work_email": "buyer@company.example",
  "summary": "Needs custom B2B portal integration with existing PostgreSQL inventory database.",
  "recommended_next_step": "Schedule 20-minute technical scoping call",
  "transcript_id": "chat_94f1c2"
}

Keep this action explicit: show the visitor a confirmation card ("Send these details to our team?") or trigger it only after they submit their email in a dedicated form field inside the chat UI. Never silently post unverified guest details into production workflows.


Step 4: Public Widget Defenses Against Abuse and Prompt Injection

A public website chatbot is exposed to anonymous internet traffic 24/7. Without basic hardening, automated bots can drain your OpenAI credits overnight or trick your widget into outputting off-brand content—classic failure modes documented in the OWASP Top 10 for Large Language Model Applications.

Four Essential Public-Endpoint Controls

  • Per-IP and session rate limits: Cap anonymous visitors at something reasonable (e.g., 15 messages per 10 minutes and a 500-character input limit per message) using Redis sliding windows.
  • System prompt isolation: Keep operational rules server-side and treat visitor input strictly as user content—never concatenate raw query strings into system instructions.
  • No sensitive write tools: Anonymous website visitors should only trigger read-only retrieval and validated lead-submission forms, never account lookups or database mutations.
  • XSS-safe rendering: Render bot responses through a strict Markdown sanitizer that strips raw HTML tags and javascript: links.

Launching a Grounded Business Chatbot with SmitDev

Whether you are upgrading an existing web platform or launching a new digital storefront—from 7-day business websites at $399 flat to full custom web application development and AI agent systems—I build grounded chatbots that connect cleanly to your data and CRM without ongoing SaaS lock-in.

With 170+ shipped case studies since 2017—detailed across our engineering case studies—you can bring me in for focused $55/day senior sprints (8–9 hours daily) or $1,999/month dedicated delivery. Send over your website URL and key customer questions, and we will scope a clean, abuse-proof chatbot tailored to your buyers.

Written by Smit Desai · Principal Full-Stack & FDSE

8+ years shipping production systems · 171 case studies · 300+ WordPress servers managed for Finland partners.

Next Steps and Recommended Resources

Next Steps · Recommended Resources

Pillar 1 · Agentic Engineering

AI Agents & Automation Consulting

Deploy schema-validated AI agents, RAG pipelines, and CRM/support automation with predictable token and latency budgets.

Interactive Tool · Scope & Budget

SaaS & AI Cost Calculator

Estimate development timeline, MVP phases, and build costs across $55/day sprints or $1,999/month dedicated delivery.

01 — Frequently asked questions

ai & agents

Why build a custom website chatbot instead of embedding a generic SaaS widget?

Generic widgets lock your lead data inside third-party dashboards, struggle with live inventory or pricing rules, and charge per-seat or per-resolution markups. A custom chatbot connects directly to your database, CRM, and booking calendar while keeping full control over citations and tone.

How do you stop a business chatbot from inventing prices or policies?

Use Retrieval-Augmented Generation (RAG) scoped strictly to approved pages and product tables, enforce low temperature (0.0–0.2), require inline source links, and instruct the model to reply with a clear fallback and human handoff whenever context chunks lack the answer.

Do we need a separate vector database like Pinecone for a business website?

Usually not. For most business websites with hundreds or tens of thousands of documentation and product chunks, PostgreSQL with the pgvector extension handles hybrid keyword and semantic retrieval inside your existing database with zero extra infrastructure.

How fast and affordable is it to build a custom website chatbot with SmitDev?

Focused business websites launch in 7 days for $399 flat, while custom AI chatbots and CRM-integrated assistants are delivered via $55/day senior sprints (8–9 hours daily) or $1,999/month dedicated engineering.

03 — Have an engineering need?

hire the right expertise

Let's talk tech.

Deciding between an embedded forward deployed engineer or a senior full stack developer? Share your technical context and timeline.

Solitaire Corporate Park, Makarba, Ahmedabad, Gujarat 380015, India · IST (UTC+5:30) · --:-- IST · Mon–Fri 09:00–18:00 IST · US & EU overlap daily

No newsletter, no CRM. Just a reply.