# Policy as code for AI agents explained | Kaba Digital Inc.

> What policy as code means for AI agents, a simple way to structure the rules, and how to test them. A starting point before the hands-on lab.

Source: https://kabadigitalinc.com/blog/policy-as-code-for-ai-agents-explained/

[← All posts](https://kabadigitalinc.com/blog/)

# Policy as code

October 8, 2026 · Concepts · 2 min read · Kaba Digital Inc.

An AI agent decides what to do and then does it by calling tools. That second part is where trust matters: the agent can send a message, change a record, or spend money. **Policy as code** means writing down what the agent is allowed to do as ordinary code, so the rules are visible, reviewed, and tested like the rest of your software.

## The idea in one sentence

Between “the model decided to call a tool” and “the tool runs”, you put a small piece of code that looks at the request and answers one of three ways: **allow**, **ask a person**, or **block**.

## A simple structure

1. **List the tools** the agent can call, and what each one can change.
2. **Classify each action** by how reversible and how sensitive it is. Reading is usually safe. Sending, deleting, and paying are not.
3. **Write the rules** next to the tools, in code: for example, “block any delete”, “ask a person above a certain amount”, “allow reads”.
4. **Log every decision**, including the ones that were allowed, so you can replay what happened.

## Why code and not a prompt

Instructions in a prompt are suggestions. A model can ignore them, misread them, or be talked out of them. A rule in code runs every time, in the same way, and can be tested. Prompts still help the model behave well, but the hard limits belong in code.

## How to test it

Write tests that describe the rules in plain terms: this request must be blocked, this one must ask a person, this one is allowed. Run them whenever the rules or the model change. If a test fails, you know before a user finds out.

## Try it yourself

This is the idea behind our [policy as code lab](https://kabadigitalinc.com/labs/policy-as-code-for-ai-agents/), where you build and test a policy from a starter template. The tutorial above is general guidance. It is not legal, security, or compliance advice.

## An idea worth building?

Bring the problem, the insight, and the ambition. Let’s figure out what we could build together.

[Start a conversation ↗ ](https://kabadigitalinc.com/contact/)
