How to Configure LlamaIndex Supabase Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a llamaindex supabase audit log by creating a dedicated Postgres role and enabling statement logging. Then you pair those database records with callback logs inside your Python app. Many teams start by giving their agent the default database admin password. That shortcut creates a huge risk when an agent translates user questions into live SQL queries. Broad permissions let a single bad prompt read private tables or alter production rows. How a llamaindex supabase audit log works in

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 a llamaindex supabase audit log by creating a dedicated Postgres role and enabling statement logging. Then you pair those database records with callback logs inside your Python app. Many teams start by giving their agent the default database admin password. That shortcut creates a huge risk when an agent translates user questions into live SQL queries. Broad permissions let a single bad prompt read private tables or alter production rows.

How a llamaindex supabase audit log works in practice

LlamaIndex connects to Postgres through a light wrapper around SQLAlchemy. Its natural language query engine turns plain text questions into SQL statements over named tables. If you do not specify a table list, the engine pulls all schema context into the prompt. The official LlamaIndex docs warn that running arbitrary SQL queries is a security risk. They suggest using restricted roles, read-only databases, and sandboxing to lower that risk.

Every Supabase project starts with a default postgres role that holds admin privileges. Supabase does not grant full superuser status because that allows destructive actions on the database. Still, the default role still holds broad power over your data and schema. The password you set at project creation belongs to this default admin role. Supabase warns teams never to share this password with an external service unless they trust it completely. Instead, you should create a new database user specifically for your LlamaIndex service.

When you give LlamaIndex its own Postgres role, the database log becomes much clearer. Queries that run in the Supabase Dashboard run under the default admin role. They also carry a source comment that marks them as dashboard traffic. Queries from your agent will show up under the dedicated role name you created. You can then turn on Postgres statement logging for that specific user role. You can also attach event handlers in LlamaIndex to record the prompt alongside the generated SQL.

What native roles and logs solve and what they miss

A dedicated Postgres role and database audit logs solve the basic tracking problem. Your team can review the log later to see which SQL statements the agent ran. A read-only role also stops the agent from dropping tables or deleting rows. Separating agent traffic from human dashboard queries makes incident reviews much faster.

Still, database roles and native logs leave a wide operational gap during live execution. A database role only checks who logs in and which whole tables they can read. It does not inspect what individual statements do in flight before they finish running. If a user asks the agent for customer emails or phone numbers, a read-only role allows it. The database sends the raw rows back to the language model right away. Native audit logs only tell you about that data leak after the query completes.

Audit Log Integrity + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Database roles also require you to put a static password inside your app settings. Anyone who reads that setting can log in as the agent from another machine. Also, Postgres logs do not link the SQL query back to the human user who asked the question. To control data exposure in flight, teams need controls that inspect queries and rewrite results before delivery.

Best practices for restricting agent database roles

Start by naming the exact tables your query engine needs in your LlamaIndex setup. Never let the query engine pull your entire database schema into the model context. Grant your custom Postgres role select rights only on those specific public tables. Keep sensitive tables with card numbers or national IDs outside the agent role's reach.

Next, set a strict statement timeout on the Postgres role used by your agent. Language models often write slow joins that can lock up your database CPU. A role timeout stops runaway queries before they hurt other users on your app. Review your recorded statements each week to spot strange prompt patterns or failed queries.

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

Should I use the default postgres role for my LlamaIndex agent?

No, you should never use the default admin role for an AI agent. Create a dedicated read-only user so you can limit table permissions and isolate agent queries in your logs.

How does LlamaIndex decide which Supabase tables to query?

You pass a specific list of table names to the natural language SQL query engine. If you leave that list blank, LlamaIndex pulls the whole schema context, which increases risk and token cost.

Do database audit logs stop an agent from reading sensitive columns?

No, audit logs only record the SQL query after the database runs it. To protect emails, phone numbers, or card numbers during a query, you must restrict permissions or rewrite matched fields in results.

The query runs. The emails stay hidden.