An approval gate for LlamaIndex agents
Put guard() around the LlamaIndex tools that move money, ship code or talk to customers. The safe calls clear in milliseconds and your agent never stops; the consequential ones wait for a named person.
The problem
A LlamaIndex agent picks its own tools at runtime. Hand a FunctionAgent or AgentWorkflow a toolset — issue_refund, send_email, post_update — and the model decides when to fire each one and with what arguments. That flexibility is the whole point. It's also how one bad retrieval or a confidently wrong query ends up calling refund.create for £5,000, or email.send to your entire list, before anyone gets a look. By then the tool has run. You're not approving, you're apologising.
The framework's own answer is an InputRequiredEvent the workflow blocks on, which puts a prompt in front of every sensitive call. So someone signs off the £4 refund as often as the £4,000 one, and they tune it out fast. Gate everything and the agent crawls. Gate nothing and you're trusting a prompt instruction the model can argue itself out of. The llamaindex-agent-approval-gate you actually want clears the routine on its own and only interrupts on the calls that carry real consequences.
How ClearedBy handles it
-
01
Wrap the tool, leave the workflow alone
Keep your FunctionTool as written and put guard() around its handler. guard checks the action first and only runs your real refund or email logic once it clears. No InputRequiredEvent wiring, no rewrite of the agent loop.
-
02
Your policy decides in milliseconds
Every call arrives at the gate with its action type and the exact arguments the model chose. In-policy ones — a refund under £50, an internal reply — clear instantly, so the agent keeps moving. The rest are held.
-
03
A named person clears the held few
Held calls land in a fast queue, or Slack, or someone's phone. That one tool call awaits a verdict while the rest of the workflow runs on; the agent only gets a short-lived credential to act after a reviewer clears it, with the arguments they saw.
-
04
The verdict gets sealed
Auto-cleared or signed by hand, every decision writes to a tamper-evident, hash-linked record bound to the reviewer's passkey. Months later you can show which call ran, with what arguments, and who put their name on it.
import { ClearedBy } from '@clearedby/sdk'
import { FunctionTool } from 'llamaindex'
import { z } from 'zod'
const cb = new ClearedBy({ apiKey: process.env.CLEAREDBY_API_KEY! })
const refundTool = FunctionTool.from(
({ orderId, amount }: { orderId: string; amount: number }) =>
cb.guard(
{ action: 'refund.create', params: { orderId, amount } },
() => shopify.refund(orderId, amount), // runs only once cleared
),
{
name: 'issue_refund',
description: 'Refund an order',
parameters: z.object({ orderId: z.string(), amount: z.number() }),
},
)
FAQ
Does this cover AgentWorkflow and FunctionAgent, or only the old ReActAgent?
All of them. guard sits inside the tool's handler, so it doesn't care which agent or workflow invokes the tool — FunctionAgent, AgentWorkflow, ReActAgent, or a direct tool call behave identically.
My LlamaIndex agent is in Python. Am I stuck with the TypeScript SDK?
No. The gate is a plain HTTP endpoint (POST /v1/gate), and there's an MCP tool, request_clearance, you can hand to a Python agent. Same clear-or-hold behaviour either way.
What happens to the run while a tool call is held?
guard awaits that single call until your policy or a reviewer resolves it, so the branch pauses instead of erroring. Set your own timeout, and run async or streaming so the rest of the workflow carries on.
Can I switch this on without blocking anything yet?
Yes. Start in shadow mode, no card. guard runs every tool as normal and logs what the policy would have held, so you see the real hold rate on live agent traffic before you enforce a thing.
The model picked the arguments — does the reviewer see those exact values?
Yes. The params you pass to guard — order id, amount, recipient, draft body — are what the reviewer reads and what gets sealed, and your function runs with precisely those approved values. The agent can't quietly change them after sign-off.
Related use cases
Let your agents run. Inside the rules you set.
Put guard() around the LlamaIndex tools that move money, ship code or talk to customers. The safe calls clear in milliseconds and your agent never stops; the consequential ones wait for a named person.