How to Configure Pydantic AI Redis Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up pydantic ai redis permissions by creating a scoped user role. Then you pass that role into your agent tools at run time. Many teams start by giving their AI agents the default admin user. That broad role lets a bad prompt wipe keys or read secret cache data. Scoping the agent role stops those risky commands before they harm your store. How pydantic ai redis permissions work in practice Pydantic AI lets you build agents that call Python functions as tools. You pass a shared state ob

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 permissions by creating a scoped user role. Then you pass that role into your agent tools at run time. Many teams start by giving their AI agents the default admin user. That broad role lets a bad prompt wipe keys or read secret cache data. Scoping the agent role stops those risky commands before they harm your store.

How pydantic ai redis permissions work in practice

Pydantic AI lets you build agents that call Python functions as tools. You pass a shared state object into the agent when it runs. That state object holds your data store client and its user credentials. When the agent needs data, it runs a tool that queries the store.

Inside the data store, control lists define what each user role can do. You can create a role that only reads keys with a specific prefix. You can also block dangerous admin commands that delete data or change server rules. When the agent tool sends a command, the server checks this rule list first. If the command breaks a rule, the server blocks it and returns an error. Your Python tool catches that error and tells the agent what went wrong.

Separating read and write roles for agent tools

Most AI workloads do not need the same permissions for every single step. An agent might read user history in one step and write state later. If you use one shared role for both, every tool gets write power. A safer design splits these jobs into two distinct user roles.

You can set up a read-only role for lookup tools and search tasks. Then you create a second role that only writes to a safe key space. You pass both clients into the agent context when the session starts. Each tool picks the right client for its specific job. This setup keeps a confused lookup tool from overwriting live session state.

AI Agent Permissions + Redis Access Control Lists: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native roles solve and where gaps remain

Native user roles are great at blocking broad classes of server commands. They stop an agent from running server checks or deleting whole key spaces. They also keep an agent inside its own key prefix during normal runs. Every team should set up these base rules before shipping an agent.

Still, native roles only check who logs in and which key prefix matches. They do not inspect the actual payload inside a valid read or write command. If an agent reads a permitted key, the server returns the full value. That value might hold raw emails, phone numbers, card numbers, or national IDs. Data masking rewrites matched fields in results so raw values stay out of prompts. Also, static credentials stored in app settings are hard to rotate across many workers. Native logs rarely tie a fast cache read back to the exact person asking.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Why should agents avoid the default user role?

The default role often has full power to run any server command. A flawed prompt could trick the agent into dropping keys or reading secrets. A custom role limits the agent to safe commands and specific key names.

How do you limit which keys an agent can read?

You define key patterns inside the user rule list on the data store. Give all agent keys a clear prefix like agent-cache or chat-state. Then set the role so it only reads keys that match that prefix.

Can native store rules mask sensitive fields inside values?

No, native rules only allow or block commands based on the key name. If a read command passes the check, the store returns the whole payload. To rewrite emails or card numbers in flight, you need field masking.

The query runs. The emails stay hidden.