How to Configure Pydantic AI Bigquery Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a pydantic ai bigquery sandbox by linking your agent tool to a free Google Cloud project. Next, you attach a read-only service role and pass structured output schemas to the model. Many teams start by giving the agent broad project roles to move fast. Overly broad roles let the model read every table or change warehouse settings. How the pydantic ai bigquery sandbox workflow runs This setup links a Python agent framework with a cloud data warehouse. The sandbox lets your team test

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 a pydantic ai bigquery sandbox by linking your agent tool to a free Google Cloud project. Next, you attach a read-only service role and pass structured output schemas to the model. Many teams start by giving the agent broad project roles to move fast. Overly broad roles let the model read every table or change warehouse settings.

How the pydantic ai bigquery sandbox workflow runs

This setup links a Python agent framework with a cloud data warehouse. The sandbox lets your team test SQL queries without adding a credit card. You build an agent in Python and define strict data shapes for inputs and outputs. Then you write a custom tool function that sends SQL queries to the warehouse client.

First, you create a project in the cloud console and open the warehouse workspace. The sandbox mode turns on when you skip the billing setup step. Next, you create a service account for your agent app to use. You grant this account a viewer role on one specific test dataset. You also grant a job user role so the agent can run queries.

On the app side, you pass the database client into the agent context. When a user asks a question, the model picks the query tool. The framework checks the tool inputs against your strict type rules before running code. The client runs the SQL job in the cloud and returns the rows. Finally, the framework checks the result shape and sends a clean answer back.

Where native cloud roles fall short in agent tests

Native cloud roles control which account can log in and start a job. They also limit which datasets and tables that account can read or change. This setup stops an outside user from touching your cloud project. It also keeps the sandbox within fixed storage and query quotas.

Still, cloud roles cannot inspect the actual SQL text that an agent writes in flight. Once the service account logs in, it can read every column in an allowed table. If a test table holds real emails or phone numbers, the query returns them. The raw text goes straight into the model prompt and external logs.

Native permissions also cannot block a slow, full-table scan before it runs. An agent might write a bad join that burns through your daily free quota. You need a way to check each query and mask sensitive fields in results. Rewriting matched fields like card numbers or national IDs keeps test runs safe.

AI Sandbox Environments + BigQuery IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Best practices for safe agent data testing

Keep your sandbox dataset small and separate from your main cloud projects. Load synthetic rows into your test tables instead of copying real customer records. If you must use real data shapes, scrub emails and phone numbers first. Set table expiration dates so old test data clears out on its own.

Write separate tool functions for metadata lookups and actual row queries. One tool can list table names and column types for the agent. The second tool can run read-only select statements with a hard row limit. Check that the query string starts with a select word before sending it.

Log every prompt and every generated SQL statement during your test runs. Reviewing these logs helps your team spot bad query patterns early. You can then tighten your system prompt and schema descriptions before going live.

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

Do I need a credit card to use the BigQuery sandbox?

No, you do not need a credit card or a billing account. You get free storage and monthly query quotas with default table expiration rules.

How does the agent know the table schema before writing SQL?

You can pass the table schema in the system prompt or build a lookup tool. The lookup tool queries the dataset metadata and returns column names and data types.

Can I use the same service key for local tests and staging?

You should never share one service key across different test setups. Create a separate account for each app stage and limit roles to single datasets.

The query runs. The emails stay hidden.