Frameworks & tools

Human-in-the-loop approval for LangChain agents

Wrap a LangChain or LangGraph tool with guard() and the agent has to ask before it acts. Routine calls clear in a few milliseconds. The ones that can hurt you wait for a named person.

cb.guard({ action }, fn)refund.createemail.sendcode.deploycontent.publish
your agent cb.guard() cleared

The problem

Your LangChain agent picks the tool and the arguments at runtime. That flexibility is the whole reason you reached for it, and it's also where the trouble starts. The same ReAct loop that calls refund.create for a £6 reship will call it for £4,200 if the reasoning takes a wrong turn, or fire email.send at the full list instead of one address. Your code runs the tool the instant the model emits it, so by the time you notice, the side effect has already happened.

The obvious patch is a LangGraph interrupt() in the node that does the scary thing. It covers that one node, nothing else, and an agent that re-plans mid-run can route around it. You're then on the hook to build the rest yourself: a queue someone actually watches, a notifier, a signed record, a credential check the model can't talk its way past. Rebuild it again the day you add a tool or move to LangGraph. What you want instead is the agent running inside rules you wrote, with a person answerable for the handful of calls that carry real weight.

How ClearedBy handles it

  1. 01

    Wrap the tool with guard()

    Pass any StructuredTool, @tool function, or raw callable in a LangGraph node through guard(). The reasoning loop is untouched. The checkpoint sits at the call boundary, so it doesn't matter which tool the agent reaches for.

  2. 02

    The agent asks, then waits

    When the model decides to call a guarded tool, the wrapper ships the action type and its arguments to ClearedBy and blocks. The tool body stays frozen until a verdict comes back.

  3. 03

    Policy clears the routine, holds the rest

    Calls that sit inside your rules (small amounts, safe channels, recipients you already know) clear in milliseconds and the tool just runs. A refund over your line, a deploy to prod, a post mentioning a price: held, and routed to a named reviewer in the queue, Slack, or on their phone.

  4. 04

    Cleared, then sealed

    Approve it and the tool gets a short-lived credential and executes. Reject it and the body never runs at all. Either way the verdict is written to a tamper-evident, hash-linked record bound to whoever signed it.

agent.ts
import { ClearedBy } from '@clearedby/sdk'
import { tool } from '@langchain/core/tools'
import { z } from 'zod'

const cb = new ClearedBy({ apiKey: process.env.CLEAREDBY_API_KEY! })

const issueRefund = tool(
  ({ order, amount }) =>
    cb.guard(
      { action: 'refund.create', params: { order, amount } },
      () => shopify.refund(order, amount),        // runs only once cleared
    ),
  {
    name: 'issue_refund',
    description: 'Refund an order',
    schema: z.object({ order: z.string(), amount: z.number() }),
  },
)

FAQ

Does this cover LangGraph as well as plain LangChain?

Yes. guard() wraps any tool or callable, so it gates a StructuredTool inside a ReAct agent or an action inside a LangGraph node the same way. The gate lives at the call boundary, not in your graph topology.

Why not just use LangGraph's interrupt()?

interrupt() pauses one node in your own process. There's no policy engine, no signed record, and nothing stops a re-planned run from skipping the node entirely. ClearedBy adds the policy that auto-clears the routine, the named sign-off, the sealed record, and a credential the agent only receives after approval.

Won't the whole agent stall waiting on a reviewer?

Only the guarded call pauses, and only when policy holds it. Routine calls clear in milliseconds, so the loop runs full speed and stops on the few percent that actually need a human. You set the timeout for how long a hold can sit.

Can the agent dodge the gate by calling the underlying function directly?

No. The real side effect needs a short-lived credential that's only issued after approval, so calling the unwrapped function gets it nowhere. The gate isn't a prompt instruction the model can argue with.

Do I have to wrap every tool?

No, and you shouldn't. Guard the tools with consequences (refunds, sends, deploys, posts) and leave read-only lookups alone. Start in shadow mode with no card so nothing blocks while you watch what your policy would have held.

Related use cases

Let your agents run. Inside the rules you set.

Wrap a LangChain or LangGraph tool with guard() and the agent has to ask before it acts. Routine calls clear in a few milliseconds. The ones that can hurt you wait for a named person.