Skip to main content

aegis.guard()

The core method. Evaluates an AI agent action against all registered guardrail rules, logs an immutable audit event, and returns a decision.


Signature​

await aegis.guard(options: GuardOptions): Promise<GuardResult>

Parameters — GuardOptions​

ParameterTypeRequiredDescription
actionstring✅The action name. Use a consistent naming convention: send_email, execute_query, http_request.
payloadobject✅The full data payload for this action. This is logged in full.
agentIdstring✅Identifier for the agent. Used for filtering in the dashboard.
userIdstring—The user or session ID that triggered the agent.
tagsobject—Key-value metadata tags. Useful for filtering by team, feature, or risk level.

Return Value — GuardResult​

FieldTypeDescription
approvedbooleantrue if the action is safe to proceed.
auditIdstringUnique ID for this audit event.
reasonstring?Block reason from the matching rule (only present when approved: false).
matchedRulestring?Name of the rule that fired.
timestampstringISO 8601 UTC timestamp.
latencyMsnumberTime taken for rule evaluation, in milliseconds.

Example​

const result = await aegis.guard({
action: 'execute_query',
payload: {
query: 'DELETE FROM users WHERE last_login < NOW() - INTERVAL 1 YEAR',
database: 'prod-postgres',
},
agentId: 'db-cleanup-bot',
userId: 'admin_user_01',
tags: { team: 'data-engineering', risk: 'high' },
});

if (result.approved) {
await db.execute(result.payload.query);
} else {
logger.warn({
message: 'Agent action blocked',
auditId: result.auditId,
rule: result.matchedRule,
reason: result.reason,
});
}

Latency​

Rule evaluation happens synchronously in-process. For typical rule sets (< 10 rules, no async DB lookups), evaluation takes < 5ms. The audit event is shipped to the Auditail API asynchronously on a background worker, with zero impact on your agent's response time.