Human-in-the-loop (HITL) is not a fallback for weak models. It is an architectural layer for any agent that touches external systems. The question is not whether to add a human checkpoint, but where to place it.
Start with a copy-paste approval gate. This module stores a proposed action as pending, authenticates the approver, and executes only after an authorized approval is recorded. It fails closed: if the caller cannot approve, nothing runs.
from dataclasses import dataclass from enum import Enum from typing import Optional from datetime import datetime, timezone class ApprovalStatus(str, Enum): PENDING = "pending" APPROVED = "approved" REJECTED = "rejected" @dataclass class PendingAction: id: str action: str # what the agent proposes to do payload: dict # exact arguments to execute requested_by: str # user or agent identity status: ApprovalStatus = ApprovalStatus.PENDING approved_by: Optional[str] = None approved_at: Optional[datetime] = None idempotency_key: Optional[str] = None def approve_and_execute( draft: PendingAction, approver_id: str, can_approve: bool, executor, ) -> str: if not can_approve: raise PermissionError("This identity cannot approve outgoing actions") if draft.status is not ApprovalStatus.PENDING: raise ValueError("This action is no longer pending") if draft.idempotency_key and already_executed(draft.idempotency_key): raise ValueError("This action has already been executed") draft.status = ApprovalStatus.APPROVED draft.approved_by = approver_id draft.approved_at = datetime.now(timezone.utc) log_audit(draft) # append-only: who, when, what return executor(draft.payload) Key rule: approval is a trusted application event bound to a user identity and timestamp, not a model-generated statement that "the user approved."
Place the gate by impact, reversibility, and who is affected
Do not ask for approval just because the system can. Sort actions into three buckets using impact and reversibility:
- Low impact, reversible. Read-only search, a private draft, tagging a ticket. Let it run without interruption; the user reviews the result naturally.
- Medium impact, hard to fully reverse. Sending an email, posting publicly, replying to a customer. Use a draft-and-review step, especially for sensitive cases.
- High impact, irreversible. Deleting data, canceling services, issuing refunds, changing account access, making financial commitments. Keep a human approver in the loop for a long time; the agent prepares the option but does not pull the trigger.
Risk is not only about the action itself. Consider who is affected, how quickly errors can be corrected, and whether the user reasonably expects the agent to proceed.
Design the approval request, not just the button
A checkpoint is not a yes/no button. It is the right information at the moment of decision, so the reviewer can judge in seconds instead of re-investigating from scratch. Show the person:
- What the agent proposes to do.
- Which data or source informed the recommendation.
- What will happen if they approve.
- Whether the action can be undone.
- What alternatives are available.
Instead of "Approve action?", show: "Send this reply to customer A about order 4821. It offers a replacement under the delayed-shipment policy. The message will be sent from the support inbox." The person should be able to inspect or edit the draft before approval.
Avoid approval fatigue
Approval fatigue is a real failure mode. When reviewers click through hundreds of low-stakes actions, the one risky item sails through because it looked like the other ninety-nine. Fewer, meaningful checkpoints beat many trivial ones.
Use deterministic rules. Filter by dollar amounts, data sensitivity levels, or confidence thresholds to decide which actions need human review. Do not rely solely on the model's self-reported confidence score, which can be hallucinated. Combine model signals with hard-coded business rules. Reviewers must be able to edit, reject, or take over a task rather than merely approve or block it.
Persist the approval state
You cannot rely on the LLM's context window to remember whether a user approved an action. Store the proposed action as pending in a database, and execute it only after an authorized approval is recorded. The audit trail must be append-only and tied to a specific identity and timestamp.
Prevent time-of-check to time-of-use bugs: if a draft changes after approval, require a new approval. An agent must not be able to modify a payload between the human's review and execution.
Human approval does not replace security controls
Approval is one layer in a larger design that also includes authentication, authorization, validation, and monitoring. Authenticate approvers, check authorization scopes, bind approval to the exact content, and maintain an audit trail. These checks live in application code and trusted services, not in prompts. A prompt can explain the workflow to the model; it cannot enforce a permission boundary.
How this differs from related agent-safety posts
This series has covered permission hooks that fail on exit codes, read-only role guards that are not walls, and unattended-run deny rules. This post addresses a different layer: where to place the human approval point in the workflow, how to make the approval state durable and idempotent, and how to keep approvals meaningful instead of ceremonial.
Before you ship: a short checklist
- [ ] Every outbound action has an impact/reversibility bucket assigned.
- [ ] High-impact actions require explicit human approval before execution.
- [ ] Approval state is persisted, not kept in the model context window.
- [ ] The audit trail records who approved, when, and what exact payload ran.
- [ ] Changing a payload after approval forces a new approval (TOCTOU guard).
- [ ] Approvers can edit, reject, or take over. They must not just click through.
Worked example: a customer refund request
A support agent drafts a refund for order 4821. The refund is $120, reversible within 30 days, but it touches money and an external customer. Bucket: medium impact, hard to fully reverse.
The gate should present: "Refund $120 to customer A for order 4821, paid by card, reason: delayed shipment. Funds return to the original card within 5–10 business days. Cannot be recalled after the batch settles at 22:00 UTC." The reviewer can edit the amount or reason, approve, reject, or take over and process manually.
The system records: who requested it (agent identity), who approved it (support lead ID), when (timestamp), and the exact payload (order ID, amount, payment method). If the agent changes the amount after approval, a new approval is required before execution.
Reject, expire, and idempotency
Approval is not a one-time yes. Three behaviors belong in every gate:
- Reject with reason. A reviewer who rejects must record why, so the agent (or a later human) does not resubmit the same bad action blindly.
- Approvals expire. An approval id must match an unexpired approval record at execute time. A stale approval must not unlock an action days after it was granted.
- Idempotency. Hash the exact arguments at preview time and check the same hash at execute time. A retry or a changed id must not run something the human never saw. If the payload changed, require a new approval (time-of-check to time-of-use guard).
These rules live in application code and trusted services, not in prompts. A prompt can explain the workflow to the model; it cannot enforce a permission boundary.
Sources
- DEV Community, "Human-in-the-Loop Design: Where AI Agents Should Ask Before They Act," Nov 22, 2026 (main source; impact-reversibility matrix and Python pattern).
- Study Times, "Building a sound AI governance system," Nov 13, 2026 (cross-check: human retains final authority on key decisions).
- The Paper, Wang Ming on how AI agents reshape cybersecurity, Nov 2026 (cross-check: human-machine collaborative autonomy keeps high-risk approval nodes).
This post was written with AI assistance. The author is responsible for its content.
