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
from langchain.agents import create_agent
# Add callback to your agent
agent = create_agent(model=model, tools=tools)
try:
result = await agent.ainvoke(
{"messages": [{"role": "user", "content": "run the task"}]},
config={"callbacks": [APortCallback()]},
)
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
Metadata
Release files for aport-agent-guardrails-langchain 1.0.34
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aport_agent_guardrails_langchain-1.0.34.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aport_agent_guardrails_langchain-1.0.34-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / aport_agent_guardrails_langchain-1.0.34.tar.gz
| Download URL | aport_agent_guardrails_langchain-1.0.34.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
083ec271995b7f0d6e64f647904f4eef7227461aca3aeb9684416f71b79c91d9
|
|
BLAKE2b-256 checksum How to use checksums |
cb2c05332f135a1ad63f8a90497add2ec7bb02d4d4011fd8a2f5eaf435fd6528
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / aport_agent_guardrails_langchain-1.0.34-py3-none-any.whl
| Download URL | aport_agent_guardrails_langchain-1.0.34-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bb4919779ece70f555ee38ddd1e1710cb8c1285f56d4a0a71ec1bf4cc49598c9
|
|
BLAKE2b-256 checksum How to use checksums |
b30da5baee09338e4199df8817939d0b4ff63d6951b7684da6ffeac161f7d00d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|