langchain-openterms
LangChain adapter for OpenTerms — emits a signed ORS v0.1 receipt for every tool invocation in a LangChain chain or agent.
Depends on openterms-py>=0.1.0 for canonicalization, signing, and the HTTP client. One signing path is shared with crewai-openterms.
Install
pip install langchain-openterms
This pulls in langchain-core>=0.3,<1.0. The adapter uses only the public BaseCallbackHandler hooks, which have been stable through the 0.3 line. If you need to run against an older LangChain version, pin langchain-core and report compatibility issues on the repo.
Quickstart
from langchain_core.tools import tool
from openterms import IngestClient, generate_keypair
from openterms_langchain import OpenTermsCallbackHandler
sk, _ = generate_keypair()
client = IngestClient(
base_url="http://localhost:3000",
workspace_id="00000000-0000-4000-8000-0000000000aa",
key_id="my-key",
private_key=sk.private_bytes_raw(),
agent_id="my-agent",
)
handler = OpenTermsCallbackHandler(
client=client,
agent_id="my-agent",
terms_url="https://example.com/terms",
terms_hash="a" * 64,
emit_post_action=True,
)
@tool
def add(a: int, b: int) -> int:
"""Add two integers."""
return a + b
add.invoke({"a": 2, "b": 3}, config={"callbacks": [handler]})
Two receipts will be emitted per call: one on on_tool_start with the inputs, and one on on_tool_end with action_context.post_state_hash = SHA-256 of the output.
See examples/quickstart.py for a runnable copy.
Configuration
terms_url/terms_hash: the default terms binding for every receipt. Override per-tool withhandler.set_tool_terms(tool_name, terms_url=..., terms_hash=...).emit_post_action: whenTrue, emit a second receipt onon_tool_end. DefaultFalse.strict: whenTrue, re-raiseopenterms.IngestErrorfrom the callback so a failed emission propagates up the chain. DefaultFalse— failures are logged and swallowed so a misbehaving ingest cannot break an agent loop.
What this adapter does
- Hooks LangChain's
on_tool_start/on_tool_end/on_tool_errorlifecycle. - Builds an ORS receipt with
action_type="tool_call"andaction_context = {tool_id, args}. - Signs and POSTs through
openterms.IngestClient. - Optionally emits a second receipt on tool completion containing a
post_state_hash(SHA-256 of the stringified output).
What this adapter does NOT do
- It does not run an ingest service. You must point
IngestClientat a running OpenTerms API. Seeapps/apiand IMPLEMENTATION_STATUS.md. - It does not handle auth. The bearer-token placeholder on
IngestClientis not yet enforced by the service. - It does not host a JWKS. Verification requires a JWKS you supply.
- It does not buffer or retry. A failed emission is logged once (or re-raised if
strict=True) and the call proceeds. - It does not patch LangChain. The handler is purely additive — you attach it via the
callbacksconfig argument and remove it the same way.
Repository
Source and issue tracker: jstibal/openterms.
License
Apache-2.0.
Metadata
Release files for langchain-openterms 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_openterms-1.0.1.tar.gz | 7.4 kB | Without provenance | Details for langchain_openterms-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_openterms-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for langchain_openterms-1.0.1-py3-none-any.whl |
Total release size: 13.6 kB
Release files / langchain_openterms-1.0.1.tar.gz
| Download URL | langchain_openterms-1.0.1.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6067b4af53216668ec3a7fe664a727485307ee7233dd8111a82b38e48c1d24a0
|
|
BLAKE2b-256 checksum How to use checksums |
69274eb4cf02386e74d624b85210c8eb15c1f3d9dc4715b38dda79120a962423
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / langchain_openterms-1.0.1-py3-none-any.whl
| Download URL | langchain_openterms-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ca3accb931b022b97bca938a9402a34371aa10e0ae3b2cfa79ed9053348c820
|
|
BLAKE2b-256 checksum How to use checksums |
fff9c740a9b6a2030618d9978a5925051461765d11dfe083731f5dd3860d8453
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for langchain-openterms 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.