AI loops on rails

Build AI loops you can actually ship.

The best engineers have stopped writing one-off prompts and started writing loops: systems that prompt an agent, check the output, and decide the next step until the work is done. LoopRails is rails for those loops in two senses. Like Ruby on Rails, it gives you conventions and a working scaffold so you build a loop fast. Like guardrails, it keeps the loop safe to run unattended, with a human at the decisions that actually matter. Fast to build, safe to run.

Start with this one rule: asking a person to click Approve does not turn them into a reliable error-catcher. Approval prompts stop some bad actions, but they barely improve a human's odds of noticing a bad one. When a human can't realistically catch the mistake, prevent the action instead of reviewing it. A-17
agent · on the rails

RAIL · Reversible · Authorized · Interruptible · Logged

Free download · the LoopRails Kit

Get the 5 templates for shipping a guarded loop

Enter your email and I'll send you the LoopRails Kit: the fill-in templates that take an agent loop from idea to safely running, plus the one-page cheat sheet. New essays on loop engineering after that.

No spam. Unsubscribe anytime. The templates are also free to read on the Kit page.

The core idea

Most oversight breaks down in one corner.

Two questions decide how to oversee any action: how bad it is if the action goes wrong (the consequence), and whether a person can actually catch and stop the mistake in time (the controllability). The hardest corner is high consequence plus low controllability, where asking a human to review just gives you a rubber stamp. Tap a corner to see what to do.

Consequence → Controllability →
Review is a trapHigh stakes · a human can't catch it in time
Review pays offHigh stakes · a human can catch it in time
Let it runLow stakes · a human can't add much
Light touchLow stakes · easy to catch and undo
Danger zone

Review is a trap: prevent, don't review

When the stakes are high but a person can't reliably catch the mistake in time, a confirmation prompt only produces a rubber stamp, and a scapegoat when it goes wrong. So don't rely on review. Prevent the bad outcome: make the action reversible, limit how far the damage can spread (the blast radius), run it in a sandbox (an isolated, contained environment), force a deliberate decision, or block the action and hand it to someone who can decide.

Do: Sandbox-First · Capability Lock · make it reversible · escalate

The failure gallery

The common ways human oversight fails, and how to fix each one.

These failures are real and well-documented, in aviation, medicine, finance, and 2026 studies of AI coding agents. Each card shows what goes wrong and the design change that prevents it. Press “See the fix” on any card.

The method

Four steps: Grade · Guard · Show · Prove.

Apply these to each action your agent can take, not to the system as a whole. They double as four questions for standup: Did we grade this action? How is it guarded? What do we show the person reviewing it? Have we checked the oversight actually works?

STEP 1

Grade

Rate each action by how far harm could spread, whether it can be undone, and how bad it is if wrong. That gives a grade from G0 (trivial) to G3 (critical).

STEP 2

Guard

Match the controls to the grade. Where a person can't realistically catch the mistake in time, prevent the bad outcome instead of asking them to review it.

STEP 3

Show

Design the review moment well: make the action and its consequences clear, show where the request came from, help the person spot problems, and don't spend more of their attention than the action is worth.

STEP 4

Prove

Test whether people actually catch errors, not just whether a review step exists. Attack your own oversight the way you'd attack the agent.

Try it · about 20 seconds

Grade an action.

Answer four questions about an action your agent is about to take. LoopRails gives you its grade, the right level of control, and a warning if asking a human to review it would just be a rubber stamp.

New to it? Tap a real example to load it into the grader ↓
Fully reversible
Recoverable with effort
Can't be undone
Just me / local
My team / shared systems
Customers / the public
Trivial
Meaningful
Severe
Yes
Not sure
No
,
Consequence grade
Answer the four questions →
Recommended control
,
Patterns to reach for
,
⚠️ Don't rely on review here. The stakes are high, but a person can't reliably catch the mistake in time, so a review step would just be a rubber stamp. Prevent the bad outcome instead.
The four properties to keep

Keep every governed action on the RAIL.

RAIL is a checklist of four properties any well-governed action should keep: Reversible, Authorized, Interruptible, Logged.

R

Reversible

You can undo it, or the damage is contained. Save hard stop-and-ask gates for the few actions that truly can't be undone.

Read in depth →
A

Authorized

The agent has only the permissions it needs for this grade, no more. For high-stakes actions, whoever proposes the action isn't the one who approves it.

Read in depth →
I

Interruptible

