← All Frameworks

LangChain Guardrails

AsyncCallbackHandler for pre-tool-call authorization

Python

LangChain is the most widely-used framework for building LLM applications with 90k+ GitHub stars. APort integrates as an AsyncCallbackHandler that intercepts tool execution before it happens, enforcing OAP policies on every tool call.

Quick Start

1. Create passport & config

npx @aporthq/aport-agent-guardrails langchain

2. Install guardrails package

pip install aport-agent-guardrails-langchain

3. Add to your code

from aport_guardrails_langchain import APortCallback

agent = initialize_agent(
    tools=tools,
    llm=llm,
    callbacks=[APortCallback()]
)

How It Works

🛂

Passport

Your agent gets an OAP passport declaring its identity, capabilities, and operational limits.

🔒

Evaluate

Before every tool call, the guardrail evaluates it against the passport's policy. Locally or via hosted API.

Decision

Allow or deny with structured OAP reason codes. Signed decisions create an auditable trail.

Frequently Asked Questions

How do LangChain guardrails work?

APort provides an AsyncCallbackHandler that hooks into LangChain's on_tool_start event. Before any tool executes, the handler evaluates the call against your OAP passport's declared capabilities and limits.

Does this work with LangGraph?

Yes. Since LangGraph is built on LangChain, the APortCallback works in LangGraph workflows, ToolNodes, and agent executors without modification.

Ready to secure your LangChain agents?

Get started in under 2 minutes with a single command.