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.24.tar.gz (4.8 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.24.tar.gz.

File metadata

File hashes

Hashes for aport_agent_guardrails_langchain-1.0.24.tar.gz
Algorithm Hash digest
SHA256 70fdde8c017617c19604b6eef8ddb678b6d42948616983907997ba01b8088a67
MD5 291baa312c3ff8fba09e6456cf60b26e
BLAKE2b-256 54cb196d312f6d73882d52940c8dee70462c0754b58c7b333cb6943f3c8eb7d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aport_agent_guardrails_langchain-1.0.24-py3-none-any.whl
Algorithm Hash digest
SHA256 6713c2cafc9a43c8620d8184c2567ce90cc9e6ff0e7f199902b54ed01b50a40d
MD5 872c7f7d3d79936e1ca3b725487ddf67
BLAKE2b-256 289f4d43c920fe92969e22ac081e6d20943d8b1474e793db3ca9afd1a1fe8ab4

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