Sub topic 3
Deciding which actions need approval
This chapter assumes you can read short Python programs, know how an LLM agent calls tools, and are comfortable with JSON-shaped data. You don't need to have built an approval gate yet. That comes in the next chapter. Here the question is narrower: for each tool call an agent might make, should a human see it first?
Why classification comes first
An agent that asks about every action is unusable. An agent that asks about none is unsafe. The useful design sits between these two. It lets low-risk calls run on their own and stops the rest for review.
To place a call on that line, you need a rule that is cheap to evaluate and easy to explain. The rule should depend on facts about the tool and its arguments. It should not depend on how confident the model sounds. A model can be wrong and sure of itself at the same time, so its own opinion is a poor risk signal.
This chapter builds that rule in three steps: pick the factors that make an action risky, encode them in a lookup, then refine the lookup with argument-level checks.
The factors that make an action risky
Two questions do most of the work.
- Reversibility. Can the effect be undone? Reading a record can't hurt anything. Editing a draft can be reverted. Sending an email, charging a card, or deleting production data cannot be taken back.
- Blast radius. How much and who is affected? Updating one row in a test table is small. Emailing every customer is large.
Other factors raise or lower the level.
- Side effects outside your system. An external call (email, payment, a public post) leaves your control the moment it runs.
- Data sensitivity. Reading customer records or secrets is "read-only" but can still leak information.
- Cost. Some calls spend money, such as a large batch job or a paid API.
- Authority. Changing permissions, credentials, or approval policy itself should always need review.
A simple way to combine the first two questions is a grid.
| Row | Small blast radius | Large blast radius |
|---|---|---|
| **Reversible** | Low: run automatically | Medium: run with logging, or review |
| **Irreversible** | Medium: review | High: always review |
The grid is a starting point. Your own system may weight cost or data sensitivity more heavily, and that is fine as long as the rule is written down.
A first implementation: a lookup table
The simplest classifier is a dictionary from tool name to risk level. It is easy to audit, because a reviewer can read every entry.
from dataclasses import dataclass
@dataclass(frozen=True)
class ToolCall:
name: str
args: dict
RISK = {
"search_docs": "low",
"send_email": "high",
"delete_record": "high",
}
def risk_of(call: ToolCall) -> str:
# Unknown tools default to high risk, so new tools need approval until classified.
return RISK.get(call.name, "high")The important line is the default in RISK.get(call.name, "high"). If a developer adds a tool and forgets to classify it, the call is stopped for review instead of running silently. This is called failing closed: when the system is unsure, it takes the safe action. The opposite, failing open, would let unclassified tools run, and the mistake would only show up after something went wrong.
A quick check shows the behavior:
print(risk_of(ToolCall("search_docs", {"query": "refund policy"}))) # low
print(risk_of(ToolCall("send_email", {"to": "[email protected]"}))) # high
print(risk_of(ToolCall("export_all_users", {}))) # high (unknown)Why the tool name alone is not enough
A lookup by name treats every call to a tool the same way. Real tools take arguments, and the arguments often change the risk.
update_recordon a draft is low risk. On a billing record it is high.send_emailto an internal test address is low risk. To 40,000 customers it is high.run_querywith aSELECTis low risk. With aDELETEit is not.transfer_fundsfor 5 units is routine. For 500,000 it is not.
So the classifier should be able to look at the arguments. A common pattern is to keep the table as a baseline and add small functions that can raise the level for specific tools.
from dataclasses import dataclass
@dataclass(frozen=True)
class ToolCall:
name: str
args: dict
BASE_RISK = {
"search_docs": "low",
"update_record": "low",
"send_email": "medium",
"delete_record": "high",
"transfer_funds": "medium",
}
ORDER = {"low": 0, "medium": 1, "high": 2}
def raise_to(current: str, minimum: str) -> str:
return current if ORDER[current] >= ORDER[minimum] else minimum
def risk_of(call: ToolCall) -> str:
level = BASE_RISK.get(call.name)
if level is None:
return "high" # fail closed for unknown tools
if call.name == "update_record" and call.args.get("table") == "billing":
level = raise_to(level, "high")
if call.name == "send_email":
recipients = call.args.get("to", [])
if not isinstance(recipients, list) or len(recipients) > 10:
level = raise_to(level, "high")
if any(not r.endswith("@example.com") for r in recipients if isinstance(r, str)):
level = raise_to(level, "high")
if call.name == "transfer_funds":
amount = call.args.get("amount")
if not isinstance(amount, (int, float)) or amount > 1000:
level = raise_to(level, "high")
return level
print(risk_of(ToolCall("update_record", {"table": "notes"}))) # low
print(risk_of(ToolCall("update_record", {"table": "billing"}))) # high
print(risk_of(ToolCall("send_email", {"to": ["[email protected]"]}))) # medium
print(risk_of(ToolCall("transfer_funds", {"amount": "lots"}))) # highNotice the pattern in the argument checks. Each rule can only raise the level, never lower it. Malformed arguments, such as a string where a number is expected, also raise it. This keeps the function safe to extend: adding a rule can make the system stricter but cannot quietly loosen an earlier decision.
Edge cases and common errors
Unknown or renamed tools. If a tool is renamed, the old table entry no longer matches, and the default sends it to review. This is the behavior you want, but it creates noise until the table is updated. Keep the table in the same change as the tool definition so the two move together.
Composite tools. A tool such as run_shell or execute_sql can do anything. Do not classify it as medium and hope. Either classify it as high, or parse the command and allow only a narrow set of safe forms, with everything else going to review.
Chains of low-risk calls. Each call may be harmless alone. Reading a customer list, then writing it to a public file, then sharing the link may be a high-risk sequence made of low-risk steps. Per-call classification cannot see this. Where it matters, track what the run has done so far and raise the level when a combination appears, such as "read sensitive data" followed by "external write."
Read-only is not always safe. A search that returns confidential data is read-only, but the result may then flow into a later email. Treat sensitive reads as medium, or tag the data so later steps know it is sensitive.
Trusting the model's own risk label. If the model supplies a field like "risk": "low" in its tool call, ignore it. Classification must come from code you control. Text that influences the model, including content from documents or web pages, could push it to label a dangerous call as safe.
Using the description instead of the name. Classify by the tool you actually execute, not by free text the model writes about what it is doing.
Choosing thresholds
The thresholds in the example, 10 recipients and 1000 units, are placeholders. Pick yours by looking at real use.
- Review a sample of past or simulated agent runs and note which actions you would have wanted to see.
- Set limits just above normal activity, so routine work passes and unusual work stops.
- Start strict. Loosening a rule after you gain evidence is safer than tightening it after an incident.
- Revisit the table when you add tools, change permissions, or see a near miss.
Being too strict has a cost too. If reviewers see many trivial requests, they begin approving without reading. A later chapter covers this problem, called approval fatigue. For now, keep in mind that every unnecessary approval weakens the value of the necessary ones.
What this chapter produces
The output of classification is a single value per call, such as "low", "medium", or "high". The approval gate in the next chapter reads that value. Low-risk calls run directly. Others pause and wait for a human decision. Keeping classification in a separate function, as shown here, lets you change the policy without touching the gate.
Exercise
A new tool called archive_project is added to the agent, but nobody adds it to the BASE_RISK table. The agent calls it. What does risk_of return, and why is this the desired behavior?
Show answer
It returns "high", because BASE_RISK.get(call.name) finds nothing and the function fails closed for unknown tools. The call goes to a human for review until someone classifies the tool, so a missing table entry cannot let an unreviewed action run.
Exercise
The send_email rule uses len(recipients) > 10 to raise risk. An agent sends 50 separate calls with one recipient each. Does the rule catch it, and what could you add to handle it?
Show answer
No. Each call has one recipient, so each is rated medium on its own. To catch it, track state across the run, for example a count of emails sent so far, and raise the level once the running total passes a limit. Rate limits per run are a common way to do this.
Exercise
Why should argument-based rules only raise the risk level and never lower it?
Show answer
If a rule could lower the level, a later rule could undo a stricter earlier decision, so adding a rule might silently make the system less safe. With raise-only rules, each addition can only make the system stricter, which keeps the function safe to extend and easy to reason about.