Guide

How to Build an AI Assistant Inside Your SaaS Product (Not Just a Chatbot)

By Zain Ul Hassan · Published · Updated · 10 min read

Top Rated on Upwork100% Job Success4+ years

An AI assistant for SaaS is a chat panel inside your product that knows how your features work, can look at the signed-in user's own workspace, and can take a few safe actions for them. A generic chatbot can answer from your help center, but it cannot tell a user why their integration stopped syncing or open a support request with the right context attached. This guide covers the architecture I use with Next.js and Supabase, how to ground answers in your own product knowledge, how to give the assistant data access without leaking it, and the order I would build it in.

On this page
  1. Chatbot vs AI agent vs in-app assistant
  2. What an in-app AI assistant should actually do
  3. AI assistant for SaaS: architecture that works in production
  4. Teach it your product, not the internet
  5. Tools and actions: letting the AI do things safely
  6. Security mistakes to avoid
  7. A realistic build order
  8. A real example: LENA in LeadsMind
  9. FAQ

Chatbot vs AI agent vs in-app assistant

These terms get used interchangeably, but they describe different levels of access, and access decides the work and the risk.

TypeWhat it doesData it can reachActions it can takeRisk level
ChatbotAnswers questions from a script or a help centerPublic docs and FAQsNone, beyond linking to a pageLow: the worst case is a wrong answer
AI agentPlans multi-step tasks and calls tools until a goal is metWhatever its tools expose, often broadMany, sometimes chained without reviewHigh, unless every tool is tightly scoped
In-app assistantAnswers product questions and helps inside the user's own workspaceProduct knowledge plus the signed-in user's data, through permission checksA small set of named actions, with writes confirmed by the userMedium, and under your control

The difference between a chatbot and an AI agent is autonomy: a chatbot responds, while an agent decides what to do next and does it. An in-app assistant sits deliberately in between. It uses tools like an agent, but the tools are few, narrow and owned by your product. When founders ask me for a SaaS AI copilot, this is usually what they need.

If you only need answers from your content, that is custom AI chatbot development. Assistants that work with live product data fall under my work as an AI developer for SaaS products.

Related reading: if your customers should reach the assistant on WhatsApp, see Meta Business Agent vs a custom WhatsApp AI agent.

What an in-app AI assistant should actually do

Start from the support requests you already get. Most fall into four jobs a useful AI product assistant should cover.

Answer product questions

How do I connect my calendar? Why can't my teammate see this report? The assistant should answer in your product's own terms, link to the right screen, and never describe features you do not have.

Diagnose problems in the user's own workspace

This is where an in-app AI assistant beats a help center. Instead of listing every reason an integration might fail, it checks this user's integration, sees that the connection expired, and says so. Diagnostics are read-only: the assistant inspects, explains and suggests a fix, but changes nothing.

Take safe, well-defined actions

Contacting support with the conversation attached, booking a meeting with your team, or preparing a draft the user reviews. Each action is a named function with narrow inputs, not open access to your API.

Hand off to a human

An AI customer support agent that cannot escalate becomes a wall. When it is unsure, or the request touches billing or account deletion, it should offer a person and pass along what it already learned.

AI assistant for SaaS: architecture that works in production

The important property is where trust sits: on the server and in the database, not in the model.

Architecture of an in-app AI assistant for a SaaS product The signed-in user types in a chat panel in the Next.js app. The app sends the message to an assistant API route on the server, which checks authentication, loads the user's workspace and applies rate limits. The route calls three things: retrieval over a knowledge store of product docs and feature notes, the LLM API, and a set of tools. Tools run permission checks and write an audit log, then query Postgres as the signed-in user, where row level security filters every row to that user's own workspace. User signed in to a workspace Your app Next.js chat panel Assistant API route auth, workspace, rate limits Retrieval relevant passages for this question LLM API OpenAI or Claude; no keys, no database access Tools permission check and audit log on every call runs as the user Knowledge store product docs and feature notes, embedded (pgvector) Postgres with RLS rows filtered to the user's own workspace
Request flow for an in-app assistant: the API route owns authentication and calls retrieval, the model and tools; tools reach the database only as the signed-in user, under row level security.

