guardrails
Safety mechanisms that constrain agent behavior: input validation, output filtering, action limits, budget caps, and human-in-the-loop checkpoints.
Syntax
ai-agents
validate(input) -> agent -> validate(output) -> execute_if_safe(action)Example
ai-agents
// Agent guardrails:
const safeAgent = {
maxCost: 1.00, // Stop if API cost > $1
maxSteps: 20, // Prevent infinite loops
allowedTools: ["search", "read_file"], // Whitelist only
bannedPatterns: [/rm -rf/, /DROP TABLE/], // Block dangerous actions
requireApproval: (action) => action.type === "write_file",
async run(task) {
if (!this.isAllowed(task)) throw new Error("Task blocked");
// ...
}
};