Skip to main content

moss-langchain

MOSS signing integration for LangChain. Unsigned output is broken output.

PyPI

Installation

pip install moss-langchain

Quick Start: Explicit Signing (Recommended)

Sign specific outputs with full control:

from langchain_openai import ChatOpenAI
from moss_langchain import sign_tool_call, sign_chain_result, sign_message

# Sign a tool call
tool_call = {"name": "get_weather", "args": {"location": "NYC"}, "id": "call_123"}
result = sign_tool_call(tool_call, agent_id="weather-bot")
print(f"Signed: {result.signature[:20]}...")

# Sign a chain result
chain = ChatOpenAI() | StrOutputParser()
output = chain.invoke("What is 2+2?")
result = sign_chain_result(output, agent_id="math-bot", chain_name="calculator")

# Sign a message
message = AIMessage(content="The answer is 4")
result = sign_message(message, agent_id="math-bot")

Enterprise Mode

Set MOSS_API_KEY for automatic policy evaluation:

import os
os.environ["MOSS_API_KEY"] = "your-api-key"

from moss_langchain import sign_tool_call, enterprise_enabled

print(f"Enterprise: {enterprise_enabled()}")  # True

# Tool calls are evaluated against policies
result = sign_tool_call(
    {"name": "send_email", "args": {"to": "user@example.com"}, "id": "call_1"},
    agent_id="email-bot",
    context={"user_id": "u123"}
)

if result.blocked:
    print(f"Blocked by policy: {result.policy.reason}")

Callback Handler for Auto-Signing

For automatic signing of all chain events:

from moss_langchain import MOSSCallbackHandler

# Create handler - signs tool calls and chain outputs
handler = MOSSCallbackHandler(
    agent_id="my-agent",
    sign_tools=True,
    sign_chains=True
)

chain = ChatOpenAI() | StrOutputParser()
result = chain.invoke("Hello", config={"callbacks": [handler]})

# Access signed envelopes
for envelope in handler.envelopes:
    print(f"Signed: {envelope.subject}")

Verification

from moss_langchain import verify_envelope

# Verify any signed envelope
verify_result = verify_envelope(result.envelope)
if verify_result.valid:
    print(f"Signed by: {verify_result.subject}")

All Functions

Function Description
sign_tool_call() Sign a LangChain tool call
sign_chain_result() Sign chain output
sign_message() Sign an AI message
sign_tool_result() Sign tool execution result
sign_output() Sign any output (generic)
verify_envelope() Verify a signed envelope

Legacy API

The old auto-signing API is still available for backwards compatibility:

from moss_langchain import enable_moss, SignedCallbackHandler

enable_moss("moss:myteam:agent")  # Global auto-signing
cb = SignedCallbackHandler("moss:bot:summary")  # Per-chain signing

Enterprise Features

Feature Free Enterprise
Local signing ✓ ✓
Offline verification ✓ ✓
Policy evaluation - ✓
Evidence retention - ✓
Audit exports - ✓

Links

License

This package is licensed under the Business Source License 1.1.

  • Free for evaluation, testing, and development
  • Free for non-production use
  • Production use requires a MOSS subscription
  • Converts to Apache 2.0 on January 25, 2030

Metadata

Release files for moss-langchain 1.0.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 moss-langchain 1.0.0
File Size Uploaded
moss_langchain-1.0.0.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for moss-langchain 1.0.0
File Interpreter ABI Platform
moss_langchain-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.0 kB

Release files / moss_langchain-1.0.0.tar.gz

Download URL moss_langchain-1.0.0.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
efb1dc932965098664ae2988486f645f2b960d7ff06608a6b399864222fcc91b
BLAKE2b-256 checksum
How to use checksums
42eac671b1f51bf6fc1fc562e508e7314cbd7c79ff56ad063f6a48ee945de1bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.

Transparency log

Release files / moss_langchain-1.0.0-py3-none-any.whl

Download URL moss_langchain-1.0.0-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af17737a2a81580d034cd06085bdd877c3972605371542e1472284d5f657e1b8
BLAKE2b-256 checksum
How to use checksums
52f7b0ca88be6592613ce6bdbd888da108520c4b256477c03e3aff0bbba2a978
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.0

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