Here is what each part does, in the order a message travels:

  • User and app. The chat panel in your Next.js frontend sends the message and a conversation ID. User and workspace IDs come from the session, never from the browser.
  • Assistant API route. A server route that authenticates the request, loads the user's workspace and role, applies rate limits and runs the conversation loop. Everything sensitive happens here.
  • Retrieval over product knowledge. Your docs and feature notes, stored as embeddings (pgvector in Supabase works well). The route pulls the passages that match the question.
  • Tools. Server functions the model can ask to run, such as checking an integration's status or contacting support. The model only requests a call; your code decides whether it runs.
  • Database with row level security. Tools query Postgres as the signed-in user, so RLS policies limit every row to their own workspace, even if a tool has a bug.
  • LLM. The model, from OpenAI or Anthropic, receives instructions, retrieved passages and tool results, and writes the reply. It holds no credentials and has no direct database access.

The model is the least privileged part of the system. Everything else follows from that.

Teach it your product, not the internet

A general model knows a lot about software and nothing about yours. Ask it how your export feature works and it will describe a plausible export feature, confidently. Grounding fixes that by giving the model your own material at the moment it answers.

There are two ways to do it. Prompt-only means putting product knowledge directly in the system prompt. It works for a small product and is the fastest route to a prototype. Retrieval means storing knowledge as searchable chunks and sending only the relevant ones with each question. It scales, keeps prompts short, and updates without a deploy. I walk through the retrieval side step by step in how to build a RAG chatbot with OpenAI and pgvector.

The knowledge matters more than the technique. I usually add short feature notes alongside the help center: what each feature does, its limits, which plan includes it, and the common reasons it fails. Those notes become the assistant's source of truth.

  • Keep it current. Re-embed a document whenever it changes.
  • Cite the source. Link each answer to the doc or settings screen it came from, so users can check it.
  • Make "I don't know" acceptable. Instruct the model to say when the retrieved passages do not cover the question, then offer support.
  • Test with real questions. Keep a list of questions from real support requests with expected answers, and rerun it after every change to prompts, content or models.

Tools and actions: letting the AI do things safely

Tool calling lets the model ask your code to do something. It returns the name of a function and the arguments it wants; your server decides whether to run it and sends the result back. The model never executes anything itself, and that gap between asking and running is where your safety lives.

  • Read-only first. Ship lookups before writes. A tool that reads integration status is useful on day one and cannot damage anything.
  • Check permissions on every call. Run the tool as the signed-in user, confirm they belong to the workspace and have the right role, and ignore any user or workspace ID the model supplies.
  • Confirm before writes. For anything that changes data or contacts someone, the assistant proposes the action and the user confirms it with a real button in your UI, not with the model's reading of "yes".
  • Log every call. Record the user, workspace, tool, arguments, result and time, for debugging, support and security reviews.

Illustrative example, not production code. A minimal read-only tool in TypeScript, with the workspace check done on the server from the session rather than from anything the model sends:

// Illustrative example only, not production code.
import type { SupabaseClient } from "@supabase/supabase-js";
import { z } from "zod";
import { logToolCall } from "./audit"; // your own audit-log helper

// What the model sees: a name, a description and narrow parameters.
export const getIntegrationStatus = {
  name: "get_integration_status",
  description: "Read the connection status of one integration in the user's current workspace.",
  parameters: z.object({ integration: z.enum(["calendar", "email", "payments"]) }),
};

// Built on the server from the session, never from the model's arguments.
type Ctx = { supabase: SupabaseClient; userId: string; workspaceId: string };

export async function handleGetIntegrationStatus(args: unknown, ctx: Ctx) {
  const { integration } = getIntegrationStatus.parameters.parse(args);

  const { data: member } = await ctx.supabase
    .from("workspace_members")
    .select("role")
    .eq("workspace_id", ctx.workspaceId)
    .eq("user_id", ctx.userId)
    .maybeSingle();
  if (!member) return { error: "You do not have access to this workspace." };

  // The client uses the user's session, so RLS also filters this query.
  const { data } = await ctx.supabase
    .from("integrations")
    .select("status, last_synced_at, last_error")
    .eq("workspace_id", ctx.workspaceId)
    .eq("provider", integration)
    .maybeSingle();

  await logToolCall(ctx, "get_integration_status", { integration });
  return data ?? { status: "not_connected" };
}

The parameters are a narrow list of allowed values, so the model cannot ask for arbitrary tables. And because the Supabase client uses the user's session, the membership check is a second layer; row level security is the first.

Security mistakes to avoid

