How to Configure Pydantic AI Snowflake Read Only Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up pydantic ai snowflake read only permissions by creating a custom database role. This role grants usage and select rights to your agent service user. Many teams start by giving their AI agents shared admin or developer roles. Broad permissions let a bad prompt drop tables, change records, or read every table. How to set up pydantic ai snowflake read only permissions To lock down your agent, you first build a dedicated role in Snowflake. You grant this role usage rights on one wareho

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 pydantic ai snowflake read only permissions by creating a custom database role. This role grants usage and select rights to your agent service user. Many teams start by giving their AI agents shared admin or developer roles. Broad permissions let a bad prompt drop tables, change records, or read every table.

How to set up pydantic ai snowflake read only permissions

To lock down your agent, you first build a dedicated role in Snowflake. You grant this role usage rights on one warehouse, database, and schema. Next, you grant select rights only on the specific tables the agent needs. You also apply future grants if the agent must read new tables later. Then, you create a dedicated service user for the Pydantic AI app. You assign the new read-only role as the default role for this user. Most teams set up key-pair login or OAuth tokens for this service user. In your Python app, you build a database tool function for the agent. This tool initializes a client session using the restricted service user credentials. When the agent runs, it calls this tool to send SQL queries. The data platform checks the active role before it runs any query. If the model tries to run an insert or delete command, it fails. The database engine blocks the write action and returns a permission error. Your Pydantic AI tool catches this error and tells the model what happened.

What native roles solve and where gaps remain

Native database roles stop accidental data changes and table drops right away. They make sure the agent cannot alter schemas or delete production records. This setup is a strong first step for any team running AI agents. Still, database roles only check who logs in and which tables they read. They do not inspect what individual queries do while they run in flight. A read-only role still lets an agent run a huge table scan. One bad query can rack up high compute costs on your warehouse. Native roles also return all rows and columns from an allowed table by default. If that table holds emails, phone numbers, or card numbers, the model gets them. Dynamic data masking can rewrite matched fields in results, but takes extra work. You must write and maintain separate masking rules for every sensitive column. Also, a shared service user hides which human user triggered a specific agent run. Your audit logs only show the bot account, not the person behind the prompt.

Best practices for agent database tools

You can harden your agent further by building strict tool boundaries in Python. Instead of letting the model write raw SQL, give it fixed query templates. Your Pydantic schemas validate the inputs before the tool builds the final query. You should also set a short statement timeout on the agent database role. This rule kills slow queries before they burn through your compute credits. Finally, route your agent traffic through a Dedicated small warehouse to cap costs. Keep this warehouse separate from the ones that power your main production apps. When the warehouse hits its limit, queries wait instead of slowing other teams.

AI Agent Permissions + Read-Only Root Filesystem: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Can a Pydantic AI agent still change data with a read-only role?

No, the database blocks all write commands when you grant only select permissions. Still, make sure the service user cannot switch to a broader default role.

How do I stop the agent from reading sensitive columns?

You can create secure views that leave out sensitive columns from the table. You can also apply masking rules that rewrite emails or card numbers in results.

How do I stop runaway agent queries from raising warehouse bills?

Set a low statement timeout parameter on the dedicated service user or role. You should also attach a resource monitor to the agent warehouse to cap usage.

The query runs. The emails stay hidden.