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:
- TypeScript
- Python
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());
from auditail import rules
aegis.add_rules([
rules.no_external_email(),
rules.no_data_deletion(),
rules.no_external_api_calls(),
rules.no_pii_in_logs(), # Alert when payload contains email/phone PII
])
Writing Custom Rules
A rule is just a function. Return true to block the action.
- TypeScript
- Python
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]);
from auditail import Auditail
from auditail.types import GuardrailRule, GuardOptions
# Block any action involving production database credentials
no_production_db_writes = GuardrailRule(
name="no-production-db-writes",
description="Blocked: direct writes to the production database are not permitted.",
condition=lambda opts: "prod" in str(opts.payload.get("connection_string", "")),
action="block",
)
# Alert when the agent touches financial data
def financial_data_condition(opts: GuardOptions) -> bool:
table = opts.payload.get("table", "")
return table in ["invoices", "payments", "transactions"]
alert_on_financial_data = GuardrailRule(
name="alert-financial-data",
description="Alert: agent is accessing financial records.",
condition=financial_data_condition,
action="alert",
)
aegis.add_rules([no_production_db_writes, alert_on_financial_data])
Rule Actions
Each rule has an action that determines what happens when the condition triggers:
| Action | Behavior |
|---|---|
block | The 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. |
alert | The 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 toblock. 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
agentIdandtagsfor 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.