How to Configure Dify Neon Read Only Access
You set up dify neon read only access by creating a restricted Postgres role. Then you add that role string to your AI app tool settings. Many teams start by pasting their default database owner key into the app. That quick shortcut gives an AI workflow full power to change or delete production tables. A single bad prompt can then wipe out customer rows or alter schemas. How dify neon read only access works in Postgres Dify lets builders create AI agents that query external Postgres databases
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 read only access by creating a restricted Postgres role. Then you add that role string to your AI app tool settings. Many teams start by pasting their default database owner key into the app. That quick shortcut gives an AI workflow full power to change or delete production tables. A single bad prompt can then wipe out customer rows or alter schemas.
How dify neon read only access works in Postgres
Dify lets builders create AI agents that query external Postgres databases for context. Neon hosts serverless Postgres databases and separates storage from compute nodes. To link them safely, you first make a new role inside your database. You grant this role permission to connect to the database and view the schema. Next, you grant select rights on the specific tables the AI agent needs.
You must also check default privileges for any future tables your team creates. If you skip this step, the AI agent might miss new data tables later. Neon also offers read-only compute endpoints that point to your primary branch. Pairing a restricted Postgres role with a read-only compute node adds a second safety net. Even if a role check fails, the compute node rejects every write command. Once the role is ready, you place its connection string into your Dify tool setup. Now the AI workflow can read records to answer user questions without altering rows.
What native database roles solve and what they miss
Native Postgres roles stop the most obvious risks of AI database tools. The database engine blocks insert, update, delete, and drop statements at the source. Your team knows the AI app cannot corrupt records or change table structures. Read-only compute nodes in Neon also keep heavy analytical queries away from your main writer node. This split keeps your core app fast while the AI agent scans large tables.
Still, database roles only check who logs in and which tables they can read. A read-only role cannot inspect what happens inside an allowed select query in flight. If a table holds emails, phone numbers, card numbers, or national IDs, select rights return them all. The AI model receives those raw fields in its prompt context and may repeat them. Also, every Dify workflow using that shared role shows up as the same database user. Your audit logs cannot tell which builder, prompt, or end user ran a specific query. Finally, static database passwords stored in app settings stay valid until someone rotates them by hand.
Auditor Read-Only Access + Customer Support Access to Production: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Managing sensitive data and query load in AI workflows
To keep private data safe, teams often create restricted Postgres views for their AI tools. A view can leave out columns that store phone numbers, emails, or card numbers. You then grant the read-only role select rights only on that clean view. This method works well for simple schemas, though it takes time to maintain across many tables. Every schema change requires someone to update the views and check role grants again.
Teams also need to watch out for slow queries written by language models. An AI agent might join several huge tables without a limit clause or an index. You can set a statement timeout on the Postgres role to kill runaway queries early. Setting a row limit or timeout keeps one bad AI prompt from exhausting compute credits.
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 a Neon read-only compute node replace a restricted Postgres role?
A read-only compute node blocks all write commands at the compute level. Still, using a dedicated Postgres role still matters because it restricts which schemas and tables the AI app can read.
How do I stop Dify agents from running slow select queries on Neon?
You can set a strict statement timeout directly on the Postgres role used by the AI app. When a generated query runs past that time limit, Postgres cancels it right away.
What happens if my schema changes after I set up the read-only role?
New tables do not inherit select grants unless you alter default privileges in Postgres. You must set default select rules on the schema so the role can read new tables.
Related guides
In this post