Anyone can stop it, a teammate, an automated monitor, even the end user, and a single kill switch halts everything at once, no questions asked. Make stopping cheap and blame-free so people actually do it.

Read in depth →
L

Logged

It leaves a record you can inspect later, so you can prove the oversight actually catches mistakes, not just that it exists.

Read in depth →
Make it concrete

Map LoopRails onto the tools you already use.

The method is tool-agnostic, but the controls are real settings. Here's where each step lives in common agent platforms, so "prevent, don't review" becomes a specific switch to flip, not a slogan.

Platform Grade decide what to gate Guard prevent / sandbox Interrupt stop it in time Log prove it
Claude Code Permission rules allow/ask/deny per tool; gate by risk in hooks A-2 Sandboxed bash, no-network containers, plan mode; /rewind checkpoints undo covers edits, not bash side-effects A-4 Esc interrupts mid-run; kill the session Session transcript; a hook can log every tool call
Cursor Command allowlist + auto-run toggle the denylist is a UX affordance, not a boundary A-14 Run in a devcontainer/sandbox; keep auto-run off for writes & shell Stop button; revert through git Lean on git history as the audit trail
GitHub Copilot agent Tool/command approval prompts; org & repo policies Runs in an ephemeral Actions sandbox; PR review before merge is built-in maker-checker Cancel the workflow run Actions logs + PR & commit history
Bedrock Agents + Guardrails Action groups with require confirmation; Guardrails policies per topic/PII IAM least-privilege on action Lambdas; VPC isolation; Guardrails block denied content Stop the invocation; disable the agent alias CloudTrail + CloudWatch model-invocation logging
LangGraph / LangChain interrupt() before chosen tool calls; route by risk in the graph A-8 Checkpointer gives durable pause/resume + a human-approval node; run tools in sandboxed executors Interrupt and don't resume; cancel the run LangSmith tracing + checkpoint history
n8n Toggle Human review per tool (v2.6+), gate high-risk tools (send / modify / delete), auto-run the rest Scope each tool's credentials; isolate the instance the gate is approve/deny, so prevent irreversible actions, don't just review Workflow pauses for approval via Slack / Telegram / Chat; Deny cancels; stop the execution Per-execution run history

Platform features as of mid-2026 and they change often, verify against current docs. The pattern that survives every release: a denylist of commands is not a sandbox A-14.

A shared vocabulary

Patterns to use, and anti-patterns to avoid.

Named designs you can point to in a meeting, most borrowed from industries that have already learned these lessons the hard way, plus the recurring mistakes you want to be able to name and stop.

✓ Patterns to use

✗ Anti-patterns to avoid

Where do you stand?

Score your oversight maturity.

Five questions, about a minute. You'll get a level from 0 to 4, and the single change that would move you up fastest.

,
Maturity level
Answer the five questions →
Take it with you

Drop LoopRails into your workflow.

Copy-paste artifacts so the framework leaves this page with you, one for your agents, one for your pull requests, one for the wall.

Read as much as you need

Practical at the top, fully sourced underneath.

Three levels of depth, each one click away. Start with the playbook; follow the citations as far down as you want to go.

Loops on rails, in both senses

Build your agent loop end to end

The loop is the unit of work now. LoopRails helps you build one the way Ruby on Rails made web apps fast, with conventions and a working scaffold, and it gives you the guardrails to run it unattended without getting hurt. Start with the principles, grab the starter, keep the templates close. The patterns here are grounded in research, collected in the Loop Engineering Codex.

Define Build Verify Grade Guard Run Learn

Build the loop (Define, Build, Verify), then keep a human at the end (Grade, Guard, Run, Learn). The grade is the hinge that lets a loop be fast and safe at once.

Start here

What is loop engineering?

From prompts to context to harnesses to loops, and why the verifier is the hard part.

Read →
Build

Build your first agent loop

Goal and done-conditions, the verifier, memory in a file, subagents, and guardrails on by default.

Read →
Recipes

Loop patterns for engineering & data science

Test-fixing, refactor, data-cleaning, and experiment loops, each with a done-condition and a verifier.

Read →
The verifier

Evaluation-driven development

An automated check, not your gut, decides whether each change improved things.

Read →
The verifier

What makes a verifier work

The research on verification functions: the strength spectrum, reward hacking, and whether the verifier replaces the spec.

Read →
Intent clarity

The two loops

An inner loop converges on the verifier; an outer loop clarifies intent. How loop engineering closes the delivery gap without waterfall.

