How to Configure LlamaIndex Neon Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a llamaindex neon audit log by turning on database statement logging. Then you connect your AI app with a restricted database role. Teams often connect agents to Postgres using a shared admin login. This broad role lets the query engine read every table and run risky commands. How a llamaindex neon audit log works in practice LlamaIndex uses a light wrapper around SQLAlchemy to talk to your database. Its natural language query engine turns user questions into raw SQL commands. You

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 neon audit log by turning on database statement logging. Then you connect your AI app with a restricted database role. Teams often connect agents to Postgres using a shared admin login. This broad role lets the query engine read every table and run risky commands.

How a llamaindex neon audit log works in practice

LlamaIndex uses a light wrapper around SQLAlchemy to talk to your database. Its natural language query engine turns user questions into raw SQL commands. You must pass a clear list of allowed tables to the engine. Without that list, the query engine pulls all schema context from the database. That exposes hidden tables to the language model during prompt generation.

On the database side, Neon runs Postgres and records activity through database logs. You set up Postgres logging rules to capture every statement that runs. You also create a dedicated database role just for the LlamaIndex app. This role should only have read permissions on the specific tables needed. When the agent runs a query, the database checks the role permissions first. Then the database writes the SQL text and timestamp to the log output. Your team can read these records to see what the AI agent asked.

What native database roles and logs leave open

Official LlamaIndex docs warn that running arbitrary SQL is a real security risk. They advise teams to use read-only databases, sandboxing, and restricted roles. Native database roles and logs solve the first part of this problem. They control which app can log in and which tables it can read. They also give you a paper trail after a bad query runs.

Still, native setup rules only check permissions when the session starts. They do not inspect what individual statements do while in flight. All queries from the LlamaIndex app share the same single database role. Because of this, the database log only shows that single app role name. It cannot tell you which human user or prompt triggered the SQL statement.

A read-only role also cannot stop the engine from reading sensitive columns. If an allowed table holds emails, phone numbers, or card numbers, the query returns them. The language model receives those raw fields in the query results. Native database logs record the query text, but they do not rewrite results. They cannot mask national IDs or block a bad query before it runs.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Steps to tighten agent database permissions

Start by removing default owner roles from your AI app settings. Create a fresh Postgres role that only has select rights on safe tables. Pass that exact table list into your LlamaIndex query engine setup. This stops the agent from pulling your whole database schema into memory.

Next, review your log records each week to spot strange query patterns. Look for broad table scans or failed permission checks from the agent role. If the agent hits a private table, tighten your table list right away. Keep your database credentials in a secure secret store, and rotate them often.

Check every Postgres query on the wire

Database roles and network rules decide who can open a session. They do not read what each SQL statement does after login. With hoop.dev, you run an open-source proxy, a sidecar for your Postgres. It runs beside your database and reads the Postgres wire protocol. Your apps and agents keep their login details and change only the host and port in the connection string their tool uses.

Before a query runs, hoop.dev guardrails check the statement by its effect, table, or pattern. They refuse bad deletes or drops with a real Postgres error. On the way back, hoop.dev data masking rewrites sensitive values in returned rows based on your rules. Every query and verdict goes to the audit trail. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for HIPAA, GDPR, and PCI DSS. See the code on GitHub.

Frequently asked questions

Why does LlamaIndex pull my whole database schema by default?

The query engine needs table definitions to write accurate SQL statements. If you do not name specific tables, it reads the entire schema context.

Can a read-only role protect sensitive columns from AI agents?

No, a standard read-only table grant lets the agent read every column by default. If a table has emails or card numbers, the query returns them.

What should we record when logging AI database queries?

You should log the exact SQL statement, the timestamp, and the user identity. This helps your team trace which prompt caused a specific database query.

The query runs. The emails stay hidden.