The first agent I shipped worked beautifully for about six hours. Then a vendor API started returning 500 errors, and the agent did the reasonable thing: it retried. Two hundred times. Each retry pushed the growing conversation history back through the model, so every failed attempt cost more tokens than the last. By the time I noticed, the run had chewed through a serious chunk of the monthly quota and produced nothing but an enormous log of identical failures.
Every agent builder I know has a version of this story. The demo works, real life hands the agent an edge case, and a missing guardrail turns a small hiccup into an expensive mess. Here are the seven mistakes that cause most of that damage — and the specific guardrail I now build in before writing any agent logic.
1. No Stopping Condition: The Infinite Loop
Agents don't get bored or embarrassed. If a task keeps failing and nothing tells them to quit, they retry forever — and every iteration re-sends the full history, tool output, and error message to the model. Loops start innocently: a rate-limited API, a page that changed its HTML, a file path that doesn't exist. The agent's logic is often sound (“try again”). It just never stops.
Guardrail: iteration caps and a repetition detector
- Hard cap per task. Ten to fifteen steps is a sane default; treat hitting the cap as a failure, not a pause.
- Repetition detection. Same tool call with the same arguments twice in a row? Break the loop and surface the error.
- Per-run budgets. Cap tokens and wall-clock time for every run.
- Circuit breaker. Three identical failures in a row should halt the agent and notify you — not trigger attempt four.
2. Handing the Agent Master Keys
The fastest way to turn a bug into an incident is one API key with full write access to everything. I've reviewed setups where the same credential could read the production database, send email, and hit the payments API. The agent doesn't need most of that on its best day — and on its worst day, that's exactly what it will use.
Guardrail: scoped, read-only credentials
- One credential per tool, created specifically for the agent. Read-only by default; grant write access only to the two or three actions the workflow actually performs.
- Allowlist exact actions. “Create draft email” yes; “send email” no — until you explicitly decide otherwise.
- Separate keys per environment, so the dev agent physically cannot touch production data.
- Inject keys server-side at the tool layer. Never put credentials in prompts or let the agent pass them around.
3. No Human Checkpoint Before Irreversible Actions
Simple test: if you wouldn't let a new intern do it unsupervised, the agent shouldn't either. Deleting records, messaging customers, spending money, publishing content — these need a human in the loop until you have months of clean logs proving the agent handles them.
Guardrail: an approval queue for anything irreversible
- Classify every tool as reversible or irreversible. Irreversible ones go behind an approval step, no exceptions.
- Show a diff before approval — the