How to Configure Pydantic AI DynamoDB Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up pydantic ai dynamodb permissions by giving your agent a scoped cloud role. That role holds strict rules that limit which tables the agent can read or write. Most engineering teams start by giving the agent a broad role during early tests. Broad roles let an agent change or delete table items by mistake during a run. Locking down those rules early keeps your data safe when the agent runs live. How pydantic ai dynamodb permissions work in practice Pydantic AI lets you build agents th

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 dynamodb permissions by giving your agent a scoped cloud role. That role holds strict rules that limit which tables the agent can read or write. Most engineering teams start by giving the agent a broad role during early tests. Broad roles let an agent change or delete table items by mistake during a run. Locking down those rules early keeps your data safe when the agent runs live.

How pydantic ai dynamodb permissions work in practice

Pydantic AI lets you build agents that use custom Python tools to do work. Your code defines these tools and passes them to the agent at runtime. When the agent needs data, it calls your custom tool with typed inputs. That tool then uses the cloud SDK to talk to your DynamoDB tables.

The agent itself does not hold any special database login rules of its own. Instead, the host machine or container running the agent holds a cloud role. The cloud SDK reads temporary keys from that host role to sign each request. Then the cloud service checks the role rules before it runs the table action.

To keep this setup safe, you build a dedicated role just for the agent. You split your agent tools into read tasks and write tasks in your code. If an agent only answers user questions, its role should only allow item reads. You also scope the role rules down to specific table names and index names. You can even add condition rules that restrict which partition keys the role can touch. This stops the agent from scanning or changing other tables in your cloud account.

Where native cloud role rules fall short

Cloud role rules do a great job of deciding which host can log in. They also block whole categories of actions, like dropping a table or writing new items. This gives your team a strong first line of defense against bad tool calls.

Still, static cloud roles leave a big gap open during live agent runs. A role decides who can run an action, not what happens inside each query. Once an agent has read rights on a table, it can pull every field. Those fields often hold sensitive user data like emails, phone numbers, or card numbers. Native role rules cannot rewrite those matched fields in results before the agent reads them. They also cannot pause a single high-risk write call to ask a human first. Finally, cloud logs show the host role, not which user prompt triggered the query.

AI Agent Permissions + DynamoDB Fine-Grained Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Best practices for scoping agent table roles

Start by separating the roles used by different agents in your app. Give your support agent a read-only role and your billing agent its own role. Never share a single broad role across multiple agents or background workers.

Next, use typed schemas in your tool definitions to validate every input field. Pydantic AI checks these types before the tool code ever calls the database. If the model invents a bad key format, the schema check blocks the call fast. This saves cloud costs and stops malformed requests from hitting your tables.

Finally, review your cloud audit logs each week to spot unused table rights. If an agent never queries a secondary index, remove that index from the role. Tightening rules over time shrinks the blast radius if a prompt goes wrong.

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

Should I put cloud keys inside my Pydantic AI agent code?

No, you should never hardcode static cloud keys inside your agent source code. Let the cloud SDK read short-lived role keys from the host runtime instead.

How do I stop an agent from deleting items in DynamoDB?

Remove the delete item action from the cloud role attached to your agent host. You can also add an explicit deny rule for all delete and table drop actions.

Can I restrict an agent to specific rows in a DynamoDB table?

Yes, cloud role rules let you add condition checks on the leading partition key. This limits the agent role so it only reads items matching specific key values.

The query runs. The emails stay hidden.