How to Configure Vercel AI SDK Supabase Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up vercel ai sdk supabase read only access by creating a new Postgres user with select privileges. Then you pass that user key to the database tool inside your AI app. Many teams start by using the default admin password from project creation. That choice gives an AI model full power to change or delete production tables. A dedicated read role stops the model from writing or dropping data. How vercel ai sdk supabase read only access works The AI SDK runs tool calls when a language mod

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up vercel ai sdk supabase read only access by creating a new Postgres user with select privileges. Then you pass that user key to the database tool inside your AI app. Many teams start by using the default admin password from project creation. That choice gives an AI model full power to change or delete production tables. A dedicated read role stops the model from writing or dropping data.

How vercel ai sdk supabase read only access works

The AI SDK runs tool calls when a language model needs fresh facts. Your app defines a tool that accepts a query or filter from the model. That tool opens a database session and runs the query against your project.

Every Supabase project starts with a default postgres role that holds admin rights. Supabase does not grant full superuser status because that allows destructive database actions. Even so, the default postgres role can still alter schemas and delete rows. Supabase states that you should never share this default password with external services. Instead, you should make a separate database user for every service you run.

To lock down your AI tool, you create a dedicated role for the app. You grant this role usage on the target schema and select rights on specific tables. When the AI SDK calls its query tool, it logs in as this restricted user. Postgres checks the role rules before it runs any query from the model. If the model tries to insert, update, or drop a table, Postgres blocks the command.

What native roles solve and what they leave open

A dedicated Postgres read role stops write queries at the database engine level. It ensures that a bad prompt cannot delete rows or change table structures. It also separates your AI app traffic from queries run in the project dashboard. Dashboard queries run as the default postgres admin role and carry a dashboard source comment.

Still, database roles only check who logs in and which tables they can read. Once a role has select access on a table, it can read every column and row by default. A model with read access to a customer table can still pull sensitive fields. Returned rows might hold emails, phone numbers, card numbers, or national IDs. Those raw values flow right into the model context and out to the user.

Auditor Read-Only Access + AI Model Access Control: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Native role rules also do not inspect individual queries in flight. A read role cannot stop an AI tool from running a slow full-table scan. It also does not tie each database query back to a specific team member or prompt. Teams still need a way to inspect queries and mask sensitive fields in results.

How to scope table rules for AI tools

Start by listing the exact tables your AI app needs to answer user questions. Do not grant schema-wide read access if the tool only needs two tables. Create a dedicated role just for the AI SDK service. Grant select access only on the safe tables that hold public or non-sensitive data.

If a needed table holds private columns, do not expose the whole table to the role. Keep user emails, phone numbers, card numbers, and national IDs out of reach. Test the new role by running a write query and a blocked table read. Confirm that Postgres rejects both actions before you deploy your AI app.

Run guardrails and masking on the Postgres connection

Role grants and firewall rules are needed setup. Setup alone cannot check single SQL statements or mask sensitive rows in a response. By design, hoop.dev is an open-source proxy that sits beside Postgres, RDS, or Aurora as a sidecar for your Postgres. Clients and agent tools keep their credentials and point their connection string at the listener.

On each query, hoop.dev guardrails refuse disallowed drops, deletes, or table reads before they run. Next, hoop.dev data masking rewrites sensitive fields in returned rows that match your rules. Furthermore, hoop.dev holds SOC 2 Type II and logs every statement and verdict per resource. Check out the project on GitHub.

Frequently asked questions

Why should I avoid using the default postgres role for AI tools?

The default postgres role has admin rights across your database. Supabase warns against sharing this password and advises creating a separate user per service.

Does a read-only role hide sensitive columns inside a table?

No, standard table select grants let the role read every column in that table by default. Without field masking or column limits, queries return emails, phone numbers, and card numbers.

Can the AI model still slow down the database with read-only access?

Yes, a read-only role can still run heavy joins or large table scans. Role rules check table permissions at login, not query cost in flight.

The query runs. The emails stay hidden.