October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Keep AI Agents Read-Only with Database-Enforced Access

A prompt cannot make database access safe. Use a dedicated least-privilege identity, backend authorization, and database-enforced controls such as PostgreSQL grants and row-level security.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Give an AI agent a dedicated database identity with only the read privileges its task requires, then enforce authorization in trusted application code as well as in the database. A prompt saying “do not write” is not a security boundary. The PostgreSQL examples below are specific to PostgreSQL; other database engines have different permission and transaction behavior.

Design the boundary before connecting an agent

Decide what the agent needs to answer, which data it may see, and which operations it may perform. Prefer a narrow, task-specific query tool or API over unrestricted SQL when that can meet the need. If SQL is necessary, treat it as untrusted input: the server must authorize the operation and its scope independently rather than assuming model-generated SQL is safe.

As an Amazon Associate I earn from qualifying purchases.

Use separate identities and credentials for the agent and for any write-capable workflow. Do not reuse a developer’s personal login or an administrator account, and do not put long-lived secrets in the model’s context. OWASP recommends minimum necessary permissions, scoped tools, and authorization for sensitive operations in its AI Agent Security Cheat Sheet and MCP Security Cheat Sheet.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Grant access to only the data the task needs

Scope access to the smallest appropriate set of databases, schemas, tables, views, and—where supported—columns. A curated view or narrow application API can keep personal, confidential, or operational data outside the agent’s reach. Read-only access is not the same as privacy: an agent can still disclose information it is permitted to read, so minimize the data returned and apply appropriate output controls.

#1 Best Overall

In PostgreSQL, privileges are granted on specific objects. Ownership is different: an object owner has inherent rights to alter or destroy that object, which ordinary privilege revocations do not reliably remove. Do not make the agent role an owner. See the PostgreSQL 18 documentation on privileges and OWASP’s Database Security Cheat Sheet.

Illustrative PostgreSQL setup

This example grants an agent login access to one database, one schema, and one view. Replace the example names with objects deliberately selected for the task; run administrative statements using an authorized administrator identity, not the agent login.

CREATE ROLE agent_reader LOGIN;
GRANT CONNECT ON DATABASE appdb TO agent_reader;
GRANT USAGE ON SCHEMA reporting TO agent_reader;
GRANT SELECT ON TABLE reporting.agent_safe_view TO agent_reader;
ALTER ROLE agent_reader SET default_transaction_read_only = on;

The role should not own the view or its underlying objects, nor inherit membership in a role with broader privileges. Granting access to a view also requires checking how that view is defined and what data it exposes. If access to additional objects is necessary, grant only those objects rather than broad database-wide rights.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use PostgreSQL read-only transactions as an extra guardrail

PostgreSQL 18 supports READ ONLY transactions. It blocks a defined set of data-modifying and schema-changing commands, including INSERT, UPDATE, DELETE, MERGE, and TRUNCATE. A transaction can be marked read-only with SET TRANSACTION READ ONLY; the example role setting above makes read-only the default for its transactions. Consult PostgreSQL’s SET TRANSACTION documentation for the full behavior and command list.

This is defense in depth, not the primary permission boundary. PostgreSQL describes read-only as a high-level transaction notion and notes that it does not prevent every write to disk. The role still needs to lack write privileges, and the transaction setting must not be mistaken for a universal guarantee that nothing can be changed. These semantics are PostgreSQL-specific; verify the equivalent controls and limitations for your database engine.

Apply row-level security where users or tenants must be isolated

Table-level SELECT permission may expose every row in a table. In PostgreSQL, row-level security (RLS) policies can further restrict which rows a role may see. Once RLS is enabled, the absence of a policy allowing access defaults to deny. However, table owners and roles with the BYPASSRLS attribute ordinarily bypass RLS, so verify that the agent is neither one. PostgreSQL documents these rules in Row Security Policies.

Do not confuse broad read access with appropriately scoped read access. PostgreSQL’s predefined pg_read_all_data role grants read access across tables, views, and sequences, as well as schema usage, even without explicit grants. It does not itself have BYPASSRLS by default, but its broad object scope may still be unsuitable for an agent. See the PostgreSQL 17 Predefined Roles documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Authorize every tool call outside the model

Prompts and tool descriptions can guide an agent, but they cannot enforce access. A trusted server or gateway should check every operation against the current user and task scope, validate arguments against a narrow schema, and enforce explicit allowlists. Do not treat model-generated SQL or a model’s interpretation of policy as authorization. OWASP’s SQL Injection Prevention Cheat Sheet covers safe handling of SQL inputs; its agent guidance also recommends limiting tools and enforcing permissions in trusted code.

Keep read and write capabilities separate. If a workflow genuinely needs writes, expose them through a distinct identity and tool with independent authorization and, where appropriate, explicit human approval. A read-only identity should not be able to switch to or assume that write-capable identity.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Assume retrieved content can try to redirect the agent

Rows, documents, tool responses, and user prompts may contain instructions intended to hijack an agent into making other tool calls or exposing data. Treat retrieved text as data, not as trusted instructions. Narrow permissions limit the damage such an attempt can cause; trusted application code must still authorize the next operation. Filtering suspicious text may help detection, but it is not a replacement for access controls. OWASP describes direct and indirect prompt injection, tool abuse, and sensitive data exposure among agent risks in its AI Agent Security Cheat Sheet.

Review the access boundary as the system changes

Keep enough audit information to identify which agent identity, tool, data scope, and policy version served an operation. Redact credentials and avoid recording unnecessary sensitive values. Review grants and tool definitions whenever the agent’s tasks, prompts, tools, memory, retrieval sources, policies, or model provider change. Test the authorization boundary before production and after material changes; OWASP’s agent security guidance recommends testing at these points.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Confirm the agent has no write grants, ownership, or inherited administrator privileges.
  • Test that queries outside the approved tables, views, columns, or rows are denied.
  • Check that a prompt or database value cannot cause a write-capable tool call without independent authorization.
  • Verify that logs support investigation without exposing credentials or excess data.

Choose an interface and scope that fit the job

There is no single safe configuration for every database and agent platform. Use these choices to assess a design:

Design choice Narrower boundary Broader or riskier boundary
Enforcement Database grants and policies, reinforced by server-side authorization A prompt or tool description with no independent enforcement
Data scope Curated views, selected objects, and user- or tenant-filtered rows Whole-database visibility without a task need
Agent interface Narrowly typed, task-specific query tools or APIs Unrestricted arbitrary SQL as the only boundary
Identity Distinct, attributable identity with a managed rotation or expiry process Shared, long-lived credentials or an administrator identity
Write escalation No write path, or a separate independently authorized workflow Read and write capability bundled into the same agent identity
Visibility Reviewable access, policy changes, and operation records Untracked grants and tool behavior

The exact controls depend on the database and agent platform. Start with the permission boundary the database can enforce, then make trusted application code validate each tool operation and keep the agent’s readable data as limited as the task allows.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.