Skip to main content

langchain-comply54

LangChain and LangGraph integration for comply54 — runtime compliance enforcement for AI agents operating under African data protection and financial-sector regulations.

Overview

langchain-comply54 wraps the comply54 policy engine as a first-class LangGraph node and LangChain tool. It intercepts agent tool calls before execution, evaluates them against African regulatory frameworks (NDPA 2023, CBN, NFIU, Ghana DPA, Kenya DPA, and 15+ more), and either blocks the call or lets it through — all in-process, with no OPA binary or external service required.

Agent → Comply54Guard → [deny] → ToolMessage error back to agent
                      → [allow] → Tools execute normally

Installation

pip install langchain-comply54

Quick Start — LangGraph Guard Node

The recommended pattern is Comply54Guard as a pre-execution node in a LangGraph ReAct graph:

from langchain_comply54 import Comply54Guard, comply54_route
from comply54.sectors import NigeriaFintechCompliance
from langgraph.graph import StateGraph, MessagesState, END
from langgraph.prebuilt import ToolNode

# 1. Build your tools and agent as normal
tools = [transfer_funds_tool, lookup_account_tool]
tool_node = ToolNode(tools)
agent_node = build_agent(tools)  # your LLM + tools

# 2. Create the guard
guard = Comply54Guard(
    NigeriaFintechCompliance(),
    context={"kyc_tier": 3, "customer_verified": True},
)

# 3. Wire it into the graph between agent and tools
graph = StateGraph(MessagesState)
graph.add_node("agent", agent_node)
graph.add_node("comply54_guard", guard)
graph.add_node("tools", tool_node)

graph.set_entry_point("agent")
graph.add_conditional_edges("agent", should_continue,
    {"comply54_guard": "comply54_guard", END: END})
graph.add_conditional_edges("comply54_guard", comply54_route,
    {"tools": "tools", "agent": "agent"})
graph.add_edge("tools", "agent")

app = graph.compile()

When the agent attempts a tool call that violates compliance policy, Comply54Guard injects a ToolMessage with a structured denial that the agent can explain to the user:

{
  "blocked": true,
  "decision": "deny",
  "reason": "CBN NIP Framework: single transfer of ₦15,000,000 exceeds the ₦10,000,000 per-transaction cap",
  "regulation": "CBN Transaction Limits & Controls",
  "audit_id": "a3f2c1d4-...",
  "jurisdictions": ["NG"]
}

Compliance Decision Outcomes

Every evaluation returns one of four outcomes:

Decision Meaning Guard behaviour
allow All checks passed Tool executes normally
audit Action logged for regulatory trail Tool executes; state gets compliance_result
escalate Elevated-risk action — human review recommended Tool executes by default; blocked if block_on_escalate=True
deny Hard regulatory violation Tool blocked; agent receives structured ToolMessage error

Available Sector Packs

Import Jurisdictions Key Regulations
NigeriaFintechCompliance NG NDPA 2023, CBN NIP (₦10M cap), NFIU AML/CFT, BVN/NIN
NigeriaHealthCompliance NG NDPA 2023, NHA, NHIA — patient data & health records
NigeriaInsuranceCompliance NG NDPA 2023, NIIRA 2025 (replaces Insurance Act 2003)
KenyaFintechCompliance KE Kenya Data Protection Act 2019, CBK guidelines
PanAfricanCompliance NG, KE, GH, RW, EG, MU, ZA, TZ, UG 9-jurisdiction pack
from comply54.sectors import (
    NigeriaFintechCompliance,
    NigeriaHealthCompliance,
    NigeriaInsuranceCompliance,
    KenyaFintechCompliance,
    PanAfricanCompliance,
)

Patterns

Block on escalate

guard = Comply54Guard(
    NigeriaFintechCompliance(),
    block_on_escalate=True,  # treat escalate as deny
)

Per-request context from agent state

Merge dynamic context (e.g. session KYC tier, consent flags) at evaluation time:

# Set compliance_context in your agent state before the guard runs
state["compliance_context"] = {
    "kyc_tier": user.kyc_tier,
    "customer_verified": user.is_verified,
    "consent_documented": user.has_data_transfer_consent,
}

LangChain StructuredTool (self-check pattern)

For agents that should self-check before acting rather than being intercepted automatically:

from langchain_comply54 import comply54_tool
from comply54.sectors import NigeriaFintechCompliance

# The agent can call this tool to ask "is this action allowed?"
compliance_check = comply54_tool(NigeriaFintechCompliance())
tools = [transfer_funds_tool, compliance_check]

Legacy state-dict node

For LangGraph graphs that pass structured state rather than messages:

from langchain_comply54 import compliance_node
from comply54.sectors import NigeriaFintechCompliance

node = compliance_node(NigeriaFintechCompliance())
# state must contain: action, params, output, context
# node writes back: compliance_result, compliance_blocked, compliance_message

Compliance Certificate

Every evaluation produces an auditor-exportable compliance certificate:

result = guard._compliance.check(action="transfer_funds", params={"amount": 5_000_000})
cert = result.to_certificate(
    sector_pack="NigeriaFintechCompliance",
    jurisdictions=["NG"],
    regulations=["NDPA 2023", "CBN FPR"],
)
print(cert.to_json())

Requirements

  • Python 3.9+
  • comply54[langgraph] >= 0.3.0 (installed automatically)
  • No OPA binary, no Docker, no external services

Links

License

Apache 2.0

Metadata

Release files for langchain-comply54 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-comply54 0.3.0
File Size Uploaded
langchain_comply54-0.3.0.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-comply54 0.3.0
File Interpreter ABI Platform
langchain_comply54-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / langchain_comply54-0.3.0.tar.gz

Download URL langchain_comply54-0.3.0.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8b1a23994d59100a7d26cbefac530b6cd2217c278cbe2b58e8b2ddc5a2c3a089
BLAKE2b-256 checksum
How to use checksums
90b21fa045ca1ac0a595b379e142a366f2b6dc8ebd81c8cca53319ac61686c53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / langchain_comply54-0.3.0-py3-none-any.whl

Download URL langchain_comply54-0.3.0-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d73ec003b02d7b0d833cecea5cdee8ef5b791004d8c45a02e4b436007a553e8
BLAKE2b-256 checksum
How to use checksums
6b1c74340247429e5c8516f31aa414c78a81246df31f3b77edc954b52609318a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page