Sub topic 5
Approve, reject, edit, and feedback
This chapter covers the decisions a reviewer can make at an approval gate and how your code should act on each one. It assumes you can read short Python programs, know how an agent calls tools, and have seen a basic approval gate that pauses before a risky call. Earlier chapters covered where the gate sits in the agent loop and which actions need it. Here the focus is on what happens after the human answers.
Why a yes/no gate is not enough
A gate that only accepts "yes" or "no" forces the reviewer into a bad choice. Suppose an agent drafts an email to the wrong recipient. The reviewer can approve a mistake, or reject the whole step and lose the useful draft. Neither outcome helps the agent finish the job.
A richer set of decisions fixes this. Most systems support four:
| Decision | What the reviewer does | What the workflow does next |
|---|---|---|
| Approve | Accepts the action as proposed | Runs the tool call unchanged |
| Reject | Refuses the action | Does not run the tool, and tells the agent why |
| Edit | Changes the arguments | Runs the tool with the new arguments |
| Feedback | Gives guidance without a decision on the exact call | Returns the guidance to the agent so it can try again |
In practice, reject and feedback often share one code path, because both skip the tool and send text back to the agent. They are still worth treating as separate ideas. A rejection says "do not do this." Feedback says "do something different, and here is how."
Approve
Approve is the simple case. The reviewer saw the exact call and accepted it, so the tool runs with the original arguments.
Two details matter. First, the approval must apply to the call the reviewer saw. If the arguments change between display and execution, the approval no longer means anything. A later chapter covers binding an approval to the exact action. Second, approval should be recorded as a decision, not just implied by the tool running. You need that record later for the audit trail.
Reject
Rejection means the tool does not run. The important design question is what the agent sees afterwards.
If you return nothing, the agent has no idea what happened. It may retry the same call, loop forever, or report success that never occurred. Return a structured result that says the action was rejected and includes the reviewer's reason when there is one.
from dataclasses import dataclass
@dataclass(frozen=True)
class ToolCall:
name: str
args: dict
def rejection_result(call: ToolCall, reason: str) -> dict:
return {
"rejected": True,
"tool": call.name,
"reason": reason or "No reason given",
"note": "The action was not performed. Do not retry it unchanged.",
}
print(rejection_result(ToolCall("send_email", {"to": "[email protected]"}), "Too many recipients"))The note field matters. Models tend to treat a tool result as information about the world. Saying plainly that the action did not happen, and should not be retried as is, reduces repeated attempts.
A rejection without a reason is legal, but it gives the agent little to work with. Where your interface allows it, ask reviewers for a short reason. Even a few words change what the agent does next.
Edit
Edit lets the reviewer fix the call instead of throwing it away. Typical edits are correcting a recipient, lowering a refund amount, or narrowing a delete filter.
Editing has a few edge cases that a basic implementation misses:
- Validate the edited arguments. The reviewer is a person typing into a form or JSON box. A typo can produce arguments the tool cannot accept. Validate them against the same schema the agent's arguments go through, before you run anything.
- Check risk again. An edit can raise the risk of a call. If a reviewer changes a refund from 20 to 20,000, a policy that required a second approver above 1,000 should still fire. Re-run your risk classification on the edited call.
- Tell the agent what changed. If the tool runs with different arguments than the agent proposed, the agent should know. Otherwise its memory says it refunded 20, while the system refunded 200. Include both the original and the executed arguments in the result.
- Record both versions. The audit trail should store what the agent proposed and what actually ran.
import json
def validate_refund_args(args: dict) -> dict:
amount = args.get("amount")
if not isinstance(amount, (int, float)) or amount <= 0:
raise ValueError("amount must be a positive number")
if not isinstance(args.get("order_id"), str) or not args["order_id"]:
raise ValueError("order_id must be a non-empty string")
return args
def apply_edit(original_args: dict, edited_args: dict) -> dict:
validated = validate_refund_args(edited_args)
return {
"executed_args": validated,
"original_args": original_args,
"edited": validated != original_args,
}
result = apply_edit(
{"order_id": "A-1001", "amount": 200},
{"order_id": "A-1001", "amount": 20},
)
print(json.dumps(result, indent=2))If validation fails, do not run the call and do not silently fall back to the original arguments. Return the error to the reviewer so they can correct it. Falling back to the original would run an action the reviewer tried to change.
Feedback
Feedback is the least obvious decision. The reviewer does not accept or refuse a specific call. Instead they say something like "Use the billing contact, not the account owner" or "Check the order status before refunding."
The tool does not run. The text goes back to the agent as new input, and the agent plans again. The result is closer to a conversation than a verdict.
Feedback works best when it is delivered in a form the agent will act on. Put it where the agent expects tool results, label it as reviewer guidance, and keep the original call identifiable so the agent knows which step the comment refers to.
def feedback_result(call: ToolCall, text: str) -> dict:
return {
"feedback": True,
"tool": call.name,
"reviewer_guidance": text,
"note": "The action was not performed. Revise your plan using the guidance.",
}Feedback is also the point where prompt injection can matter. Reviewer text is trusted, since it comes from your own user. Text the agent drafted is not. Keep these clearly separate so the agent cannot treat content from a web page as if a reviewer wrote it.
One dispatcher for all four decisions
Put the decision handling in a single function so every path is validated and logged in the same way. This version builds on the gate from the previous chapter and adds feedback and edit validation.
def handle_decision(call: ToolCall, decision: dict, tools: dict, validate=None) -> dict:
action = decision.get("action")
if action == "approve":
return {"status": "executed", "output": tools[call.name](**call.args)}
if action == "edit":
new_args = decision.get("args")
if not isinstance(new_args, dict):
raise ValueError("edit decision needs an args object")
if validate is not None:
new_args = validate(new_args)
output = tools[call.name](**new_args)
return {
"status": "executed_with_edit",
"original_args": call.args,
"executed_args": new_args,
"output": output,
}
if action == "reject":
return {"status": "rejected", **rejection_result(call, decision.get("reason", ""))}
if action == "feedback":
return {"status": "feedback", **feedback_result(call, decision.get("text", ""))}
raise ValueError(f"Unknown decision action: {action!r}")The last line is deliberate. An unknown action must fail loudly. If the function returned an empty result for unrecognized input, a bug in the review interface could look like a quiet rejection, or worse, fall through to execution.
Common errors
- Defaulting to approve. If the decision is missing or malformed, treat it as not approved. Never use a default that runs the tool.
- Running edited arguments without validation. Reviewer input is user input.
- Skipping the second risk check after an edit. A change can move a call into a higher risk tier.
- Returning nothing on reject. The agent retries or invents a result.
- Not telling the agent about edits. The agent's view of the world then disagrees with reality.
- Mixing reviewer text with untrusted content. The agent should know which words came from a person with authority.
Testing each decision
Each decision type is a separate branch, so each needs its own test. For every one, check two things: what the tool did, and what the agent saw. A test that only checks the tool misses the case where the agent receives a misleading result.
def test_reject_does_not_run_tool():
calls = []
tools = {"send_email": lambda **kw: calls.append(kw)}
call = ToolCall("send_email", {"to": "[email protected]"})
out = handle_decision(call, {"action": "reject", "reason": "wrong person"}, tools)
assert calls == []
assert out["status"] == "rejected"
assert out["reason"] == "wrong person"
def test_unknown_action_fails():
call = ToolCall("send_email", {})
try:
handle_decision(call, {"action": "maybe"}, {})
except ValueError:
return
raise AssertionError("unknown action should raise")
test_reject_does_not_run_tool()
test_unknown_action_fails()
print("ok")Exercise
A reviewer edits a refund from 200 to 20,000 by mistake, and your policy requires a second approver above 1,000. Which two steps in the edit path should catch or limit this, and what should the agent be told if the call runs?
Show answer
First, validate the edited arguments against the tool's schema (and sensible limits). Second, re-run risk classification on the edited call so the policy requiring a second approver fires before anything executes. If the call does run, the result sent to the agent should include both the original arguments (200) and the executed arguments, so the agent's view matches what actually happened.
Exercise
What is the difference between a reject decision and a feedback decision, and why might they still share most of their code?
Show answer
Reject says the action must not happen, optionally with a reason. Feedback gives guidance for how to change the plan. Both skip the tool and return text to the agent, so the code path is nearly the same. They differ in intent: after feedback the agent is expected to propose a revised action, while after a reject it may simply stop or choose another route.