Most AI security problems in SaaS are ordinary access-control problems with a new entry point. These are the ones I check first when I review an assistant.

  • Tenant isolation enforced only in code. If the assistant's queries use a service-role key that bypasses row level security, one missed filter shows a user another customer's records. Query as the user and let RLS hold the boundary. The common policy gaps are in Supabase RLS mistakes that leak customer data, and an RLS review is part of my Supabase developer and security audit work.
  • Prompt injection from user data. The assistant reads text that users and outsiders wrote: contact notes, email bodies, form submissions. Any of it can contain instructions aimed at the model. Treat retrieved and tool-returned content as data, keep write tools behind user confirmation, and never let content decide which tools run.
  • Leaking other customers' data through shared knowledge. If you embed support conversations or customer content alongside your docs, scope every chunk to its workspace. Product docs can be shared across customers; customer content cannot.
  • Over-broad tool permissions. A generic "run SQL" or "call any endpoint" tool turns the model into an admin. Give each tool one job and the narrowest inputs it needs.
  • Secrets in prompts. API keys, internal URLs and other customers' names do not belong in the system prompt. Assume users can get the model to repeat it.

These are also good interview questions. If you are deciding who should build this, my guide on how to hire an AI developer for a SaaS product covers the rest of what to ask.

A realistic build order

Shipping everything at once is how assistants end up useless or risky. Each stage is useful on its own and earns the trust the next one needs.

  1. v1: Answer questions. Retrieval over your docs and feature notes, citations, an "I don't know" path and a link to support, with no access to user data. The lightest engineering stage; most of the effort goes into writing and testing the knowledge, not the code.
  2. v2: Diagnostics. Read-only tools that inspect the user's workspace: integration status, failed jobs, missing settings. Moderate effort, mostly in permission checks and in deciding what a useful diagnosis says.
  3. v3: Actions. A few write tools behind confirmation, starting with low-stakes ones such as contacting support or booking a meeting. More effort, because the confirmation UI, audit logging and failure handling all have to be solid.
  4. v4: Analytics and feedback. Track unanswered questions, ratings and escalations. Unanswered questions show which docs to write next.

If you want to add AI to an existing SaaS, v1 usually fits your current stack without schema changes. If the product is still being built, plan the workspace model and row level security with an assistant in mind from the start; it is the same groundwork I put in place for SaaS MVP development.

A real example: LENA in LeadsMind

I built LENA, the in-product assistant for LeadsMind, an all-in-one CRM, LMS and marketing platform. LENA is trained on the platform's features, so it answers product questions in LeadsMind's own terms and helps users troubleshoot when something is not working. It can also scan a workspace for issues, and it includes Contact support and Book a meeting actions, so a user who needs a person can reach one without leaving the chat.

The full build, including the multi-tenant platform LENA runs inside, is in the LeadsMind CRM and LMS case study.

FAQ

What is the difference between a chatbot and an AI agent?

A chatbot answers questions, usually from a fixed body of content. An AI agent decides on steps and calls tools to complete a task. An in-app assistant uses tools like an agent, but only a few narrow ones that run with the signed-in user's own permissions.

How long does it take to add an AI assistant to a SaaS product?

It depends on scope. Answering questions from your docs is the smallest piece of work; diagnostics and actions each add permission checks and testing. Start with questions and answers, then add tools.

What stack should I use to build an AI assistant for my SaaS?

Next.js for the chat interface and the server route that runs the conversation, Supabase for Postgres, authentication and row level security, an LLM API such as OpenAI or Claude, and vector search with pgvector for retrieval over your product knowledge.

How do I give an AI assistant access to product data without leaking it?

Run every query as the signed-in user so row level security limits results to their workspace, take user and workspace IDs from the session rather than the model, keep tools narrow and read-only by default, and require the user to confirm any write.

Do I need to fine-tune a model for my product?

Usually not first. Retrieval over your own docs gives accurate, current answers and is updated by editing content. Fine-tuning can help with tone or format later, but it is not a reliable way to teach a model facts about your product.

How do I hire someone to build an AI assistant into my SaaS?

Look for someone who has shipped AI features inside a real multi-tenant product, not only a demo. Ask how they would enforce permissions on tool calls, how they would ground answers in your content, and what they would build first.

Sources

Keep reading

Related service, case study and articles

Need an AI assistant built into your product?

I build in-app assistants on Next.js and Supabase, from grounded answers to permission-checked actions. Tell me about your product and I will suggest what to build first.

Prefer to write a full brief? Use the hire page.

Book a 30-min callBook a call