Guardrails for AI Agents: Permissions, Validation and Human-in-the-Loop

Keep AI agents safe in production: permission tiers, input and output validation, budgets, sandboxes, approvals for risky actions, and audit logs.

Published December 1, 2026

An agent that can call tools can do real damage: refund the wrong order, email the wrong customer, delete the wrong file. Guardrails are the controls that keep an agent's actions within acceptable bounds even when the model makes a mistake or is manipulated. They are mostly ordinary software engineering, applied deliberately around the agent loop.

The concept

Start by classifying tools by risk. Read-only tools (search, fetch, query with a read-only role) can usually run automatically. Reversible writes (draft a reply, create a branch) may run automatically with logging. Irreversible or externally visible actions (send email, issue refund, deploy, delete) should require explicit human approval, at least until the agent has a strong track record.

Then add deterministic checks the model cannot talk its way around: schema validation of tool inputs, allow-lists and limits (refunds under ₹2,000, only these recipients), budgets on steps, tokens and money, sandboxes for code execution, and an audit log of every action. Model-based checks (a second model reviewing output) are useful but should complement, not replace, hard limits.

Permission tiers

TierExamplesPolicy
Read-onlysearch_docs, get_order, run_selectAuto-run, logged
Reversible writecreate_draft, add_label, open_branchAuto-run with limits
Irreversible / externalsend_email, refund, deploy, deleteHuman approval required
Forbiddenchange permissions, access secretsNot exposed to the agent

An approval flow

validateover limitnotifyModel proposesrefund ₹12,000Schema + policy checklimit ₹2,000Escalateneeds approvalHuman decidesapprove / deny
Deterministic checks route risky actions to people.

Where guardrails go

Input guardrailsPII detection, injection screening, topic limitsTool guardrailsschemas, allow-lists, limits, tiersExecution guardrailssandboxes, timeouts, budgetsOutput guardrailsformat validation, policy checks, citationsOversightapprovals, audit logs, monitoring
Guardrails at each stage of the loop.

Practical examples

Policy check before executing a tool

Code, not prompts, enforces limits.

def execute(call, user):
    spec = TOOLS[call.name]
    args = spec.schema.validate(call.arguments)            # raises on bad input
    if call.name == "issue_refund" and args.amount_paise > 200_000:
        return queue_for_approval(call, user, reason="over auto-refund limit")
    if spec.tier == "external" and not user.approved(call):
        return queue_for_approval(call, user)
    audit.log(user.id, call.name, args)
    return spec.run(**args)

Run generated code in a sandbox

No network, limited CPU, memory and time.

docker run --rm --network none --memory 512m --cpus 1 --pids-limit 128 \
  --read-only -v "$PWD/job:/job:ro" python:3.13-slim timeout 30 python /job/script.py

Structured output validation

Reject malformed responses before they reach users or systems.

from pydantic import BaseModel, Field
class TriageResult(BaseModel):
    category: str = Field(pattern="^(billing|technical|account)$")
    priority: int = Field(ge=1, le=4)
    summary: str = Field(max_length=280)
result = TriageResult.model_validate_json(llm_output)

Common mistakes

  • Relying on the system prompt ("never refund more than X") instead of code-enforced limits.
  • Giving the agent the same credentials as an admin user.
  • Approval prompts so frequent that users approve without reading.
  • No audit trail of what the agent did and why.

Key takeaways

  • Classify tools by risk and gate irreversible actions behind approval.
  • Enforce limits in code: schemas, allow-lists, budgets.
  • Sandbox code execution and scope credentials narrowly.
  • Log every action for audit and improvement.

FAQ

Do guardrails make agents less useful?

Good guardrails let you give agents more capability safely. Start strict, measure, then relax limits where the agent proves reliable.

Are guardrail libraries worth using?

They help with common checks like PII detection and schema validation, but business limits still belong in your own code.

How do I reduce approval fatigue?

Batch approvals, show clear diffs or summaries, and auto-approve low-risk actions so humans only see what matters.

More AI articles