How to Configure Pydantic AI Redis Read Only Permissions
You set up pydantic ai redis read only permissions by creating a restricted database user. Then you pass those read-only credentials into your agent tool dependencies at runtime. Many teams start by giving agents the default database user during early testing. This broad role lets an AI agent change or delete live cache keys by mistake. How pydantic ai redis read only permissions work in practice Pydantic AI uses a clean dependency injection system to pass data clients into tools. You define
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 redis read only permissions by creating a restricted database user. Then you pass those read-only credentials into your agent tool dependencies at runtime. Many teams start by giving agents the default database user during early testing. This broad role lets an AI agent change or delete live cache keys by mistake.
How pydantic ai redis read only permissions work in practice
Pydantic AI uses a clean dependency injection system to pass data clients into tools. You define a tool function that takes a context object and a database client. The agent decides when to call this tool based on user prompts and schemas. The framework itself does not limit what commands the database client can run.
To enforce read-only behavior, you must configure the permissions inside Redis itself. You use the native ACL system to create a dedicated user for the agent. In this rule set, you allow read commands and block all write commands. You also block admin commands that could slow down the server or drop keys.
Next, you restrict which key patterns this user can read in the memory store. You might let the agent read product cache keys while blocking session token keys. Once the database role is ready, you store the user credentials in secret storage. Your Python app loads these credentials when it starts up and builds the client.
When the agent runs, it receives this restricted client through its run context. If the model tries to run a write command, the database rejects it. Your tool function catches the error and tells the agent the action failed.
Why you should also wrap Python tools
Database rules are essential, but you should also restrict the agent tool definitions. Do not give the model a generic tool that runs raw command strings. Instead, write small Python functions that only perform specific read lookups. For example, create a tool that fetches a user profile by its ID.
Pydantic validates the input arguments before the Python function ever runs a query. This stops the model from sending malformed arguments or unexpected data types. Combining strict tool schemas with database ACL rules gives you two layers of safety. The schema guides the model, and the database enforces the hard boundary.
AI Agent Permissions + Read-Only Root Filesystem: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native read-only roles solve and what they miss
Native ACL rules stop an agent from wiping data or changing stored values. They also prevent the agent from running heavy admin commands that lock the server. For basic safety against bad writes, native database permissions work very well.
Still, static database credentials still leave several operational gaps open for your team. First, the Python app must hold long-lived passwords in its runtime memory. If an attacker compromises the app server, they can steal those database credentials.
Second, read-only permissions do not stop an agent from reading sensitive personal data. A key might hold customer emails, phone numbers, card numbers, or national IDs. If the key pattern matches, the database sends the full record to the model. Static rules cannot rewrite matched fields in results to hide private details.
Third, shared app users make auditing very hard for security teams. Every agent run logs in with the exact same database username. When a bad query happens, your logs do not show which user prompt triggered it. You only see that the shared Python worker ran a read command.
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
Can Pydantic AI enforce read-only rules on its own?
No, the agent framework only validates tool inputs and structures model outputs. You must enforce read-only rules in the database ACL and your tool code.
What happens when an agent tries to write with a read-only user?
The database blocks the command and returns a permission error to your Python client. You should catch this error in your tool and return a clear message.
How do I stop agents from reading sensitive cache keys?
Use key pattern rules in your database ACL to limit which prefixes the role reads. You can also add data masking to rewrite emails or card numbers in results.
Related guides
In this post