LangChain compliance middleware with hash-chained audit trails for EU AI Act readiness
Project description
langchain-nobulex
Compliance middleware for LangChain agents with hash-chained audit trails.
Enforce covenant rules on agent tool calls, block forbidden actions, and maintain a tamper-proof audit log — ready for EU AI Act compliance requirements.
Installation
pip install langchain-nobulex
Quick Start
from langchain_nobulex import create_agent, NobulexComplianceMiddleware
agent = create_agent(
model="gpt-4.1",
tools=tools,
middleware=[
NobulexComplianceMiddleware(
rules="permit read; forbid transfer where amount > 500; require log_all;"
)
]
)
How It Works
Define rules using a simple covenant DSL:
permit <action>— explicitly allow a tool/actionforbid <action> [where <condition>]— block a tool/action, optionally with conditionsrequire <behavior>— declare required behaviors (e.g.,log_all)
The middleware:
- Intercepts every tool call from the model
- Matches it against your covenant rules
- Blocks forbidden actions before they execute
- Logs every action (allowed and blocked) in a SHA-256 hash-chained audit trail
Verify integrity independently:
from langchain_nobulex import verify
log = agent.get_audit_log()
assert verify(log) # True if chain is intact, False if tampered
Audit Trail
Every entry in the audit log contains:
| Field | Description |
|---|---|
timestamp |
ISO 8601 UTC timestamp |
action |
Tool/action name |
params |
Tool arguments |
allowed |
Whether the action was permitted |
matching_rule |
The rule that matched |
prev_hash |
SHA-256 hash of the previous entry |
hash |
SHA-256 hash of this entry |
Each hash links to the previous entry, forming a tamper-evident chain. Use verify() to independently validate the entire chain.
EU AI Act Compliance
This middleware supports EU AI Act (Regulation 2024/1689) requirements for high-risk AI systems:
- Article 14 — Human oversight: Rules let operators define boundaries before deployment
- Article 12 — Record-keeping: Hash-chained audit logs provide tamper-proof records of all AI actions
- Article 9 — Risk management: Forbidden rules act as runtime guardrails against identified risks
- Independent verification: The
verify()function enables third-party audit of the action log
API Reference
NobulexComplianceMiddleware(rules: str)
Main middleware class. Pass a covenant rules string.
after_model(response)— intercepts and filters tool callswrap_tool_call(tool_call)— hook for per-execution loggingafter_agent(state)— attaches audit log to final agent stateget_audit_log()— returns the full audit trail as a list of dictsget_audit_log_json()— returns the audit trail as formatted JSON
verify(audit_log)
Independently validates a hash-chained audit log. Returns True if intact.
create_agent(model, tools, middleware)
Creates a middleware-aware agent wrapper.
License
MIT
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 langchain_nobulex-0.1.0.tar.gz.
File metadata
- Download URL: langchain_nobulex-0.1.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dba54975fab39780e0dfe715c96c2f99b35460eed73c2fa674720659a108c13
|
|
| MD5 |
393e638bea472b273927f52e5fc4f6cc
|
|
| BLAKE2b-256 |
03fcaa704755fd2849656edf7b5f0504e2f2f15b410d59a9afe0908de0b97bdc
|
File details
Details for the file langchain_nobulex-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_nobulex-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbde218bf64836114d5fe3bbd03f16964a5af2b724521867954ae66dc684cb29
|
|
| MD5 |
5e834c16dc8200cb97027a9d9336a151
|
|
| BLAKE2b-256 |
8ba7c4f8f031fd0ba708c0f56144f96087ead969e015ab29d4ce816ca936b701
|