Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aport_agent_guardrails_langchain-1.0.20.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file aport_agent_guardrails_langchain-1.0.20.tar.gz.

File metadata

File hashes

Hashes for aport_agent_guardrails_langchain-1.0.20.tar.gz
Algorithm Hash digest
SHA256 d2af719d81517fda77b3932427c1dbba8edebb83e6abe692d46979c3f05b6923
MD5 4936287462242d21789b9c02f38c5768
BLAKE2b-256 18bc018123e11af5ab3a67db8184f47511c80086ca255f7325532b468c34c5ad

See more details on using hashes here.

File details

Details for the file aport_agent_guardrails_langchain-1.0.20-py3-none-any.whl.

File metadata

File hashes

Hashes for aport_agent_guardrails_langchain-1.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 07c59215091368930fecd1372fbf1e6fbe2f86573dbd544adb0ab8f29a108dbf
MD5 29d74b74534feb8b1b94129f2b93772a
BLAKE2b-256 806ebb1728bf15b2041cbb421f0f31f1264a9d729b0b0475a980c0c3e74f80ca

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