How to Configure Pydantic AI Bigquery Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up pydantic ai bigquery credentials by binding a cloud service account to your agent. Your Python app then reads those keys from the local host or workload identity. Most engineering teams start by granting a single project role to that account. When that role is too broad, an agent can read every table in the dataset. A prompt mistake can also trigger huge table scans or pull sensitive customer records. How pydantic ai bigquery credentials work in practice Pydantic AI agents use cust

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 bigquery credentials by binding a cloud service account to your agent. Your Python app then reads those keys from the local host or workload identity. Most engineering teams start by granting a single project role to that account. When that role is too broad, an agent can read every table in the dataset. A prompt mistake can also trigger huge table scans or pull sensitive customer records.

How pydantic ai bigquery credentials work in practice

Pydantic AI agents use custom tool functions to run SQL against Google Cloud data warehouses. The agent framework does not manage database keys on its own. Instead, your tool function loads the Google Cloud client library inside your Python app. That client library looks for default keys in the host runtime.

In local testing, developers often log in with their own user accounts. In production, teams attach a cloud service account to the container or virtual machine. The client library trades that service account identity for a short token. BigQuery checks that token against project roles before it runs any job.

You pass the active client object into the agent through its dependency injection system. When the language model decides to query data, it calls your registered tool. The tool runs the SQL string using the attached service account permissions. The database returns the rows to the tool, which sends them back to the model.

Why static service accounts leave a security gap

Cloud IAM roles decide which service account can log in and read a dataset. They do not inspect what an individual SQL statement does while it runs. Once the service account has read permissions, every agent call shares that exact same power. If a user asks a trick question, the agent might query a restricted billing table.

Static roles also make audit logs hard to read for security teams. Every query in the cloud log shows the same shared service account name. You cannot tell which human user or agent session ran a specific query. If a query scans terabytes of data, you cannot trace the root cause fast.

Ephemeral Credentials + BigQuery IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What happens to sensitive data in query results

BigQuery stores customer emails, phone numbers, card numbers, and national IDs in raw columns. When an agent runs a broad select query, those fields flow into the model context. External language models then process those raw values to build their text response. Native cloud roles only block whole columns or tables before the query starts.

Teams often try to fix this by building dozens of custom views per dataset. Maintaining separate views for every agent role takes weeks of manual database work. When schemas change, those views break and stop the agent from working. Teams need a way to inspect queries and rewrite sensitive fields in results on the fly.

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 I put service account JSON files in my agent code repository?

No, never store raw JSON key files inside your source code or container images. Use workload identity on cloud hosts so the runtime fetches temporary tokens on its own.

How can I stop an AI agent from modifying or dropping BigQuery tables?

Assign a read-only job and data viewer role to the agent service account. You should also block write and delete statements before they reach the database.

How do I keep customer emails and card numbers out of model prompts?

Use dynamic data masking to rewrite matched fields like emails and card numbers in query results. The agent receives masked text in its context while the database keeps the original values.

The query runs. The emails stay hidden.