How to Configure Pydantic AI DynamoDB Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a pydantic ai dynamodb audit log by turning on cloud data events. Then you bind strict cloud roles to your agent tools. Engineering teams often start by giving the agent a broad role for database tasks. This fast setup lets the agent read and write any item in the table. When permissions are too broad, one bad prompt can wipe out key records. A clear log helps your team track every single call the agent makes. How a pydantic ai dynamodb audit log works Pydantic AI lets developers b

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 dynamodb audit log by turning on cloud data events. Then you bind strict cloud roles to your agent tools. Engineering teams often start by giving the agent a broad role for database tasks. This fast setup lets the agent read and write any item in the table. When permissions are too broad, one bad prompt can wipe out key records. A clear log helps your team track every single call the agent makes.

How a pydantic ai dynamodb audit log works

Pydantic AI lets developers build agents that use typed functions to run tasks. Each function acts as a tool that the model can call during a run. When an agent needs data, it runs a tool that calls the database. In a DynamoDB setup, this tool uses a cloud role to log in the session. The cloud provider checks the role permissions before it allows the read or write.

To build the pydantic ai dynamodb audit log, you must turn on data plane logging. Standard cloud logs only track table creation, deletion, or role changes. They do not record item reads, writes, or updates inside the table itself. You must enable data events in your cloud logging service for that specific table. Once active, every item request from the agent tool writes an event record. This record holds the caller identity, the time, the table name, and the action.

What native logging solves and what it misses

Native cloud logging gives you a solid record of which role called the database. Security teams can review these logs to spot odd patterns after an incident happens. You can see if the agent role ran a full scan or deleted items. It proves that the cloud role authenticated the session and had the right permissions.

Still, native setup rules only check who logs in, not what queries do in flight. The cloud role grants table permissions, so every tool call shares those exact same rights. Native cloud logs also omit the item payload to keep log sizes small. You can see that an agent updated an item, but not the new values. Worse, if a query returns emails, phone numbers, or card numbers, the model gets them. Native logging records the read event after the fact, without rewriting sensitive fields in results.

AI Audit Trails + Audit Log Integrity: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Managing agent permissions and data exposure

Teams often try to fix this gap by writing custom code inside each agent tool. Developers add checks to validate inputs and strip out national IDs before returning data. This approach puts security rules inside the app code, which is hard to maintain. Every time a developer adds a new tool, they must remember to copy those checks.

A better design separates role permissions and data checks from the agent code itself. You should scope cloud roles down to the exact actions the agent needs to run. You also need a way to inspect commands in flight before they hit the database. Masking rules that rewrite emails and card numbers in results keep sensitive data safe. Combining scoped roles with in-flight checks gives your team a complete audit trail.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Does DynamoDB log item reads and writes by default?

No, the database only logs table management events by default. You must turn on data event logging in your cloud trail settings to track item calls.

How do I link an agent run to a specific database log entry?

You can pass a unique trace ID in the cloud session name when the tool runs. That session name then appears inside the cloud log entry for easy matching.

Can native cloud logs stop an agent from reading sensitive fields?

No, audit logs only record actions after the database runs the request. To hide emails or phone numbers, you need a tool that rewrites matched fields in results.

The query runs. The emails stay hidden.