How to Configure Pydantic AI Snowflake Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up pydantic ai snowflake permissions by assigning a dedicated read role to the service user. Your Python agent then uses that role during each warehouse session. Many teams rush this step and reuse a broad developer account. That shortcut lets an automated agent drop tables or read private records. How pydantic ai snowflake permissions work Pydantic AI builds structured agents that call Python tools to fetch data. You write a custom tool function that opens a Snowflake session. That t

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 permissions by assigning a dedicated read role to the service user. Your Python agent then uses that role during each warehouse session. Many teams rush this step and reuse a broad developer account. That shortcut lets an automated agent drop tables or read private records.

How pydantic ai snowflake permissions work

Pydantic AI builds structured agents that call Python tools to fetch data. You write a custom tool function that opens a Snowflake session. That tool passes user credentials or a private key to log in. Snowflake checks the assigned role before it runs any SQL query.

A safe setup starts inside the data platform with a custom role. You grant this role usage rights on one warehouse and one database. Next, you add select rights on the specific schemas the agent needs. You never assign admin roles to an automated Python script.

Your Python code stores the role name inside a typed dependency object. When the model needs data, it calls your query tool with validated inputs. The tool starts a session under that restricted role and runs the query. The database returns rows, and Pydantic checks the output structure.

Why native roles are only a starting point

Native database roles do a great job of blocking unauthorized schema changes. A read-only role stops an agent from deleting tables or adding new users. It also keeps the agent out of databases that belong to other teams. This basic boundary is required for any production AI app.

Still, static grants only check who logs in at the start. They do not inspect what individual SQL statements do while in flight. An agent with select rights on a customer table can still pull every row. If a prompt tricks the model, it might query sensitive columns.

Even when you use native masking policies, managing them across many tables takes work. Database admins must write and update rules for emails, phone numbers, and card numbers. Also, database logs only show the shared service user that ran the query. You cannot easily link a bad query back to the specific app user.

AI Agent Permissions + Snowflake Access Control: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

How to tighten agent query controls

First, split your agent tools by task instead of writing one open SQL runner. Give the model small functions that run fixed queries with typed parameters. This stops the language model from inventing wild joins or scanning huge tables. Pydantic validates every input before the database driver ever sees it.

Second, set strict warehouse timeouts on the service user account in Snowflake. An AI agent might generate a slow query that locks up compute credits. A short timeout kills runaway statements before they drive up your cloud bill. You should also pair these limits with row caps inside your Python tool.

Third, plan how your team will handle sensitive fields in query results. When a tool pulls customer records, masking rewrites matched fields in results. Redacting emails, phone numbers, and national IDs keeps raw secrets out of model prompts. Combining tight roles, typed tools, and result redaction keeps your data safe.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Should a Pydantic AI agent use a shared admin role?

No, an agent should never run with admin rights. Create a dedicated service role that only has select grants on needed tables. This limits damage if a user prompt tricks the model into running bad queries.

How do I stop an agent from writing raw SQL?

Do not give the model a tool that runs raw text strings as SQL. Instead, build specific Python tool functions that accept typed filter inputs. Your code then puts those safe inputs into a fixed query template.

How can I protect sensitive columns from language models?

You can restrict role grants to safe views that exclude private columns. You can also use dynamic masking so the system rewrites emails or card numbers in results. Both steps stop raw customer secrets from reaching external model providers.

The query runs. The emails stay hidden.