How to Configure Pydantic AI Oracle Permissions
You set up pydantic ai oracle permissions by creating a narrow database role for your agent. Next, you pass that role into your agent tools through a dependency object. Most teams start by giving the agent a broad developer role during testing. That broad role often stays in place when the app goes live. If an agent holds wide database rights, one bad prompt can read or change sensitive tables. How pydantic ai oracle permissions work in practice Pydantic AI uses a clean dependency pattern to
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 oracle permissions by creating a narrow database role for your agent. Next, you pass that role into your agent tools through a dependency object. Most teams start by giving the agent a broad developer role during testing. That broad role often stays in place when the app goes live. If an agent holds wide database rights, one bad prompt can read or change sensitive tables.
How pydantic ai oracle permissions work in practice
Pydantic AI uses a clean dependency pattern to give tools the resources they need. You build a context object that holds an active Oracle database session. The agent does not hold the database password or session details in its prompt. Instead, the framework passes the session into the Python function when the model calls a tool.
On the database side, admins create a specific user account just for the AI agent. They grant this user a custom role with read rights on a few safe tables. Sometimes they build views that leave out sensitive columns before the agent can read them. When the tool runs a query, Oracle checks the role attached to that active session. If the query touches a table outside that role, the database blocks the statement right away.
Setting up scoped roles for agent tool calls
A strong setup splits agent tasks into separate database roles based on risk. You might create one role for reading public product tables and another for updating orders. Your Python app holds a separate session pool for each database role. When you define a tool in Pydantic AI, you link it to the matching session pool.
Type hints and validation models add another layer of safety inside your Python code. You define strict input schemas so the model must send clean parameters to the tool. The tool then plugs those checked values into a fixed query template. This pattern stops the model from writing raw SQL strings on its own. Still, many teams want their agents to write flexible SQL for complex data analysis. Once you let an agent generate raw SQL, input schemas cannot catch every risky query.
AI Agent Permissions: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native database roles solve and what they miss
Native Oracle roles are great at enforcing hard rules at the table and view level. They make sure an agent account cannot drop tables or read restricted schemas. Database admins can manage these grants using the standard tools they already know well. For simple apps with fixed tool queries, native roles handle the basic security needs.
The gap appears when an agent needs to query tables that mix safe and sensitive data. A native role decides which user can log in and read a given table. It does not inspect what individual statements do in flight or who triggered the agent prompt. If a table holds customer emails, card numbers, or phone numbers, a read grant exposes them. Building and maintaining separate database views for every single agent task takes too much time. Teams also lack a clear log linking a specific user prompt to the final database query. Also, native roles cannot pause a risky update to ask a human for approval first.
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 an AI agent share a database role with the main web app?
No, you should always create a separate user and role for your AI agent. Web apps run fixed code, while agents can generate unexpected queries from user prompts. A separate role limits the damage if a prompt tricks the agent.
How can I stop an agent from reading emails or card numbers in a table?
With native database tools, you must build a filtered view that leaves out those columns. Another option is using data masking that rewrites matched fields like emails and card numbers in results.
Can Pydantic AI validation stop all bad database queries on its own?
Validation only checks the inputs passed into a Python function against your schema rules. If your tool lets the model pass a raw SQL string, schema checks will not inspect the SQL logic.
Related guides
In this post