Best Way to Add an AI Assistant to a Lovable, Bolt or Replit App That Reads Your Supabase Data
Learn how to add an AI assistant to a Lovable, Bolt or Replit app that reads Supabase data without exposing your service role key. Use scoped routes and typed answers with Claix.
Claix · Updated November 2026. Related guides: safe Supabase access for AI agents, stop agents leaking customer data, and database permissions checklist. Product: Claix Retrieve and Claix Guard.
Lovable, Bolt and Replit make it easy to build an app. Supabase makes it easy to add a database. The next step is often the same: “Can we add an AI assistant that answers questions about the data?”
That is where teams get stuck. The quick path is to give the assistant a Supabase key. The safe path is to give it a scoped retrieval layer.
Why the service role key is a bad idea
The Supabase service role key bypasses row-level security. If you give it to an AI assistant, the assistant can read and write anything the key allows. That is a large blast radius.
A prompt is not a permission model. If the assistant is influenced by a malicious input, the key is still there.
What the assistant actually needs
An assistant inside an app usually needs to answer questions like:
- How many orders does this customer have?
- What is the status of this order?
- Is this subscription active?
- What is the current balance?
- Is this user eligible for a refund?
It does not need access to every table. It does not need the service role key.
The safer architecture
A practical setup has four parts:
| Part | What it does |
|---|---|
| Your app | Sends the question and the user context |
| Claix Retrieve | Answers within a scoped boundary |
| Claix Guard | Checks writes before they run |
| Supabase | Stores the data |
Claix Retrieve controls what the assistant can read. Claix Guard controls what it can change.
Step 1: Create a Claix route
A route specifies:
- Which tables the assistant can access.
- Which columns it can retrieve.
- A guide with your rules and vocabulary.
You create a route once and attach it to as many agents as you need. For an app assistant, that might mean orders, customers, subscriptions and invoices. It does not need access to every table.
Step 2: Create one agent per app
An agent is the identity that uses one or more routes. Each agent has:
- Its own endpoint.
- Its own business prompt.
- Its own attached routes.
- Its own response mode.
This means a support bot and an internal assistant can share the same database while seeing different data. For a Lovable, Bolt or Replit app, create one agent per app. That gives you a clear boundary and a clear audit trail.
Step 3: Call Retrieve from your app
The endpoint is:
POST https://claix.dev/retrieve/{agent_name}You send a JSON body with the questions you want answered. Each question can include an optional format.
{
"questions": [
{ "question": "How many orders does this customer have?", "format": "int" },
{ "question": "Is this subscription active?", "format": "boolean" }
]
}The response includes the answers in order and a log_id you can use in Traces.
Step 4: Pass the user context
The assistant should not decide which user it is serving. Your app should pass the user context. That context should come from your authentication system, not from a prompt.
Step 5: Add Guard for writes
If the assistant needs to write, add a guardrail. Claix Guard is a rules checker for the database changes an AI agent proposes. Before an agent runs an INSERT, UPDATE or DELETE, Guard checks it against rules you approved.
- Allow: your code can execute the statement.
- Deny: your code should not execute it, and the agent receives the reason.
Claix Guard does not execute the statement. Your own code does, using its own database credentials. Keep write credentials in your backend or Edge Function executor, not in the browser or the model prompt.
Step 6: Keep row-level security
Claix does not replace row-level security. If multiple customers share the same tables, keep RLS in Supabase. Claix explicitly recommends keeping row-level security when different people or tenants share a table.
What the assistant should not do
- Use the service role key.
- Have access to every table.
- Return sensitive columns.
- Run writes without a guardrail.
- Skip audit trails.
A practical example
Say you built a SaaS with Lovable and Supabase. You want an assistant that answers order status, subscription status, invoice status and refund eligibility. A practical setup is:
- Create a Claix route for orders, subscriptions and invoices.
- Create a Claix agent for that route.
- Call the Retrieve endpoint from your app.
- Pass the user context from your auth system.
- Add Guard before any write.
- Keep RLS in Supabase.
Common mistakes
Giving the assistant the service role key
That bypasses row-level security. It is a large blast radius.
Giving the assistant broad access
If the assistant can query every table, a prompt injection has a much larger blast radius.
Treating a prompt as a permission
A prompt can guide behavior, but it is not an enforcement mechanism.
Skipping audit trails
When something goes wrong, you need to know what the assistant requested and what came back.
Frequently asked questions
- Can I put the Supabase service role key in a Lovable or Bolt AI assistant?
- No. The service role key bypasses RLS. Use a scoped Retrieve agent for reads and keep any write credentials in a server-side executor that calls Guard first.
- Does Claix replace Supabase RLS?
- No. Keep RLS for tenant isolation. Claix adds an agent-scoped retrieval and write-check layer on top of your database controls.
- Where should user identity come from?
- From your app’s authentication system. Pass that context into the retrieval call. Do not let the prompt choose which customer the assistant is helping.
- Does Claix Guard execute SQL against Supabase?
- No. Guard returns allow or deny for proposed writes. Your backend or Edge Function executes the statement only when it is allowed.
- Do I need a separate agent for each app?
- One agent per app is a good default. It keeps routes, prompts and traces clear when Lovable, Bolt and Replit projects share the same Supabase project.
- What should the assistant be allowed to read?
- Only the tables and columns needed for the product questions: orders, subscriptions, invoices and similar. Exclude payment secrets, admin notes and other tenants’ rows.
Conclusion
Adding an AI assistant to a Lovable, Bolt or Replit app is a common next step. But the assistant should not get the service role key.
Retrieve limits and structures what the assistant can read. Guard checks proposed writes before they run. Traces make requests and decisions reviewable.
If you are building an app with Supabase, start with a scoped route, not with a key.
You might also like…
Guides · Supabase
How to Give an AI Agent Safe Access to Your Supabase Database with Claix
Guide · Alternatives
Best Alternative to the Supabase MCP Server for Production Agents
Security · Guardrails
Replit's AI Agent Deleted a Production Database During a Code Freeze: What Happened and How to Prevent It
Guides · Security
Best Way to Stop an AI Agent From Leaking Customer Data: Supabase and Postgres