How to Configure Dify Neon Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up dify neon prevent delete rules by assigning a restricted Postgres role to your AI app. You also turn on branch protection in your database project to block branch drops. Many teams start by giving their AI workflows the default database owner key. That broad role lets a bad prompt or agent loop wipe out production tables. Scoping down permissions before you launch stops accidental data loss. How to set up dify neon prevent delete in your database First, you need to separate databas

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 dify neon prevent delete rules by assigning a restricted Postgres role to your AI app. You also turn on branch protection in your database project to block branch drops. Many teams start by giving their AI workflows the default database owner key. That broad role lets a bad prompt or agent loop wipe out production tables. Scoping down permissions before you launch stops accidental data loss.

How to set up dify neon prevent delete in your database

First, you need to separate database admin duties from daily app queries. Neon gives you a default role that owns the schema and all tables. Do not put this owner key into your AI workflow settings. Instead, create a dedicated database role for your AI agent or app. Grant this new role permission to read rows and insert new records. Leave out the permission to delete rows or drop tables.

Next, you put the new role credentials into your Dify tool or dataset settings. When the AI workflow runs a query, Postgres checks the role rules first. If the model tries to delete rows, the database rejects the command right away. You can also turn on protected branches inside your database project. This setting stops users and scripts from deleting your main production branch by mistake. It also prevents anyone from resetting the branch to an older state.

What native database roles solve and what they miss

Database role grants work well when an app never needs to remove any data. They block delete commands at the database engine level every single time. Protected branches also keep your core database instance safe from bad API calls. Together, these native controls stop full table wipes and accidental branch removals.

Still, static database roles decide who logs in, not what individual queries do in flight. Sometimes an AI agent needs permission to delete temporary state or clean up old drafts. If you grant delete rights for those tasks, the role can delete any row in that table. A native role cannot check if a delete command lacks a filter clause. It also cannot ask a human to approve a risky delete query before it runs. In the same way, database roles do not rewrite sensitive fields like emails or phone numbers in query results.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Managing mixed read and write workflows safely

To handle mixed workloads, split your AI tools into two separate database roles. Give your main retrieval and chat tools a strict read-only database user. Create a second user that can write or update rows only in specific staging tables. Never give the write user access to your core customer tables.

You can also use Postgres row security rules to limit which rows a user can touch. This rule checks a tenant or user tag on each row before running a command. Even with row rules, you should watch query logs to spot bad agent prompts early. Good role design paired with runtime checks keeps your data safe from unpredictable model behavior.

Add query and result controls beside Postgres

Grants and pools govern who logs into PostgreSQL. Yet every query in an open session still runs with that role's full scope. In practice, hoop.dev runs beside your database as a sidecar for your Postgres. It reads plain and prepared queries on the wire with no change to your users or drivers.

When a tool or agent sends SQL, hoop.dev Postgres controls check each statement against your deny rules. An AI Analyzer you configure can also score intent or hold a risky query for human review. Matched sensitive columns in result rows are masked in memory before they reach the caller. Each query and decision is logged per listener, which generates evidence for SOC 2, HIPAA, and GDPR audits. View the binary on GitHub.

Frequently asked questions

Can Neon branch protection stop SQL delete statements inside a table?

No, branch protection only stops someone from deleting or resetting the database branch itself. To block SQL delete statements inside tables, you must revoke delete privileges from the Postgres role.

How should Dify connect to Neon when it only needs to read context data?

Create a read-only Postgres user or use a read replica host for your workflow. This setup ensures that prompts and tools can only fetch data and never change it.

What happens if an AI agent needs to delete specific rows but not whole tables?

You can revoke table truncate rights and add row security policies in Postgres. For stricter control, require human approval on delete statements before they reach the database.

The query runs. The emails stay hidden.