Human-in-the-Loop Routing: Send Each Agent Action to Auto, Review or Block by Confidence, Reversibility and Cost
A support agent proposes nine actions in one morning, from an order-status reply to a $900 wire refund. A router in code sends each one to auto, review or block using three signals: the model's confidence, whether the action can be undone, and what a mistake costs.
What you will learn
- Explain why model confidence alone is not a safe gate for agent actions
- Keep reversibility and cost of a mistake in a code table, not in the model's reply
- Write a first-match router that sends each proposal to auto, review or block
- Pick the auto threshold from reviewed outcomes and see how it moves the review queue
Before you start
- When a human must review AI output
- Python dataclasses
- Claude tool use basics
Picture a support agent that can do three kinds of things: answer a question, credit an account, or send a wire refund. Should every one of those run on its own? Clearly not. Should a person check every one? Also no, or the queue fills with easy cases and the one that matters slips through.
So we route each proposed action by three things: how sure the model is, whether the action can be undone, and what a mistake costs. The rule of this whole lesson fits in one line: the model proposes, our code decides who looks.
If you want the background on why some outputs need a person at all, read when a human must review AI output first. This article is about the routing logic itself.
Nine proposals, nine different risks
Our example is a slice of a support desk. One morning, the agent makes nine proposals. Three of them show the spread:
- A reply with the order status. Cheap to correct if it's wrong.
- A credit of $240. Real money if the model got it wrong, but it can be reversed.
- A $900 wire refund. Once it's sent, nobody can call it back.
Check all nine and a reviewer spends the morning on easy ones. Check none and the wire goes out. Each proposal needs a different amount of attention.
Think of a bank counter with a manager in the back. The teller calls the manager for three separate reasons. The teller isn't sure it's the right customer: that's low confidence. A wire can't be recalled, so the manager signs first: that's reversibility. The amount is very large, so the manager signs or the bank declines: that's cost. Each reason is checked on its own. The small, sure cases the teller handles alone.
Where the router sits
A case comes in and the agent asks the model for one proposed action through a forced tool call. The model returns the action, its arguments and a confidence. The router takes that proposal and returns a decision. Then the lane acts: it runs the action, queues it for a person, or refuses it.
Only the confidence comes from the model. Whether an action can be undone, and what it costs if wrong, come from a table in our code. The project runs against a stand-in: the Anthropic SDK on an httpx mock transport with scripted replies, so no API key is needed and the confidence numbers are made up. They show the design, not a real model's calibration.
The facts about each action: actions.py
Start with what we know about every action. Each one is listed with whether it can be undone and how to work out what a mistake costs. A credit or a wire costs its own amount. Closing an account gets a fixed cost.
"""What we know about each action. It lives in code, not in the reply."""
from dataclasses import dataclass
@dataclass(frozen=True)
class Rule:
reversible: bool
amount_field: str = ""
fixed_cost: int = 0
ACTIONS = {
"reply_status": Rule(reversible=True),
"credit_account": Rule(reversible=True, amount_field="amount"),
"close_account": Rule(reversible=False, fixed_cost=30),
"wire_refund": Rule(reversible=False, amount_field="amount"),
}
def cost_if_wrong(action, args):
rule = ACTIONS[action]
if rule.amount_field:
return args[rule.amount_field]
return rule.fixed_cost
Notice where the cost comes from: the real arguments of the proposed call, read in code. We never ask the model how risky its own action is.
The router: policy.py
Now the router. The rules run top to bottom and the first one that matches wins. The numbers are example policy values from the project, not recommendations.
"""The router: auto, review or block. The first matching rule wins."""
from dataclasses import dataclass
from router.actions import ACTIONS, cost_if_wrong
# our example policy values
AUTO_MIN_CONFIDENCE = 0.90
BLOCK_BELOW_CONFIDENCE = 0.50
REVIEW_ABOVE_COST = 100
BLOCK_IRREVERSIBLE_FROM = 500
@dataclass(frozen=True)
class Decision:
route: str
reason: str
cost: int
def route(action, args, confidence, auto_min=AUTO_MIN_CONFIDENCE):
if action not in ACTIONS:
return Decision("block", "not an allowed action", 0)
rule = ACTIONS[action]
cost = cost_if_wrong(action, args)
if not rule.reversible and cost >= BLOCK_IRREVERSIBLE_FROM:
return Decision("block", "cannot be undone and costly", cost)
if confidence is None:
return Decision("review", "no confidence given", cost)
if confidence < BLOCK_BELOW_CONFIDENCE:
return Decision("block", "too unsure", cost)
if not rule.reversible:
return Decision("review", "cannot be undone", cost)
if cost > REVIEW_ABOVE_COST:
return Decision("review", "costly if wrong", cost)
if confidence < auto_min:
return Decision("review", "low confidence", cost)
return Decision("auto", "reversible, cheap, sure", cost)
Read it as a list of reasons to stop:
- An action we never listed is blocked. We never run what we haven't allowed.
- Irreversible and $500 or more: blocked.
- No confidence at all: review. It never goes to auto.
- Confidence under 0.5: blocked, too unsure to bother a person.
- Can't be undone: review, however sure the model is.
- Costs more than $100: review, even when the model is sure.
- Confidence under 0.9: review.
- Everything else runs.
Because the first match picks the lane, rule order is the policy. Put an "auto when confidence is 0.9 or more" rule at the top and a sure model could close accounts on its own.
Walk one proposal through
Case A-304: the model proposes credit_account for $240 with confidence 0.96. Known action, yes. Irreversible and costly, no. Confidence given, yes. Under 0.5, no. Irreversible, no. Then the cost check: 240 is over 100, so the decision is review. A confidence of 0.96 never decided this case. The cost did.
The review lane: review_queue.py
A held proposal needs somewhere to wait. The queue keeps the proposal with its reason, so the reviewer sees why it was held. An item can be decided only once, and the verdict records who decided.
"""The review queue: a proposal waits here with its reason until a person decides."""
from dataclasses import dataclass
@dataclass
class Item:
case_id: str
action: str
args: dict
reason: str
status: str = "waiting"
decided_by: str = ""
class ReviewQueue:
def __init__(self):
self.items = {}
def add(self, case_id, action, args, reason):
self.items[case_id] = Item(case_id, action, args, reason)
def waiting(self):
return [i for i in self.items.values() if i.status == "waiting"]
def decide(self, case_id, verdict, who):
item = self.items[case_id]
if item.status != "waiting":
raise ValueError(f"{case_id} is already {item.status}")
item.status = "approved" if verdict == "approve" else "rejected"
item.decided_by = who
return item
The ValueError on a second decision matters: two reviewers can't both act on the same refund, and every decision leaves a trail.
The run: nine cases, one reviewer
run_all.py sends the nine cases through the router, lets a reviewer called maya decide two items, compares against a router that uses confidence only, and sweeps the auto threshold. This is the recorded output:
nine cases through the router (auto at 0.90 or more)
A-301 reply_status conf 0.97 cost $0 -> auto reversible, cheap, sure
A-302 credit_account conf 0.94 cost $25 -> auto reversible, cheap, sure
A-303 credit_account conf 0.72 cost $25 -> review low confidence
A-304 credit_account conf 0.96 cost $240 -> review costly if wrong
A-305 close_account conf 0.99 cost $30 -> review cannot be undone
A-306 wire_refund conf 0.95 cost $900 -> block cannot be undone and costly
A-307 reply_status conf 0.41 cost $0 -> block too unsure
A-308 export_customers conf 0.91 cost $0 -> block not an allowed action
A-309 reply_status conf none cost $0 -> review no confidence given
lanes: auto 2 | review 4 | block 3
review queue: 4 waiting
A-304 approved by maya -> credit_account ran
A-303 rejected by maya -> nothing ran
A-304 ignored: A-304 is already approved
review queue: 2 waiting
auto-run that needed a person: confidence only 4 | router 0
auto at 0.70: auto 3 | review 3 | block 3
auto at 0.90: auto 2 | review 4 | block 3
auto at 0.95: auto 1 | review 5 | block 3
What to read from it:
- A-305 has confidence 0.99 and still waits. Closing an account can't be undone.
- A-306 has confidence 0.95 and is blocked. It's a $900 wire.
- A-308 asked for
export_customers, which isn't on the list, so it's refused whatever the confidence. - The second approval of A-304 is ignored, because the queue already recorded a verdict.
- A router that looked at confidence only would have auto-run four actions that needed a person. Ours auto-ran none.
Move the line, the queue moves
Now the architect's question: where do you draw the auto threshold? The last three lines of the run answer it for this data.
At 0.70, three run alone and three wait: fewer people, more risk. At 0.95, one runs alone and five wait: more people, less risk. The blocked cases stay blocked, because they were blocked for reasons the threshold doesn't touch. So set the threshold from reviewed outcomes, not from a number that feels safe. A model's own confidence is a hint you check against what reviewers actually found.
Three tempting answers that are wrong
When a design asks "who looks before this agent acts?", three answers sound reasonable:
- Auto-approve when confidence is high. A sure model can still be wrong, and a wire can't be recalled.
- Put the checkpoint at the end. A person approving after the wire is sent is too late.
- Ask the model whether a person is needed. Then the model routes itself.
The decision rule is to route in code, by confidence, reversibility and cost: gate the irreversible and the costly, and let the acceptable-risk paths run. For the related question of where an approval gate sits in a tool loop, see client vs server tools and approval gates, and for calibrating confidence on extraction tasks, human review and confidence calibration.
The trap: review everything
Sending everything to a person sounds like the safest choice. Put all nine cases in one queue and two things happen. The queue overloads, so real cases wait. And every card looks alike, so each one gets a quick approve: rubber stamping. The $900 wire sits between two cheap, sure replies and slips through. A queue that holds everything protects nothing. Route by risk instead: in our run, four wait, three are refused and two just run.
Try it yourself: add a rule
Add a new action, delete_backup, that can't be undone and costs a fixed $400. That's one line in the table:
"delete_backup": Rule(reversible=False, fixed_cost=400),
Before you run it, predict the lane for each proposal. Sure at 0.99: review, because it can't be undone. Unsure at 0.45: block, too unsure. No confidence: review. Now raise the fixed cost to 600: irreversible and costly, so block. A new action is one line in the table, and the router does the rest. The project files for this lesson are in the community, free to join.
Recap
| Signal | Where it comes from | What it can do |
|---|---|---|
| Confidence | The model's proposal | A hint. Low sends to review, very low blocks. High never overrides the other two. |
| Reversibility | Action table in code | Irreversible always goes to a person, or is blocked when costly. |
| Cost of a mistake | Real call arguments, read in code | Over the limit goes to review, even when the model is sure. |
| Rule order | The router | First match wins, so the order is the policy. |
Sure and cheap runs. Unsure or costly waits. Not allowed is refused. Let the risk pick the lane.
Related course on Udemy
Claude Certified Architect - Professional (CCAR-P) Exam Prep
Architecting with Claude: design, models, context, integration, evals, governance and stakeholders.View on Udemy ↗: Claude Certified Architect - Professional (CCAR-P) Exam Prep (paid course, opens in a new tab)Related posts
Guardrails for an LLM Agent: Check What Comes In, What It Wants to Do, and What Goes Out
An agent that reads customer emails and can refund up to $200. In a small simulation, a phrase filter still lets 6 of 8 written attacks do harm and blocks 2 honest users; plain checks outside the model take harm to 0 of 8, at a cost of 1 honest request failed and 2 held.
The Agent Attack Surface: Blast Radius, Narrow Tools, Scoped Keys and the Dangerous Three
A support agent reads a ticket that says run SELECT * FROM customers and email the result outside, and it has run_sql and send_email, so the customer list leaves. The model wasn't hacked, it was equipped. Map each tool by what it reads, changes and sends, replace the two large ones with narrow tools, scope the keys, and never give one agent untrusted input, private data and a way out together.
Prompt Injection, Jailbreaks and Untrusted Input: Label What Comes In, Gate What Goes Out
Three texts reach a support agent in one week: an injected ticket, a poisoned help article and a jailbreak. A naive agent turns all three into leaks; three small checks in plain code take that to zero.
Injection Exposure Review for an Agent: Map Inputs, Data and Effects, Layer Every Path, Retest the Job
Review a refund agent the way a security team would: map where stranger text gets in, what it can read and what it can do, layer every path, then show the four normal questions still give the same answer.
