How to Configure Vercel AI SDK Supabase Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a vercel ai sdk supabase audit log, create a dedicated database role for your model tools and record every query it runs. You also capture tool calls inside your app handlers and write those events to a separate tracking table. Many teams start by giving their app the default postgres role to move fast. That default role has admin privileges, which creates high risk when a model runs database queries. If a prompt triggers a bad tool call, broad role rights allow unwanted changes across

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.

To set up a vercel ai sdk supabase audit log, create a dedicated database role for your model tools and record every query it runs. You also capture tool calls inside your app handlers and write those events to a separate tracking table. Many teams start by giving their app the default postgres role to move fast. That default role has admin privileges, which creates high risk when a model runs database queries. If a prompt triggers a bad tool call, broad role rights allow unwanted changes across your tables.

How to set up a vercel ai sdk supabase audit log

A good setup separates your model database user from your admin user. Every project includes a default postgres role with admin rights, though it is not a full superuser. The platform docs state that you should never share this main password with an external service. Instead, you should make a fresh database user for every service that talks to your data. This rule applies directly when your app uses model tool calls to read or write rows.

Start by creating a custom role just for your model workflow. Grant this role permission to read only the specific tables your app needs. Next, set up your app to record each step the model takes during a request. When the model decides to call a tool, your app code receives the tool inputs first. Your handler can write the user ID, timestamp, and tool inputs to an audit table before running the query.

You should also track activity inside the database itself. Queries run in the web dashboard execute as the postgres role and include a source comment. When your app connects with its own dedicated role, the database logs show that specific role name. This separation helps your team tell human dashboard queries apart from automated model queries.

What native roles and app logs leave open

Creating a separate role for your model tools is a strong first step. It stops the app from using the main admin account for daily tasks. Writing tool events from your app handlers also gives you a basic history of model actions. Your team can check this table later to see which user triggered a specific tool call.

Still, database roles only check who logs in at the start of a session. Once the role connects, the database trusts every valid query that role is allowed to run. A role cannot inspect what an individual statement does in flight before it hits the data. If a model builds a wide query on a permitted table, the database runs it right away.

AI Audit Trails + Audit Log Integrity: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Native roles also return raw table values to the app by default. If a table holds emails, phone numbers, card numbers, or national IDs, the query returns them in plain text. App-level logging also depends on developers writing tracking code inside every single tool handler. If a developer adds a new tool and forgets the logging step, that action leaves no record. Teams also have to manage and rotate the database password stored in the app settings.

Why runtime query checks matter for model tools

Model workflows act differently than standard app code with fixed queries. When a user sends a prompt, the model picks which tool to run and fills in the inputs. Even with a scoped database role, a model might ask for more rows than needed. Checking each statement right before it runs gives teams tighter control over data flow.

Data masking at the query level also helps protect sensitive fields during model runs. Masking rewrites matched fields like emails or card numbers in results before the app processes them. This keeps raw personal data out of model prompts and third-party logs while keeping the app working.

Add query and result controls beside Postgres

Grants and pools govern who logs into PostgreSQL. Yet every query in an open session still runs with that role's full scope. In practice, hoop.dev runs beside your database as a sidecar for your Postgres. It reads plain and prepared queries on the wire with no change to your users or drivers.

When a tool or agent sends SQL, hoop.dev Postgres controls check each statement against your deny rules. An AI Analyzer you configure can also score intent or hold a risky query for human review. Matched sensitive columns in result rows are masked in memory before they reach the caller. Each query and decision is logged per listener, which generates evidence for SOC 2, HIPAA, and GDPR audits. View the binary on GitHub.

Frequently asked questions

Should I use the default postgres role for my model app?

No, the default postgres role has admin privileges across your project. You should create a new database user with limited table permissions for your app service instead.

How can I tell dashboard queries apart from model queries in logs?

Queries run in the project dashboard use the postgres role and carry a dashboard source comment. When you give your model app its own database user, its queries log under that separate role name.

Does a custom database role hide sensitive columns from model responses?

A role can block access to a table, but permitted queries still return raw values. Data masking is needed to rewrite fields like emails or phone numbers in query results.

The query runs. The emails stay hidden.