How to Configure Pydantic AI Bigquery Approval

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a pydantic ai bigquery approval flow, pause agent tool calls before they run. Then make a human review and approve the SQL statement before it hits your cloud warehouse. Engineering teams often build this by pairing agent tool functions with chat alerts or ticket queues. Without this pause, an agent with a broad role might run huge scans or change production tables. How a native pydantic ai bigquery approval workflow operates In a standard setup, the agent framework defines tools as

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 a pydantic ai bigquery approval flow, pause agent tool calls before they run. Then make a human review and approve the SQL statement before it hits your cloud warehouse. Engineering teams often build this by pairing agent tool functions with chat alerts or ticket queues. Without this pause, an agent with a broad role might run huge scans or change production tables.

How a native pydantic ai bigquery approval workflow operates

In a standard setup, the agent framework defines tools as Python functions with strict input types. When the model wants to query data, it drafts a SQL string and picks the tool. Instead of running the query right away, your app code catches the request in flight. The app saves the pending query state and sends a message to a reviewer in chat.

On the database side, Google Cloud manages permissions through service accounts and Identity and Access Management roles. You give the agent app a service account key or link it through workload identity. That account holds specific roles for reading datasets, running jobs, or updating tables in the project. Once the human reviewer clicks approve in the chat app, the Python backend wakes up. It then uses the cloud client library to send the SQL job to the data warehouse. The warehouse checks that the service account can run jobs and read the target dataset. It then runs the query and sends the rows back to the agent.

What native cloud roles solve and where gaps remain

Native cloud roles do a great job of deciding which service account can log in. They also control which datasets or tables that account can see at a project level. You can split roles so one agent only reads analytics tables while another writes staging data. You can also set project quotas to cap how many bytes a single user scans each day.

Still, static cloud roles cannot judge the intent of a single query in flight. Once an account has permission to run jobs on a dataset, any valid query can run. Custom approval code inside your app tries to fix this, but it creates new problems. Every team ends up writing their own review logic, state storage, and chat hooks from scratch. If an engineer forgets to add the pause check on a new tool, queries skip review. Also, native cloud roles do not rewrite sensitive columns in query results on the fly. If a table holds emails, phone numbers, or card numbers, the query returns those raw values. Relying only on app code and static cloud roles leaves gaps in audit logs and data safety.

Approval Chains & Escalation + BigQuery IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Managing sensitive data and query limits in agent workflows

When an agent reads customer tables, you must think about what data returns to the model. Large data warehouses often store national IDs, emails, and phone numbers next to basic usage metrics. If an agent pulls a full row, those fields travel back to the external model provider. Native warehouse features like column tags require manual setup on every single table and view. When schema changes happen fast, teams often miss new columns that hold private user details. A strong workflow pairs query review with automatic field masking that rewrites matched fields in results.

Cost control is another major reason teams add human review to agent database calls. Columnar warehouses charge based on the volume of data scanned during each query job. An agent that forgets a partition filter can scan terabytes of history in a few seconds. Having a human check the query text catches missing filters before the warehouse bills your account.

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

Why do AI agents need approval before running BigQuery jobs?

Agents can write bad SQL that scans huge tables, drives up cloud bills, or alters production data. A review step lets a human check the exact SQL statement before the warehouse runs it.

Can Google Cloud IAM roles replace query approval for agents?

No, cloud roles only check if an account can access a dataset or run jobs. They do not pause individual SQL statements for human sign-off or check query filters in flight.

How does data masking help when agents query a warehouse?

Masking rewrites matched fields like emails, phone numbers, or card numbers in the query results. This keeps raw personal data out of model prompts while letting the agent finish its task.

The query runs. The emails stay hidden.