Menu

Your AI agent can read the whole database. Give it a Postgres role that can't
📰

Your AI agent can read the whole database. Give it a Postgres role that can't

DEV Community: postgres·Redlio Labs·20 days ago
#fi1Da7iu
#devtopostgresql#devto#dev#role#select
Long article (1412 words) — no AI summary yet.
Reading 0:00
15s threshold

Most "chat with your data" features start the same way. Someone wires an agent (or an MCP server) to the app's existing database connection, adds a tool that runs a query, and the demo works on the first try.

That connection usually belongs to the app. It can read every table, every column, every tenant. It can write. Whatever the model is talked into doing, it does with those rights.

Prompt instructions like "only answer questions about the current customer" are not access control. They are a request. The database is the one place that can actually say no, so that is where the limits belong.

Here is the setup we use when we add an AI feature to an existing Postgres-backed app. It takes about an hour, and none of it depends on which model or agent framework you use. Every snippet below was run against Postgres 16 with the tests at the end passing.

1. Give the AI layer its own role

The AI code path should never borrow the app's credentials.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.