How to Configure Pydantic AI Snowflake Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up pydantic ai snowflake credentials, pass a database role and key into your agent dependencies. Your agent tools then use this active session to run SQL queries against your data warehouse. Most engineering teams start by storing a static user password or private key in local settings. This basic setup works at first, but broad warehouse roles expose sensitive tables to unpredictable agent queries. How to set up pydantic ai snowflake credentials Pydantic AI uses a dependency injection

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 credentials, pass a database role and key into your agent dependencies. Your agent tools then use this active session to run SQL queries against your data warehouse. Most engineering teams start by storing a static user password or private key in local settings. This basic setup works at first, but broad warehouse roles expose sensitive tables to unpredictable agent queries.

How to set up pydantic ai snowflake credentials

Pydantic AI uses a dependency injection system to pass state and database sessions into agent tools. You first define a dependency object that holds your active warehouse session and role settings. When the agent runs, it passes this dependency into the tool function that executes SQL.

In your warehouse, you create a dedicated service user and assign a specific role to it. Key-pair login or OAuth tokens work best for automated apps that run without human input. You store the private key or token in a secret manager rather than in source files. Your app reads the secret at startup, builds the warehouse session, and hands it to the agent.

Next, you restrict the warehouse role so it only reads the schemas your agent needs. You grant select privileges on specific views and leave out tables with raw customer records. You also set a warehouse timeout rule so bad agent queries do not burn compute credits.

Why static warehouse roles fall short for AI agents

Native warehouse roles control which user logs in and which tables that role can read. They do not inspect the actual SQL text that an AI agent generates during a run. If a table holds mixed data, a read role lets the agent pull every column and row by default.

AI agents build queries based on user prompts, which makes their behavior hard to predict. A prompt injection or a logic error can trick the agent into querying raw emails or card numbers. Even with a read-only role, the agent pulls sensitive fields into the model context window. Once that data reaches the model provider, your team loses control over where it goes.

Static keys also create rotation work for your platform team across every deployed agent service. If a developer copies a key to a laptop for testing, that credential sits outside your audit logs. Warehouse logs show the shared service account name, not which prompt or user triggered the query.

Ephemeral Credentials + Snowflake Access Control: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

How to isolate agent tools and limit data exposure

To reduce risk, split your agent tools into small functions with strict input types. Instead of giving the agent a raw SQL tool, give it structured search parameters. The tool takes validated inputs from Pydantic AI and slots them into fixed query templates.

When agents must write custom SQL, point them at curated views rather than base tables. Views let you drop sensitive columns like phone numbers or national IDs before the agent queries them. You should also set row limits in your tool code so agents cannot dump whole tables.

Finally, tag every query session with metadata from the app layer before running the statement. Recording the user ID and agent run ID helps your security team trace bad queries fast.

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 use passwords or key pairs for agent warehouse logins?

Use key pairs or OAuth tokens instead of passwords for all automated agent workloads. Keys are harder to steal, support automated rotation, and work well with secret managers.

How do I stop a Pydantic AI agent from modifying warehouse tables?

Assign a read-only warehouse role to the credentials that your agent dependency uses at runtime. Never grant insert, update, drop, or delete rights to a role used by an LLM tool.

How can I protect sensitive columns when an agent queries a table?

Apply column masking rules or restrict the agent role to curated views without sensitive fields. Dynamic masking rewrites matched fields like emails or card numbers in query results before returning them.

The query runs. The emails stay hidden.