Skip to main content

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

  1. LangGraph decides to call a tool
  2. Before execution, the middleware calls Forge /v1/verify
  3. If approved: the tool runs normally
  4. 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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_forge-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

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

Hashes for langchain_forge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3ba7e182232f50bfa8adba1f3fdceb804925f1578f8a2c272f01a43835130834
MD5 4b71e4ff3050978d8a90ebbfe6aa036a
BLAKE2b-256 c09a992189876fe199765e3918e15fca2d3eeea0838e6bd47229b3f8d293c889

See more details on using hashes here.

File details

Details for the file langchain_forge-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_forge-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e59338ab80bb5ae921791a3776ec0622228cfe33c6443c87b1b547848072ead
MD5 623e8756ea4c6178f535678bc2755e03
BLAKE2b-256 3e03b46bfa236d0fc0633136488bd1f5d0961a0c82bad5e2674509ece27e52c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page