Stop your LangChain agent from overspending
What is a spend firewall for LangChain?
Add a spend firewall to your LangChain agent in 5 lines. Approve, block, or flag every tool-driven purchase before a dollar moves.
TL;DR: Add a spend firewall to your LangChain agent in 5 lines. Approve, block, or flag every tool-driven purchase before a dollar moves.
A LangChain agent with a money-spending tool is one retry loop away from a runaway bill. Wrap that tool with sipi.bot and every purchase is checked against your rules before it fires.
The pattern: call guard() inside your @tool, before the real spend. It raises on a blocked or flagged decision, so the agent physically cannot spend past your policy — and it gets a readable message back so it stops retrying instead of hammering the endpoint.
from langchain_core.tools import tool
from sipi_guard import guard, SpendBlocked, SpendNeedsApproval
@tool
def buy(amount: float, merchant: str, category: str = "") -> str:
"Spend money with a supplier. A spend firewall decides if it is allowed."
try:
guard(amount=amount, merchant=merchant, category=category)
except SpendBlocked as e:
return f"BLOCKED by spend policy: {e.reason}. Do not retry; tell the user."
except SpendNeedsApproval as e:
return f"NEEDS HUMAN APPROVAL: {e.reason}. Escalated; not purchased yet."
return really_buy(amount, merchant)
Give buy to create_react_agent(llm, tools=[buy]) as usual. When sipi.bot blocks a spend, the model reads the reason in the tool result and explains it to the user rather than looping. LangGraph works identically — the guard lives inside the node.
Why not a hardcoded check inside the tool?
A single if amount > 500 misses the runaway loop (40 small retries), the cumulative daily cap across many tool calls, the flag-for-human path, and the audit trail of why each spend was allowed. sipi.bot centralizes all of that in one call.
Frequently asked
Does sipi.bot work with LangGraph?
Yes. The guard call lives inside the tool or node function, so LangGraph agents get the same protection as LangChain ReAct agents — no extra wiring.
Do I need the LangChain SDK to call sipi.bot?
No. sipi_guard.py is a zero-dependency stdlib client. LangChain is only used for the @tool decorator in this example; the guard itself is a plain HTTP call.
What happens when a spend is blocked mid-run?
The tool returns a readable 'BLOCKED: reason' string. The LangChain agent reads it as the tool result and stops retrying, explaining the block to the user instead of looping.