Back to blog
Guide · Guard

Database Guardrails for AI Agents: How to Prevent Unsafe Writes Before They Run

Learn how database guardrails for AI agents prevent unsafe INSERT, UPDATE and DELETE operations. See how Claix Guard checks proposed writes against approved business rules.

Claix · Updated November 2026. Related guides: AI agents database access permissions (/blog/ai-agents-database-access-permissions), why direct SQL access is dangerous (/blog/why-ai-agent-direct-sql-access-is-dangerous), Claix Guard vs open-source guardrails (/blog/claix-guard-vs-open-source-ai-agent-guardrails), and SQL guardrails in five minutes (/blog/sql-guardrails-5-minutes-claix-guard). Product: Claix Guard.

AI agents are moving from answering questions to taking actions. They can create records, update orders, change inventory, issue refunds or modify customer information.

That creates a new security problem.

A database permission can decide whether an agent is allowed to write. It cannot easily decide whether a specific write makes sense for your business.

This is where database guardrails for AI agents come in.

A guardrail checks what an agent wants to change before the change happens. It turns your business rules into an enforced boundary between the agent and your database.

This guide explains why AI agents need database guardrails, which risks they address, and how Claix Guard checks proposed writes before your code executes them.

What are database guardrails for AI agents?

Database guardrails for AI agents are rules that evaluate a proposed database change before it runs.

They sit between the agent and the code that executes the change:

  • The agent proposes an action.
  • A guardrail checks the proposed action against approved rules.
  • The executor runs the action only if it is allowed.
  • The system records the decision and the reason.

A guardrail does not replace database permissions. It adds a layer that can enforce business rules the database itself cannot easily express.

For example, a database can prevent a user from writing to a table. But it cannot naturally answer questions such as:

  • Can this agent create an order?
  • Can it update an order status?
  • Can it change the order price?
  • Can it delete an order?
  • Can it apply a discount above 20 percent?
  • Can it issue a refund above 200 euros?
  • Can it make more than five refunds in one hour?

Those are business rules. They depend on your product, your workflow and your risk policy.

Why prompts are not enough

You can instruct an agent not to delete records, change prices or issue large refunds.

But a prompt is not a permission system.

Instructions can be misunderstood. They can conflict with other instructions. They can be overridden by another part of the workflow. And they cannot reliably guarantee that an agent will follow them in every situation.

A prompt can guide behavior. It should not be the only thing standing between an agent and a production database.

Database guardrails make the boundary technical and explicit. The agent can propose an action, but it cannot decide by itself whether that action is allowed.

The risks of uncontrolled AI agent writes

When an AI agent can write to a database, several problems can occur.

A missing condition can affect too many records

An update or delete without a sufficiently specific condition can affect more records than intended.

A missing filter, an incorrect ID or a misunderstanding of the task can turn a small change into a broad one.

A valid value can still be wrong

A statement can be technically valid and still violate a business rule.

For example, an agent may be allowed to update an order, but apply a discount that your policy does not allow. The database accepts the value because it is valid. The business does not.

An agent can change data it should not touch

An agent may have permission to update an order, but that does not mean it should be able to change every field in that order.

It may be allowed to update a status, but not a price, an owner, a payment amount or a contract term.

An agent can perform too many actions too quickly

An agent can enter a loop or repeat an action multiple times. Without a rate limit, it could create many records, issue many refunds or trigger many updates in a short period.

An agent can make an action difficult to audit

If you only log the agent’s final response, you may not know what it proposed, which rule applied or why a change was allowed or denied.

That makes incident response much harder.

What database guardrails should control

A useful guardrail system should be able to control several dimensions of a proposed write.

ControlWhat it prevents
Operation typeUnwanted inserts, updates or deletes
Target tableChanges to tables outside the agent’s scope
Target columnsChanges to sensitive or protected fields
Record selectionUpdates or deletes that affect too many records
Value limitsDiscounts, quantities, amounts or statuses outside allowed ranges
State transitionsInvalid changes from one status to another
Rate limitsToo many changes in a short period
Human reviewHigh-risk actions that Guard denies so your workflow can route them for review
Audit trailMissing evidence of what was proposed and decided

These controls are complementary. Database permissions and constraints remain important, but they do not cover every business rule.

How Claix Guard works

Claix Guard is a rules checker for the database changes an AI agent proposes. Before an agent runs an INSERT, UPDATE or DELETE, Guard checks the proposed statement and its parameters against rules you approved.

