By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
A support agent can look things up, and it can change things. Those are not the same risk. A lookup that is wrong produces a bad answer; a write that is wrong moves money or changes an order. Guardrails are the difference between a model that suggests a write and a system that executes one.
| Question | Read-only tool | Write tool |
|---|---|---|
| Examples | lookup_order, refund_policy, search_docs | create_replacement, issue_refund, change_address |
| May the model trigger it freely? | Yes — safe to retry, cheap, easy to audit | No — queue it for a human decision first |
| What to validate | Record exists, belongs to the customer | Existence, ownership, amount limits, idempotency key |
| Failure mode | A wrong answer you can correct | An order or a payment that changed for real |
The simplest production-valid pattern is an approval queue. The agent can only create a pending record: the exact tool name and arguments, never executed. Your backend stores the record, a human approves or rejects it, and only then does a separate executor run the write. The agent never holds the trigger.
from langchain.tools import tool
WRITE_TOOLS = {"create_replacement"}
@tool
def lookup_order(order_id: str) -> dict:
"""Read-only: look up an order by id."""
orders = {"4521": {"status": "delivered", "items": ["ceramic mug"]}}
if order_id not in orders:
raise ValueError(f"Unknown order: {order_id}")
return {"order_id": order_id, **orders[order_id]}
@tool
def create_replacement(order_id: str, item_id: str) -> str:
"""Write action: only the approved executor may call this."""
raise RuntimeError("create_replacement must run through the approval queue")
def queue_for_approval(tool_name: str, args: dict) -> dict:
"""Create a pending record; executing the write is somebody else's job."""
if tool_name not in WRITE_TOOLS:
raise ValueError(f"{tool_name!r} is not a gated write tool")
return {"status": "pending_approval", "tool": tool_name, "args": args}
pending = queue_for_approval(
"create_replacement", {"order_id": "4521", "item_id": "mug"}
)
print(pending)LangChain 1.x ships the same idea as middleware: HumanInTheLoopMiddleware(interrupt_on={'create_replacement': True}) added to create_agent(..., middleware=[...], checkpointer=InMemorySaver()). When the model asks for a gated tool, the run pauses with an interrupt payload containing the action name and arguments. A human decision — approve, edit, reject or respond — resumes the same thread with Command(resume={'decisions': [{'type': 'approve'}]}). A checkpointer and a per-ticket thread_id are required, and the LangGraph path builds this pattern from the graph up.
Key takeaways
Separate read-only tools from write tools; the model may request writes but must not execute them.
An approval queue in ordinary application code is a valid production pattern: propose, store, decide, execute.
LangChain 1.x offers HumanInTheLoopMiddleware with interrupt/resume when you want the runtime to pause for a decision.
Enforce scope, allow-lists, validation, redaction and budgets in code — not in the prompt.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.