How to Configure Pydantic AI DynamoDB Read Only Permissions
You set up pydantic ai dynamodb read only permissions by attaching an IAM read role. Next, you pass that scoped session to the agent tool functions. Many teams start by giving their agent broad cloud keys during early testing. Broad roles let a single bad prompt alter or delete live table records. Scoping the agent role down to read actions stops write calls at the cloud API. How pydantic ai dynamodb read only permissions work in practice Pydantic AI agents run Python functions to fetch data
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 read only permissions by attaching an IAM read role. Next, you pass that scoped session to the agent tool functions. Many teams start by giving their agent broad cloud keys during early testing. Broad roles let a single bad prompt alter or delete live table records. Scoping the agent role down to read actions stops write calls at the cloud API.
How pydantic ai dynamodb read only permissions work in practice
Pydantic AI agents run Python functions to fetch data for language models. These tool functions use the standard cloud SDK to query your DynamoDB tables. The cloud SDK pulls temporary keys from the host role when the app starts. Your IAM policy defines which table actions the agent session can run. A strict read policy allows item lookups, index queries, and table scans. It blocks every request that tries to create, update, or delete items. You also lock the policy to specific table names and index names. The agent passes validated parameters into the tool function during a model run. Then the cloud service checks the IAM role before returning any table items.
What native read roles solve and where gaps remain
Native cloud roles do a great job of blocking destructive write commands. If a model hallucinates a delete call, the cloud API rejects it right away. Still, IAM permissions only check who logs in and which table they query. The cloud role cannot inspect the actual records inside a permitted read response. A read role still lets an agent run a full scan across big tables. Those table rows often hold customer emails, phone numbers, or card numbers. Once the tool fetches those rows, the raw values enter the model context. Standard cloud logs also do not link table queries to specific agent prompts. Teams need a way to filter sensitive fields and audit every query in flight.
Best practices for scoping agent tool queries
Start by writing narrow tool functions that only query one specific table view. Do not let the language model pick the table name on its own. Hardcode the table name inside the tool and only ask for search keys. Use Pydantic models to check the search key format before calling the SDK. Set a strict item limit on every query call inside your Python code. This simple rule keeps the agent from pulling thousands of rows at once. Project only the exact attributes the agent needs to answer the user question. Leaving out extra columns reduces token usage and keeps private fields out of memory. Finally, rotate the execution role keys on a short timer to limit risk.
AI Agent Permissions + Read-Only Root Filesystem: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
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
Can an IAM read role hide sensitive attributes inside a DynamoDB item?
You can restrict specific attribute names in an IAM policy condition block. Still, IAM cannot rewrite emails, phone numbers, or card numbers inside returned text fields.
How does a Pydantic AI tool authenticate to DynamoDB without static keys?
Run the agent on a compute host that has an attached IAM role. The cloud SDK will fetch short-lived role credentials from the host metadata service.
How do you stop an agent from running expensive full table scans?
Remove the scan action from the IAM policy and only allow query actions. This forces the agent tool to use a partition key for every lookup.
Related guides
In this post