How to Configure Pydantic AI Snowflake Permissions
To set up pydantic ai snowflake permissions, give your agent a read-only database role. Then pass that scoped session into your agent through its dependency object. Many engineering teams rush this step during early testing. They give the agent a broad developer role to make queries work fast. That broad role lets an unpredictable model read sensitive tables or drop production data. A safe setup pairs strict database roles with typed tool inputs inside your Python app. How pydantic ai snowflak
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.
To set up pydantic ai snowflake permissions, give your agent a read-only database role. Then pass that scoped session into your agent through its dependency object. Many engineering teams rush this step during early testing. They give the agent a broad developer role to make queries work fast. That broad role lets an unpredictable model read sensitive tables or drop production data. A safe setup pairs strict database roles with typed tool inputs inside your Python app.
How pydantic ai snowflake permissions work in practice
Pydantic AI uses a dependency injection pattern to pass resources into agent tools. You build a session object for Snowflake and attach it to the agent context. The agent does not write raw login keys into its own prompts. Instead, the Python app logs in first and hands the active session to the tool.
Inside your data warehouse, permissions flow through role-based rules. You create a dedicated service user and a custom role just for the AI agent. That role needs usage rights on one warehouse, one database, and one schema. You then grant select privileges only on the specific tables or views the agent needs.
Next, you define tools in your Python code that the model can call. Each tool takes structured inputs validated by Pydantic schemas before any query runs. Rather than letting the model write raw SQL, you can restrict tools to fixed templates. This setup combines typed Python inputs with strict role boundaries in Snowflake.
Where native database roles fall short for AI agents
Native roles in Snowflake decide which tables a user can read during a session. They work well when a tool only needs a safe slice of public data. They also stop an agent from running write commands if you grant select rights only.
Still, table-level roles cannot see what an individual query does in flight. An agent often needs to query a customer table to answer a support ticket. If that table holds emails, phone numbers, or card numbers, the role returns everything. Data masking inside the warehouse requires manual rules on every single column across every schema.
Static roles also lack a human approval step for risky actions. Sometimes an agent must update a record or run a heavy query. If the role allows updates, the agent can update any row at any time. Native permissions decide who logs in, not whether a specific query is safe right now.
AI Agent Permissions + Snowflake Access Control: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Best practices for scoping agent tool calls
Start by replacing open-ended SQL tools with narrow, task-specific functions in your agent code. If the agent checks order status, build a tool that only accepts an order ID. Validate that ID with strict type rules before placing it into a query.
Keep your service account keys in a secret manager, never in agent code. Set a short query timeout on the warehouse role used by your AI app. This simple rule stops a bad agent prompt from running an expensive table scan.
Finally, review your query logs each week to see what tools the model calls. Look for failed queries or attempts to read tables outside the normal workflow. Tight schemas and narrow database roles form a strong baseline for safe agent operations.
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
Should I let my Pydantic AI agent run raw SQL queries?
No, letting a model write raw SQL creates a high risk of bad queries. Build specific Python tools with typed inputs that run fixed query templates instead. If you must allow raw SQL, restrict the database role to read-only views.
How do I pass a database session to Pydantic AI tools?
Use the built-in dependency system provided by the framework to manage state. Create your database session outside the agent, then pass it in at runtime. Your tool functions can then pull the active session from the run context.
How can I protect sensitive columns when an agent queries a table?
First, try to point your agent role at secure views that omit sensitive columns. When the agent must query tables with emails or phone numbers, use dynamic masking. Masking rewrites matched fields in results before the payload reaches the language model.
Related guides
In this post