Skip to content

AI ENGINEERING

Designing guardrailsfor AI agents.

AI agents can send emails, update records and move money. Here is a practical way to decide what an agent may do on its own, what needs a human's approval, and how to keep a record anyone can read.

  • Codesgenii team
  • 8 min read
  • 23 November 2026
On this page
  1. Why agents need guardrails
  2. Start with a permission table
  3. Approve by risk, not by habit
  4. Enforce limits outside the model
  5. Log for humans, not just machines
  6. Test the unhappy paths

Why agents need guardrails

A chatbot that gives a wrong answer is embarrassing. An AI agent that sends the wrong refund, emails the wrong customer or deletes the wrong record is expensive. The moment an AI system can take actions in your tools, you need clear rules about what it is allowed to do, and those rules have to live in code, not only in the prompt.

Start with a permission table

List every action the agent can take and give each one a rule: run automatically, run after approval, or never allowed. Write it down in a table that the business owner and the engineers both sign off. This table becomes the contract between your team and the agent, and it is the first thing we build on every agent project.

  • Automatic: read a record, look up an order, draft a reply
  • Needs approval: send an email to a customer, issue a refund, change a price
  • Never: delete data, change permissions, contact anyone outside an allowed list

Approve by risk, not by habit

Reading data is usually safe. Writing data, sending messages and spending money deserve human approval until the agent has proved itself on real cases. Once you have a few hundred approved actions with no corrections, you have evidence to move an action from approval to automatic.

  • Give each tool the smallest access it needs
  • Set hard limits on amounts, recipients and volume per hour
  • Ask for approval whenever the model's confidence is low
  • Stop and alert a person if the same action fails twice

Enforce limits outside the model

Never rely on the prompt alone to keep an agent safe. Prompts can be ignored, misread or manipulated by text the agent reads from an email or a web page. Put the real checks in the code between the agent and your tools: the API simply refuses a refund above the limit, whatever the model asks for.

Log for humans, not just machines

Record what the agent saw, what it decided, which tool it called and why, in a form a reviewer can read in seconds. Good logs make mistakes easy to fix, make audits painless, and give you the confidence to widen the agent's permissions later.

Test the unhappy paths

Before launch, try to break it. Feed it confusing requests, missing data, angry customers and messages that try to trick it into ignoring its rules. Every failure you find in testing is one your customers never see.

LET'S TALK

Have a problem worthsolving with software?

Tell us where you are and where you want to be. We reply within one business day. (placeholder)

Next step: discovery callYouDiscovery call