Skip to content
mentoor

Topic 3 of 5 · 4 min read

Read-only by default, write by exception

Goal: Convert an agent's tool set to read-only defaults with explicit, narrow write paths.

Start every agent with read-only tools, then add each write ability one at a time, as narrow as the job allows. Reading cannot corrupt anything. Writing can.

Check yourself · 1 of 3

What is the safest starting set of tools for a new agent that summarises support tickets?

Choose one answer

Why it matters

Most useful agent work begins with looking: reading files, searching tickets, querying a database, summarising a thread. Many tasks never need to change anything. A tool set that can only read has a small worst case, because the damage is limited to what the agent might see. A generic tool such as run_sql(query) or shell(command) has no such limit, since it can do whatever the account behind it can do. OWASP lists excessive functionality as a cause of agent harm: tools the task never needed.

How to do it

  1. List the tools the task needs and delete the rest. An agent that summarises tickets does not need an "edit ticket" tool.
  2. Prefer narrow tools over general ones. add_ticket_label(ticket_id, label) beats update_ticket(any_field), and both beat raw SQL.
  3. Back the read-only rule with the credential. A read-only database role, not a prompt saying "do not write". The database refuses the write even if the model tries.
  4. Add writes one by one. Each new write tool gets its own scope, its own test and a decision about approval.
  5. Offer a dry run. The tool returns what it would change, such as a diff or a count of rows, without doing it.
  6. Point writes at a copy first. A staging database, a branch or a sandbox folder. Promote the result after review.

Before and after

# Before: one tool that can do anything the connection can do
tools = [run_sql]            # connected as the app's admin user
# After: read tools by default, one narrow write behind a dry run
tools = [
    search_orders,           # SELECT only, read-only role
    get_order,
    propose_refund,          # dry run: returns the change, writes nothing
]

The refund itself happens only after a person confirms the proposal, through a separate path with its own limit.

What goes wrong

  • One universal tool. A shell or SQL tool replaces dozens of careful decisions with one open door.
  • Rules in the prompt only. "Never delete" is advice. Database permissions are enforcement.
  • Dry run that is not dry. A "preview" flag that still writes a log, sends a notification or locks a row. Test that nothing changes.
  • Staging that points at production. A copy that shares real credentials is not a copy.

Examples

From run_sql to three tools

A reporting agent had run_sql on an admin connection. It only ever ran SELECT.

tools = [
    sales_by_region,   # parameterised query, read-only role
    top_customers,
    export_csv,        # writes only to /tmp/reports
]

The worst case moved from "drop a table" to "read sales data the report already covers".

Dry run output

propose_refund(order=8841, amount=19.00) returns {"would_refund": 19.00, "order_total": 19.00, "applied": false}. A person sees exactly what would happen. The agent cannot apply it without a separate, approved call.

Key points

  • Begin with read tools only and add each write tool deliberately, one at a time.
  • Narrow, named tools are safer than a general shell or raw SQL tool.
  • Enforce read-only in the credential or role, not just in the prompt.
  • Dry runs show the planned change without making it, which lets a person check it first.
  • Run risky writes on a staging copy or branch, then promote after review.

Common mistakes

  • Giving a general shell or SQL tool when two narrow read tools would do.
  • Relying on "do not modify data" in the prompt while the connection can write.
  • Calling something a dry run without checking it truly changes nothing.
  • Pointing a "staging" agent at credentials that also reach production.

Check yourself · 2 of 3

Which approach actually enforces "the agent must not write to the database"?

Choose one answer

Check yourself · 3 of 3

A "dry run" mode for a delete tool should do which of these?

Choose one answer

Practice items, not counted towards your mastery.

Start here