How to Configure Mastra Postgres Approval

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a mastra postgres approval workflow by pausing agent steps before they run SQL. A human reviewer then checks the pending query and lets the task move forward. Most teams start by giving their AI agents a shared database login key. When that role has broad write rights, one bad prompt can delete or change live data. Splitting read and write steps gives the team a chance to check each change first. How a mastra postgres approval workflow operates In a standard setup, the agent framew

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 mastra postgres approval workflow by pausing agent steps before they run SQL. A human reviewer then checks the pending query and lets the task move forward. Most teams start by giving their AI agents a shared database login key. When that role has broad write rights, one bad prompt can delete or change live data. Splitting read and write steps gives the team a chance to check each change first.

How a mastra postgres approval workflow operates

In a standard setup, the agent framework splits database tasks into two clear parts. Safe read queries run right away, while write actions pause and wait for a human signal. You build this by setting up separate database roles on the server first. Postgres lets admins create group roles to manage permissions across many users and apps. You can give the read role permission to read only specific columns on a table. Note that this same read privilege also allows the user to export table data.

Next, you must lock down the default database rules on your server. Postgres includes a special public role that gives rights to every user on the system. By default, that public role can log in to databases and run functions and procedures. It can also make temporary tables inside the database during an active session. In Postgres 15 and newer, users cannot create new objects in the public schema by default. On older or upgraded databases, an admin must revoke that create right from the public role. Once the database roles are tight, the agent pauses before using the write role. A reviewer gets a chat alert, checks the query, and marks the step as approved.

What native setup solves and what it misses

Native roles and app pauses help stop basic mistakes inside your normal agent workflows. The database enforces who can log in and which tables that role can touch. Meanwhile, the workflow pause ensures a person looks at planned tasks inside the app. This stops an agent from running a write tool step without a human nod.

Still, this setup leaves a large gap during live database sessions. Database roles only check who logs in, not what each query does in flight. Once the app holds a write role, any query using that session can change rows. If an agent crafts a wide update statement, the database role will still allow it. Also, standard column grants are static and apply to the whole table at once. They cannot dynamically rewrite sensitive fields like emails, phone numbers, card numbers, or national IDs. If a read role includes a sensitive column, every select query returns those raw values. A complete setup needs statement-level checks and data masking that rewriting matched fields in results.

Approval Chains & Escalation + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

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

How do you stop an agent from creating tables in Postgres?

Use Postgres 15 or newer, where public schema creation is off by default. On older databases, revoke the create right on the public schema from the public role.

Can a Postgres read role still export sensitive table data?

Yes, the standard select privilege also allows the user to run bulk data exports. You can limit this by granting select rights only on specific safe columns.

Why are app-level workflow pauses not enough for database safety?

App pauses only govern steps that pass through that specific agent workflow code. They do not inspect raw SQL statements or rewrite sensitive fields like emails in results.

The query runs. The emails stay hidden.