Dashboard

Should an AI Agent Have Write Access to Your Database?

Write access is safe for a business-data agent only with read-only defaults, table-and-column scoping, no raw SQL, an audit log, and human approval on anything destructive.

Carlo Zuercher
Carlo Zuercher
Staff Engineer, Platform
24 September 20261 min read

Giving an AI agent write access to your production database is safe only under specific conditions, and those conditions are stricter than what most teams actually ship. The short version: never grant an agent standing permission to run raw SQL. Give it read access by default, then a narrow, table-and-column-scoped write path through a constrained interface, with every write logged and anything destructive or irreversible routed through a human approval step first. Set up that way, an agent that updates customer records or runs a cleanup job is a manageable risk. Skip any of it and you are one bad prompt away from a deleted table.

Worth being precise about what this post covers. This is about a general-purpose automation or assistant agent that gets asked to touch business data, things like update this customer's billing address, merge these two duplicate leads, flag and correct these malformed entries. It is not about an AI coding agent that writes and ships application code. If your worry is a coding agent poking at your database while it builds a feature, the guardrails look different, see stopping a coding agent from touching your database during development. If your worry is a coding agent shipping code changes that reach production, that is covered separately in a coding agent shipping code changes that reach production. Both are legitimate concerns. This post is about a third one: a business agent with direct write access to live customer data, and how to scope that safely. For the bigger picture on where a decision like this fits, see our overview of AI risks.

What Write Access Actually Means Here

Write access is not one thing. It is a spectrum, and where an agent sits on it determines almost all of the risk.

  • Read-only, no writes at all. Lowest risk, but it means a human still does every update by hand.

  • Scoped write through an application layer: the agent calls a specific function or API endpoint that updates one field on one row type, with validation built in. This is the sweet spot for most business tasks.

  • Direct write to the database with a broad set of table permissions. Higher risk: the agent can touch fields nobody scoped for it, and a bug or a bad prompt can cascade.

  • Raw SQL execution privileges. This is the one to avoid categorically. An agent with a connection string and insert, update, and delete rights across the schema is not write access, it is standing production access with a language model in the loop.

The failure modes here are ordinary database failure modes, just triggered by a different kind of actor. A hallucinated or mismatched identifier updates the wrong row. A vague instruction like "clean up the test accounts" turns into a bulk delete nobody explicitly approved. Text a customer submitted, if it ever flows back into a prompt the agent uses to decide what to write, can carry instructions of its own. None of this requires the model to be malicious. It only requires it to be given more latitude than the task needed.

A Scoped-Permission Framework That Actually Holds Up

The practical version of least privilege for a business-data agent comes down to four defaults.

  • Read-only by default. Every new agent or integration starts here. Write access is something you add deliberately for a specific task, not something you leave open in case it is needed later.

  • Write access scoped to specific tables and columns, never the whole schema. An agent that updates shipping addresses does not also need write access to pricing tables or authentication records.

  • No raw SQL execution privileges, ever. Writes go through a constrained interface, a typed API endpoint or stored procedure that validates inputs and enforces business rules, so the agent cannot construct an arbitrary statement even if it wanted to.

  • Separate credentials from any human admin account, so the agent's activity is distinguishable from a person's in every log, and can be revoked without touching anyone's own access.

That constrained interface is the part teams skip most often, usually because it is more work than pointing an agent at a database connection string. It is also the single control that turns "an AI agent writes to production" from a frightening sentence into an ordinary engineering decision, the same one you would make for any external system or junior teammate.

Audit Logs and Human Approval for Anything Irreversible

Two more controls matter as much as the permission scope itself.

First, log every write the agent makes: who or what made it, when, which row, and the before and after values. This is not optional. Without it, you cannot answer what the agent actually changed after the fact, and that question always comes up eventually.

Second, decide in advance what counts as destructive or irreversible, and require explicit human approval before the agent can execute it. That list usually includes deletes, bulk updates affecting more than one row, anything touching financial or billing fields, and anything that cannot be trivially undone. For those actions, the agent's job is to propose the change, not make it. A person reviews a clear diff, the row, the field, the old value, the new value, and approves or rejects it. Everything else, the narrow, single-row, non-destructive updates the agent was explicitly scoped for, can run without a human in the loop, because the blast radius of a mistake is small and reversible.

A Minimal Setup You Can Actually Implement

  1. Put the agent behind a read-only connection first, for anything you are not certain about.

  2. Build a small, purpose-specific API or set of functions for the writes you do want to allow, each one scoped to a table and a handful of columns.

  3. Add input validation and business-rule checks to that interface, so it rejects bad writes regardless of who or what is calling it.

  4. Log every write with enough detail to reconstruct it later.

  5. Define your destructive-action list and gate it behind human approval before you turn the agent loose on anything else.

  6. Review the audit log on a schedule, not just when something looks wrong.

The same reasoning applies any time you are deciding how much access to hand an agent, not just for a database. If you are also weighing connecting an agent to your email inbox, the underlying question is identical: read-only or narrowly scoped by default, with a human check before it sends, deletes, or acts on your behalf.

Frequently Asked Questions

Is a read replica enough on its own?

A read replica solves the read problem, not the write one. If the agent only needs to look things up, a replica is a reasonable default. It does not help if the actual task requires writing, that still needs the scoped-interface approach above.

Does row-level security replace the need for a constrained interface?

Row-level security is a good complementary control, especially for limiting which rows an agent can see or touch by tenant or owner. It is not a substitute for a validated write interface, because it controls which rows a query can reach, not whether the query itself makes sense.

Should the agent have its own database user or service account?

Yes. A dedicated, narrowly scoped credential makes every write attributable to the agent specifically, makes the permission set auditable on its own, and means you can revoke or rotate it without touching any person's access.

What actually counts as "destructive"?

Deletes, any update touching more than one row, anything affecting billing or financial fields, and anything without a straightforward undo path. If you are unsure whether something belongs on that list, put it there. It is cheaper to add a human approval step than to explain an unapproved bulk update.

Does this apply differently to an internal tool versus a customer-facing agent?

The framework is the same either way. A customer-facing agent tends to have a shorter list of tasks it needs write access for, which makes scoping easier, not harder.

None of this requires exotic tooling. It requires deciding, before you connect anything, exactly what the agent is allowed to touch, building that boundary into the interface rather than trusting the prompt, and keeping a human in the loop for the handful of actions that cannot be undone.

How did this land?

About the author

Carlo Zuercher
Carlo Zuercher

Staff Engineer, Platform

Carlo works on the platform that turns prompts into running apps. He writes the engineering deep dives and the changelog notes worth reading.

Share

Get the next post in your inbox

One email a month. Product updates, engineering posts, and the best of Built with Swarmz.

I agree to receive emails about AI building tips and Swarmz product news. Unsubscribe any time.