How to Configure Pydantic AI Oracle Read Only Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up pydantic ai oracle read only permissions by creating a restricted database role. Then you pass that role to your agent through its dependency injection object. Many teams start by giving their agent a broad admin account to move fast. Broad roles let one bad prompt alter tables or delete production rows in seconds. Scoping permissions down to select privileges stops accidental writes before they hit the database. How pydantic ai oracle read only permissions work in practice The set

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 read only permissions by creating a restricted database role. Then you pass that role to your agent through its dependency injection object. Many teams start by giving their agent a broad admin account to move fast. Broad roles let one bad prompt alter tables or delete production rows in seconds. Scoping permissions down to select privileges stops accidental writes before they hit the database.

How pydantic ai oracle read only permissions work in practice

The setup starts inside your Oracle database instance with a dedicated user account. Your database admin creates a role that holds only session and select privileges. You grant this role on specific views or tables that the agent needs. The admin leaves out insert, update, delete, and drop privileges from this role. Next, you build your Pydantic AI agent and define its runtime dependencies. You pass the restricted database session into the agent dependency class at startup. You then write a tool function that takes a query string from the model. The tool runs the query using the restricted Oracle session from the context. If the model tries to change a table, the database blocks the query. The tool catches the database error and returns a clean message to the agent.

What native database roles solve and what they miss

Native Oracle read-only roles stop agents from changing or deleting your core business data. They enforce a hard boundary at the storage engine level for every session. Still, static database permissions only check who logs in and which tables they read. They cannot check what an individual SQL statement does while it runs in flight. A read-only agent can still run a giant join that locks up CPU. It can also pull sensitive rows like emails, phone numbers, and card numbers. Once the database sends those rows back, the raw values enter the model prompt. Static roles also force you to store database keys inside the agent app host. Plus, shared agent accounts make it hard to tie queries back to specific users. You know the agent ran the query, but you lose the human identity behind it.

How to tighten agent tool design for database queries

You can reduce risk further by changing how you design your agent tools. Avoid giving the model a single tool that runs raw SQL strings directly. Instead, create fixed Python functions for each specific question the agent needs to answer. Use Pydantic models to check the input values before the tool builds the query. For example, require a valid customer ID integer or a narrow date range first. Set a strict row limit inside your query logic so results stay small. Add a short timeout on the Oracle session to kill slow queries early. Create restricted database views that leave out sensitive columns like national IDs or passwords. Point the agent role at those safe views instead of the base tables.

AI Agent Permissions + Read-Only Root Filesystem: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

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

Can a Pydantic AI agent still cause outages with read-only permissions?

Yes, a read-only agent can still write slow queries that scan millions of rows. You should set statement timeouts and resource limits on the Oracle user profile.

Should I let the model write raw SQL queries?

Raw SQL gives the agent flexibility for open questions, but it raises security risks. Parameterized tools with strict Pydantic input schemas are much safer for production apps.

How do I keep sensitive columns out of the model prompt?

You can create Oracle views that hide sensitive columns from the read-only role. You can also use data masking to rewrite emails or card numbers in results.

The query runs. The emails stay hidden.