The result is simple:

  • Allow: your code can execute the statement.
  • Deny: your code should not execute it, and the agent receives the reason.

There is no third verdict. If a change should be reviewed by a person, Guard denies it and your own workflow routes that denial for review.

Claix Guard does not execute the statement. It does not touch your data. Your own code executes the change using its own database credentials.

That separation matters. The agent proposes. Guard decides. Your executor enforces.

The four-step workflow

Claix Guard follows a clear workflow.

1. Define rules in plain English

You describe a limit the way you would explain it to a colleague.

For example:

  • “Agents can create and update orders, but never delete them.”
  • “Agents can update an order status, but never its price.”
  • “Discounts cannot exceed 20 percent.”
  • “Refunds above 200 euros are denied so a person can review them.”
  • “No more than five refunds per hour.”

Claix turns that description into a proposed exact rule. You can accept, reject or edit it before it becomes active.

2. The agent proposes a change

When an agent wants to create, update or delete data, it sends the proposed statement and its parameters to Guard.

Guard receives the proposed action before execution.

3. Guard applies the approved rules

Guard checks the proposed statement against the active rules for that database connection.

The check is deterministic. The same statement with the same parameters receives the same decision. No AI model decides at check time.

4. Your code executes only if allowed

If Guard returns allowed, your executor can run the statement.

If Guard returns denied, your code should not run it. The response includes a reason that the agent can use to correct the action and try again.

What Claix Guard can enforce

Claix Guard can enforce rules across several dimensions.

Allowed operations

You can define which operations an agent can perform.

  • Agents can create and update orders.
  • Agents can never delete orders.
  • Agents can update inventory, but not delete inventory records.
  • Agents can update CRM deal status and notes, but not deal ownership.

Allowed columns

You can restrict which columns an agent can modify.

  • An agent can update an order status.
  • It cannot update the order price.
  • It can update customer contact details.
  • It cannot change salary or contract information.

Required record selection

You can require that an update or delete targets a specific record.

  • An update must identify a single order by its ID.
  • A delete must not affect an entire table.
  • A change must include the conditions needed to identify the intended record.

Value limits

You can define limits for values an agent can write.

  • Discounts cannot exceed 20 percent.
  • Quantities must be above zero.
  • Order totals cannot exceed a defined maximum.
  • Status values must belong to an approved list.

State transitions

You can define which transitions are valid.

  • An order can move from pending to shipped.
  • It can move from shipped to delivered.
  • It cannot move backwards from delivered to pending.

Rate limits

You can limit how often an agent can perform an action.

  • No more than five refunds per hour.
  • No more than a defined number of records created in a period.
  • No more than a defined number of updates for the same record.

Human review via denial routing

You can deny high-risk actions and route them to a person through your own workflow.

  • Refunds above 200 euros are denied by Guard.
  • Your workflow sends that denial to a reviewer.
  • The reviewer approves or rejects the request outside the automated path.

Why the check is deterministic

Claix Guard uses exact rules, not an AI model, to decide whether a proposed statement is allowed.

That has several practical benefits.

Predictable decisions

The same statement with the same parameters receives the same answer. There is no randomness or model interpretation in the check itself.

Explainable denials

When Guard denies a statement, it returns the reason. The agent can understand what went wrong and correct the action.

Testable rules

You can test rules against example statements before relying on them in production. This includes testing actions that should be denied.

Fast checks

There is no model call in the check path. A guardrail decision does not need to wait for another model to evaluate the statement.

Why Claix Guard does not execute writes

Claix Guard is intentionally a checker, not an executor.

It does not run your INSERT, UPDATE or DELETE. Your own code does, using its own credentials.

This design has an important consequence: Claix does not need write access to your database.

It also makes the responsibility clear:

  • The agent proposes the action.
  • Guard decides whether the action follows your rules.
  • Your executor performs the action only when it is allowed.

This is the separation you want in a production system.

Guardrails need an enforcement path

A guardrail only works if every write must pass through it.

If an agent can reach the database directly with write credentials, it can bypass Guard. The guardrail becomes optional.

The recommended pattern is:

  • Give the agent no write credentials.
  • Keep write credentials in one executor function in your code.
  • Make that executor call Guard before every write.
  • Execute the statement only if Guard returns allowed.
  • Return the denial reason to the agent when the answer is denied.

Claix Guard can check the action, but your architecture must ensure that the executor is the only route to the database.

How Guard complements database security

Claix Guard is one layer in a broader database security model. It does not replace the controls that already belong in your database.

