Forge Verify middleware for LangGraph/LangChain — verify every tool call before execution
Project description
langchain-forge
Forge Verify middleware for LangGraph and LangChain. Verifies every AI agent tool call against your policies before execution.
Install
pip install langchain-forge
Quick Start
import os
from langgraph.prebuilt import create_react_agent
from langchain_core.tools import tool
from forge_langgraph import ForgeVerifyMiddleware
os.environ["VERITERA_API_KEY"] = "vt_live_..."
os.environ["OPENAI_API_KEY"] = "sk-..."
@tool
def send_payment(amount: float, recipient: str) -> str:
"""Send a payment to a recipient."""
return f"Sent ${amount} to {recipient}"
@tool
def delete_record(record_id: str) -> str:
"""Delete a database record."""
return f"Deleted {record_id}"
# Add Forge middleware — one line
middleware = ForgeVerifyMiddleware(policy="finance-controls")
agent = create_react_agent(
model="gpt-4.1",
tools=[send_payment, delete_record],
middleware=[middleware],
)
# Every tool call is verified before execution
result = agent.invoke({"messages": [("user", "Send $500 to vendor@acme.com")]})
How It Works
- LangGraph decides to call a tool
- Before execution, the middleware calls Forge
/v1/verify - If approved: the tool runs normally
- If denied: the LLM receives a denial message and can explain why
Standalone Tool
If you prefer the LLM to call verification explicitly:
from forge_langgraph import forge_verify_tool
verify = forge_verify_tool(policy="finance-controls")
agent = create_react_agent(model, tools=[send_payment, verify])
Configuration
middleware = ForgeVerifyMiddleware(
api_key="vt_live_...", # or VERITERA_API_KEY env var
agent_id="prod-finance-bot",
policy="finance-controls",
fail_closed=True, # deny when API is unreachable
skip_actions=["read_balance"], # skip read-only tools
on_blocked=lambda a, r: print(f"BLOCKED: {a} — {r}"),
on_verified=lambda a, r: print(f"APPROVED: {a}"),
)
License
MIT — Veritera AI
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
langchain_forge-0.1.0.tar.gz
(4.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_forge-0.1.0.tar.gz.
File metadata
- Download URL: langchain_forge-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ba7e182232f50bfa8adba1f3fdceb804925f1578f8a2c272f01a43835130834
|
|
| MD5 |
4b71e4ff3050978d8a90ebbfe6aa036a
|
|
| BLAKE2b-256 |
c09a992189876fe199765e3918e15fca2d3eeea0838e6bd47229b3f8d293c889
|
File details
Details for the file langchain_forge-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_forge-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e59338ab80bb5ae921791a3776ec0622228cfe33c6443c87b1b547848072ead
|
|
| MD5 |
623e8756ea4c6178f535678bc2755e03
|
|
| BLAKE2b-256 |
3e03b46bfa236d0fc0633136488bd1f5d0961a0c82bad5e2674509ece27e52c5
|