Skip to main content

aegis.guard()

The core method. Evaluates an AI agent action against all registered guardrail rules, records a tamper-evident 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.
waitboolean—For require_approval rules: false returns immediately with pending: true instead of waiting for the human. Default true.

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 guard() took in milliseconds. Includes the wait when a human approval was required.
approvalobject?Present when a require_approval rule fired: id, status (approved, denied, expired, pending, unavailable), decidedBy, comment.
pendingboolean?true only with wait: false while the request awaits a human. approved is false until it is decided.

Example​

const payload = {
query: 'DELETE FROM users WHERE last_login < NOW() - INTERVAL 1 YEAR',
database: 'prod-postgres',
};

const result = await aegis.guard({
action: 'execute_query',
payload,
agentId: 'db-cleanup-bot',
userId: 'admin_user_01',
tags: { team: 'data-engineering', risk: 'high' },
});

if (result.approved) {
await db.execute(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 delivered to Auditail in the background (batched, retried, idempotent), so guard() never waits on the network. Call flush() before a serverless function returns.