LayerWhat it does
Dedicated database roleLimits what the executor can do
Narrow privilegesRestricts access to required tables and columns
CHECK constraintsEnforces basic data validity
Row-level securityHelps isolate records by user or tenant
Audit loggingRecords activity on your side
Claix GuardChecks proposed writes against approved business rules

Claix recommends keeping a dedicated role with narrow privileges, database constraints, row-level security where appropriate and logging alongside Guard. For controlled reads, use Claix Retrieve.

Examples of database guardrails

Support agent issuing refunds and discounts

A support agent may need to help customers with refunds and discounts.

You can define rules such as:

  • Discounts cannot exceed 20 percent.
  • Refunds above 200 euros are denied so your workflow can send them to a person.
  • No more than five refunds per hour.
  • Agents cannot delete orders.

Guard checks each proposed change before execution. If a proposed refund exceeds the threshold, it is denied and your workflow can send it to a person.

Sales assistant updating a CRM

A sales assistant may need to update deal information.

You can allow it to change status and notes, while preventing changes to the deal owner or the amount of a closed deal.

Operations agent managing inventory

An operations agent may need to adjust stock levels.

You can allow adjustments within a range, while denying deletions.

Internal HR assistant

An internal assistant may need to update employee contact details.

You can allow those updates while denying changes to salary or contract information, and routing those denials to a person through your own workflow.

How to add Guard to an existing agent

Claix Guard works with any agent framework, MCP client or automation tool that can send an HTTP request. See also the MCP docs.

The integration follows five steps:

  • Create a policy and write your first rules in plain English.
  • Review and approve the proposed exact rules.
  • Test the policy in the Sandbox, including actions that should be denied.
  • Call Guard before every write from your executor function or agent tool.
  • Execute only when the response is allowed; return the denial reason when it is not.

Every decision is recorded, so you can review what was proposed and why it was allowed or denied.

What Claix Guard does not do

Claix Guard is powerful, but it has clear boundaries.

  • It does not execute statements; your code does.
  • It does not replace database permissions or constraints.
  • It does not protect a database that the agent can reach directly with write credentials.
  • It checks writes, not reads; for controlled reads, use Claix Retrieve.
  • It cannot see everything that happens inside your database, such as triggers, so critical invariants should also live in the schema.

When should you use database guardrails?

Use database guardrails when an AI agent can propose changes to data that matters.

Common cases include:

  • Customer support agents issuing refunds or discounts.
  • Sales assistants updating CRM records.
  • Operations agents changing inventory.
  • Internal assistants updating employee data.
  • Automation workflows writing to business systems.
  • Multi-agent systems where several agents share the same database.

If an agent only reads data, start with controlled retrieval and read-only access. If it can write, add guardrails before it reaches production.

Frequently asked questions

What are database guardrails for AI agents?
They are rules that evaluate a proposed INSERT, UPDATE or DELETE before it runs. The agent proposes a change, a guardrail checks it against approved policies, and your executor runs it only when it is allowed.
Why are prompts not enough to control AI agent writes?
A prompt can guide behavior, but it is not an enforcement mechanism. Instructions can be misunderstood, overridden or manipulated. Technical controls should decide whether a write is allowed.
Does Claix Guard execute SQL?
No. Claix Guard only checks proposed statements. Your own code executes the statement with its own database credentials, and only after Guard returns allow.
Does Claix Guard use an AI model at check time?
No. A model may help propose exact rules during setup, but the runtime decision is deterministic. The same statement and parameters receive the same answer.
Can Claix Guard return “needs approval”?
No. Guard returns allow or deny only. For high-risk actions, Guard denies the write and your own workflow routes that denial to a person for review.
Which databases does Claix Guard support?
Claix Guard supports PostgreSQL, MySQL and MariaDB.
Do database guardrails replace database permissions?
No. Keep a dedicated role, narrow privileges, constraints, row-level security where appropriate, and logging. Guard adds the business-rule layer on top.

Conclusion

Database guardrails for AI agents turn business rules into an enforced boundary.

They do not replace database permissions. They add the layer that can answer questions such as:

  • Can this agent delete this record?
  • Can it change this column?
  • Can it apply this discount?
  • Can it issue this refund?
  • Can it make this change more than once?

Claix Guard checks every proposed INSERT, UPDATE and DELETE against rules you approve. It returns allow or deny with a reason, while your own code executes the change only when it is allowed.

If you are building AI agents that can modify production data, do not rely on prompts alone. Put a guardrail between the agent and the database.