Read →
Evidence

Agentic loops in the wild

Real wins and failures, with the numbers: DeepSeek-R1, AlphaCodium, o3, SWE-agent, and reward hacking. The verifier and the cost.

Read →
Context

Context engineering for loops

What goes in the window each turn, and how to keep a loop effective instead of drifting.

Read →
Context

MCP & skill overload

Every tool and skill you connect spends context and lowers accuracy. How many is too many, backed by research.

Read →
The model

World models: simulate before you act

Predict what an action will do before the loop commits to it, as a preview, a planner, and an offline eval.

Read →
Scale

Multi-agent loops

When more agents help, when they just add failure surface, and the oversight each one needs.

Read →
The model

LoRA vs fine-tuning vs pre-training

How to adapt the model under your loop, and when each option is worth the cost.

Read →
The model

Models you don't control

What you can and can't change on a closed API model versus an open-weight one.

Read →
Guardrails

Keep a loop on the rails

Grade what the loop can do, cap the blast radius, and stop it when it runs away.

Read →
Run & observe

Loop health: what to monitor

Turns, spend, score trend, and the signals that trip the circuit breaker.

Read →
Run & observe

Failure recovery

Retries, rollback, checkpoints, and resuming a crashed run, from durable execution and agent research.

Read →

See all articles →

The Cookbook

Patterns for agents and RAG, with the failure modes

The recipe side of LoopRails. The ways to design an agent and design RAG, in plain English, each recipe with the same four lines: what it is, when to reach for it, how it fails, and how to fix it. Open the Cookbook →

Articles

Read up on human-in-the-loop & AI agent safety

Practical, sourced deep-dives on overseeing AI agents, what to gate, what to prevent, and how to make oversight actually work.

See all articles →

Pairs with

LoopRails handles oversight. BRACE secures the agent itself.

LoopRails decides how much human oversight each action needs. The BRACE Framework is its security counterpart, practical controls for the agent's configuration and infrastructure (nine controls plus three observability requirements). Use them together: oversight design on top, a security baseline underneath.

Explore the BRACE Framework ↗
FAQ

Human-in-the-loop & AI agent oversight, common questions

What is human-in-the-loop (HITL) in AI?

Human-in-the-loop (HITL) means a person reviews, approves, or can intervene in an AI system's actions before or while they take effect. For AI agents it usually appears as an approval prompt before a risky action, an edit/review step, or an interrupt-and-resume control. LoopRails argues the key question isn't whether a human is "in the loop," but whether they can realistically catch a mistake in time. Read the full guide →

Does human-in-the-loop actually improve AI safety?

Not automatically. In a 2026 study of AI coding agents, requiring plan approval reduced risky actions, but humans still caught a bad action only ~9-26% of the time. An approval click stops some mistakes but barely improves a person's odds of noticing one. Real AI safety comes from matching the control to the action and preventing outcomes a human can't catch. See the evidence →

When should an AI agent require human approval?

When the action is high-consequence and a human can realistically catch the mistake in time. If the stakes are high but a person can't catch it, because it's too fast, too subtle, or too frequent, an approval gate becomes a rubber stamp. In that case, prevent the action instead: make it reversible, sandbox it, or cap its blast radius. Grade an action →

What's the difference between human-in-the-loop and human-on-the-loop?

Human-in-the-loop means the person is part of each action (review/approve before it proceeds). Human-on-the-loop means the system runs autonomously while a human monitors and can intervene or stop it. LoopRails treats the human as the escalation tier and reserves in-the-loop approval for actions where review genuinely catches errors. Compare the modes →

How do you design human oversight for autonomous AI agents?

LoopRails uses four steps: Grade each action by consequence (G0-G3), Guard it with controls that match the grade, Show the reviewer the real action and consequences (not a tidy summary), and Prove the oversight catches seeded errors. Every governed action should stay Reversible, Authorized, Interruptible, and Logged (RAIL). Read the framework →

What is the "lethal trifecta" for AI agents?

The lethal trifecta is when an AI agent has all three of: access to private data, exposure to untrusted content, and a way to send data out. Together they enable data exfiltration via prompt injection. Removing any one leg, for example, making the agent read-only or cutting its network access, is the cheapest guardrail. How it works →

Is LoopRails free?

Yes. LoopRails is a free, openly published framework with a practitioner playbook, the full method, and a 366-source research codex covering human-in-the-loop, AI safety, and human-factors research.