Skip to main content

Guardrails

Guardrails are the rules that determine whether an AI agent action is allowed to proceed.

Auditail evaluates rules synchronously, in the order you register them, before any action executes. This means dangerous actions are blocked at the source — not logged after the fact.


Pre-built Rules​

Auditail ships with pre-built rules for the most common risk scenarios:

import { Auditail } from 'auditail-sdk';

aegis
// Block emails to external domains (require human approval)
.addRule(Auditail.rules.noExternalEmail())

// Block any SQL DELETE, DROP TABLE, or TRUNCATE
.addRule(Auditail.rules.noDataDeletion())

// Alert (but allow) when the agent makes an outbound HTTP request
.addRule(Auditail.rules.noExternalApiCalls());

Writing Custom Rules​

A rule is just a function. Return true to block the action.

import { Auditail, GuardrailRule } from 'auditail-sdk';

// Block any action involving production database credentials
const noProductionDbWrites: GuardrailRule = {
name: 'no-production-db-writes',
description: 'Blocked: direct writes to the production database are not permitted.',
condition: (opts) => {
const connString = opts.payload?.connectionString as string | undefined;
return connString?.includes('prod') ?? false;
},
action: 'block',
};

// Alert when the agent touches financial data
const alertOnFinancialData: GuardrailRule = {
name: 'alert-financial-data',
description: 'Alert: agent is accessing financial records.',
condition: (opts) => {
const table = opts.payload?.table as string | undefined;
return ['invoices', 'payments', 'transactions'].includes(table ?? '');
},
action: 'alert', // allows the action, but fires an alert
};

aegis.addRules([noProductionDbWrites, alertOnFinancialData]);

Rule Actions​

Each rule has an action that determines what happens when the condition triggers:

ActionBehavior
blockThe guard() call returns approved: false. Your agent should not proceed.
require_approval(Coming in full SDK) Pauses the action and sends a Slack/email notification for a human to approve or deny.
alertThe action is approved, but a notification fires. Use for monitoring, not blocking.

Rule Evaluation Order​

Rules are evaluated in registration order. As soon as a block or require_approval rule fires, evaluation stops and the action is denied.

alert rules do not stop evaluation — all alert rules will fire even if the action is eventually blocked by a later rule.


Async Rules​

Rules can be async — useful when you need to check an external permissions database:

const checkUserPermissions: GuardrailRule = {
name: 'check-user-permissions',
description: 'Blocked: user does not have permission for this action.',
condition: async (opts) => {
const userRole = await permissionsDb.getRole(opts.userId);
return userRole !== 'admin'; // block if NOT admin
},
action: 'block',
};

Best Practices​

  • Start with alert, then harden to block. Deploy alert rules first to understand your agents' behavior before blocking.
  • Be specific in descriptions. The description is logged in the audit trail and shown to your team in Slack alerts. Make it actionable.
  • Use agentId and tags for filtering. Tag actions by team, feature, or risk level so you can filter them in the dashboard.
  • Keep rules stateless. Rules run on every action — avoid expensive synchronous operations.