APort Agent Guardrail for LangChain/LangGraph — AsyncCallbackHandler for AI agent tool calls
Project description
APort Agent Guardrail for LangChain
APort Agent Guardrail for LangChain/LangGraph — pre-action authorization for AI agents: an AsyncCallbackHandler that verifies every tool call against your passport and policies before execution. On deny, raises GuardrailViolation.
Install
pip install aport-agent-guardrails-langchain
Requires aport-agent-guardrails (core); installs automatically.
Setup
aport-langchain setup
- Writes config to
~/.aport/langchain/config.yaml. - Run the passport wizard with:
npx @aporthq/aport-agent-guardrails --framework=langchain.
Usage
from aport_guardrails_langchain import APortCallback, GuardrailViolation
# Add callback to your agent
agent = initialize_agent(
tools=tools,
llm=llm,
callbacks=[APortCallback()]
)
# On deny, the callback raises GuardrailViolation
try:
result = await agent.ainvoke(...)
except GuardrailViolation as e:
print(f"Blocked: {e.code} — {e}")
print("Reasons:", e.reasons)
Config is auto-loaded from .aport/config.yaml or ~/.aport/langchain/config.yaml. Override with APortCallback(config_path="/path/to/config.yaml").
Config
- mode:
local|api - passport_path: path to passport JSON (local mode)
- agent_id:
ap_xxx(API mode, hosted passport) - api_url: optional; default
https://api.aport.io
Tests
cd python/langchain_adapter
pip install -e ".[dev]"
pip install -e ../aport_guardrails
pytest tests/ -v
Links
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
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 aport_agent_guardrails_langchain-1.0.12.tar.gz.
File metadata
- Download URL: aport_agent_guardrails_langchain-1.0.12.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
793fb697039844e91da19b7c18c426b77a0be6ee8ebe9d8174def789074c29ae
|
|
| MD5 |
93dad426af239a4a11e5c848a8e6d6a3
|
|
| BLAKE2b-256 |
ccdfde5615172cd0f8933b4bdd3d6e714f26c69a108c8481f7994e9dc098569d
|
File details
Details for the file aport_agent_guardrails_langchain-1.0.12-py3-none-any.whl.
File metadata
- Download URL: aport_agent_guardrails_langchain-1.0.12-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de8ea6af95b2f255535d2fda7100ddd108e4681a58cdc47785fc899d41e1c51b
|
|
| MD5 |
6d39a448264b1b27e4ba84f1c4b06642
|
|
| BLAKE2b-256 |
1c1cc12c258dc041b28cac69cea85cbc080083b101863979bbedc7f4d9a3fb36
|