The guardrails I put around every AI automation before it touches real customers: a short list of allowed actions, approval for anything risky, hard limits, actions that are safe to retry, a full log and an off switch.
An AI automation that answers questions is fairly safe: the worst case is a wrong answer. Once it can act (send emails, change bookings, issue refunds, update records), a wrong step costs money or a customer.
Most "the AI went rogue" stories aren't about the model being clever or malicious. They're about ordinary software problems: no limits, no approval step, a loop nobody noticed, a retry that ran something twice. These are the guardrails I build in from the start.
1. A short list of things it's allowed to do
The agent never gets general access to your systems. It gets a small set of named actions, each with a clear input schema, and anything else is refused.
import { z } from "zod";
const actions = {
sendReply: {
input: z.object({ conversationId: z.string(), text: z.string().max(2000) }),
risk: "low",
},
bookAppointment: {
input: z.object({ customerId: z.string(), slot: z.string().datetime() }),
risk: "low",
},
issueRefund: {
input: z.object({ orderId: z.string(), amountCents: z.number().int().positive() }),
risk: "high",
},
} as const;
Validating every call against a schema catches a surprising number of problems early: a missing ID, an amount in the wrong unit, a text far longer than any real reply.
2. A person approves anything risky
Each action has a risk level. Low-risk actions run straight away. High-risk ones (money, deleting data, messages to many people) become a pending request that a person approves or rejects.
async function run(name: keyof typeof actions, rawInput: unknown) {
const action = actions[name];
const input = action.input.parse(rawInput);
if (action.risk === "high") {
return createApprovalRequest({ name, input }); // shown in the dashboard, nothing happens yet
}
return execute(name, input);
}
The approval screen shows exactly what will happen and why the agent wants to do it. Over time you may move some actions to "low", but only once the approvals have been consistently right.
3. Hard limits the model can't talk its way past
Limits live in code, not in the prompt. A prompt that says "never send more than ten emails" is a suggestion; a counter is a rule.
- Steps per task: an agent that needs more than, say, 15 steps is probably stuck in a loop. Stop it and flag it.
- Actions per customer per day: no one should get five follow-ups in an afternoon.
- Spend: a daily cap on model and API costs, with an alert well before you reach it.
- Value: refunds or discounts above a set amount always need approval, whatever their risk level says.
if (task.steps >= MAX_STEPS) {
await flagForReview(task, "Step limit reached");
return;
}
4. Safe to retry
Networks fail and jobs get retried. If "send the confirmation email" runs twice, the customer gets two emails; if "issue refund" runs twice, you lose money.
Every action that changes something gets an idempotency key: a stable ID for "this action, for this task". Before running it, check whether that key has already succeeded.
const key = `${task.id}:${name}:${hash(input)}`;
if (await alreadyDone(key)) return; // retried, but it already happened
await execute(name, input);
await markDone(key);
I use the same idea for scheduled jobs in a backup queue: a failed job should be retried, never repeated.
5. Log everything, in plain language
For every task, store what triggered it, what the agent saw, what it decided, what it did and what came back. Write it so someone who isn't an engineer can read it, because the person asking "why did it send this?" usually won't be one.
Good logs turn a scary incident into a five-minute answer, and they show where the agent needs better information or tighter rules.
6. Make changes reversible where you can
Prefer actions you can undo: save a draft before publishing, keep the previous version before overwriting, cancel rather than delete. When an action can't be undone, that's a strong sign it should need approval.
7. An off switch
There should be one obvious way to pause the automation: per customer, per action and for everything. When something looks wrong, the first step is to stop it, not to debug it while it keeps running.
Test it before real customers see it
- Dry runs: run the agent on real past cases with actions recorded but not executed, and review what it would have done.
- Awkward cases: angry messages, missing information, requests outside your rules, someone trying to talk it into a discount.
- Prompt changes are code changes: keep a set of test conversations and rerun them whenever the prompt or model changes.
- Start in draft mode: for the first weeks, have a person approve everything and track how often they change it.
In short
Give the agent a short list of allowed actions, validate every call, require approval for anything risky, enforce limits in code, make actions safe to retry, log everything plainly, prefer reversible changes and keep an off switch within reach. None of this is exotic. It's the same discipline as any software that handles money and customers, applied to a component that is less predictable than most.
If you're planning an AI automation and want it built with these guardrails from day one, get in touch.