How to Configure Goose Postgres Guardrails
You set up goose postgres guardrails by creating a read-only database role for your agent. Next, you restrict that role to specific tables and columns before the agent runs queries. Many teams start by giving an AI agent their own local database login. That approach creates big risks if the agent runs a bad query. Overly broad permissions let a confused model change records or drop whole tables. A strict role setup keeps your data safe from accidental writes. How to set up native goose postgre
AI Guardrails + End-to-End Encryption: the complete guide
Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.
You set up goose postgres guardrails by creating a read-only database role for your agent. Next, you restrict that role to specific tables and columns before the agent runs queries. Many teams start by giving an AI agent their own local database login. That approach creates big risks if the agent runs a bad query. Overly broad permissions let a confused model change records or drop whole tables. A strict role setup keeps your data safe from accidental writes.
How to set up native goose postgres guardrails
PostgreSQL gives you built-in tools to limit what the Goose agent can do. First, you create a dedicated group role for your AI tools. Group roles let you manage permissions in one place for many users. You then create a specific login user for the agent. Next, you add that user to your new group role.
After you set up the role, you grant it read rights. In PostgreSQL, the SELECT privilege lets a role read from a table or view. You can also grant SELECT on specific columns instead of the whole table. This helps when a table holds secret keys alongside normal app data. Note that the SELECT privilege also allows the COPY TO command.
You must also check the default rights on your database. PostgreSQL has a special role called PUBLIC that includes every user on the system. By default, PUBLIC can connect to databases and create temporary tables. It can also run functions and procedures. The database owner can revoke these default rights from PUBLIC to lock things down.
Schema permissions matter too when you build goose postgres guardrails. In PostgreSQL 15 and newer, regular users cannot create objects in the public schema. Older databases, or upgraded ones, might still allow this by default. An admin must revoke CREATE on the public schema from PUBLIC on older systems. This stops the agent from making unwanted tables during a task.
Why native roles are only half of the fix
Native database roles do a great job of controlling who can log in. They also block an agent from writing to tables when it only has read rights. Still, static roles cannot inspect what an individual query does in flight. Once the agent logs in, it can read every row in an allowed column.
AI Guardrails + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
This creates a gap when tables hold private user details. A support table might include emails, phone numbers, card numbers, or national IDs. Column permissions are all or nothing for every row in that column by default. If the agent needs to read a table, it gets the raw text too. Static roles also require you to store a database password on the local machine. If a script leaks that file, anyone can use those credentials.
What to look for in runtime query controls
To close these gaps, teams add runtime checks between the agent and the database. Runtime controls look at each statement right before the database runs it. This lets you block risky commands even if the database role allows them. You can also require a human to approve a query from Slack or Teams.
Good runtime tooling also handles sensitive data inside query results. Data masking rewrites matched fields like emails or card numbers in results before they return. The agent gets the structure it needs to debug code without storing real secrets. Finally, every query and result should go into a clear audit log. This helps your team see what the agent ran and when it happened.
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
Can PostgreSQL restrict Goose to specific columns?
Yes, PostgreSQL lets you grant the SELECT privilege on specific columns of a table. The agent will get an error if it queries any other column on that table.
Why can a new read-only role still run functions in PostgreSQL?
PostgreSQL grants the special PUBLIC role the right to run functions by default. Every new role gets PUBLIC rights unless the owner revokes them.
Does data masking block the AI agent from reading the whole table?
No, data masking only rewrites matched fields like phone numbers or national IDs in results. The agent still reads the rest of the row to finish its task.
Related guides
In this post