Skip to main content

MOSS signing integration for LangChain via callback handler

Project description

moss-langchain

MOSS signing integration for LangChain via callback handler.

Installation

pip install moss-langchain

Usage

from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from moss_langchain import SignedCallbackHandler

# Create callback handler
cb = SignedCallbackHandler("moss:bot:summary")

# Create your chain
chain = ChatPromptTemplate.from_template("Summarize: {text}") | ChatOpenAI()

# Invoke with callback
result = chain.invoke(
    {"text": "Long document..."},
    config={"callbacks": [cb]}
)

# Access the signature
envelope = cb.envelope

Verification

from moss import Subject

# Verify the output
result = Subject.verify(cb.envelope)
assert result.valid

Multiple Outputs

The handler tracks all outputs during a session:

cb = SignedCallbackHandler("moss:bot:pipeline")

# Run multiple operations
chain1.invoke(input1, config={"callbacks": [cb]})
chain2.invoke(input2, config={"callbacks": [cb]})

# Access all envelopes
for envelope in cb.envelopes:
    print(f"Seq {envelope.seq}: {envelope.payload_hash}")

# Clear for next session
cb.clear()

Async Chains

from moss_langchain import AsyncSignedCallbackHandler

cb = AsyncSignedCallbackHandler("moss:bot:async")
result = await chain.ainvoke(input, config={"callbacks": [cb]})

Signed Events

The handler signs outputs from:

  • on_llm_end - LLM generation complete
  • on_chain_end - Chain execution complete
  • on_tool_end - Tool execution complete
  • on_agent_finish - Agent finished
  • on_retriever_end - Retriever returned documents

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

moss_langchain-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moss_langchain-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file moss_langchain-0.1.0.tar.gz.

File metadata

  • Download URL: moss_langchain-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for moss_langchain-0.1.0.tar.gz
Algorithm Hash digest
SHA256 35148799daef5481e9be5156541e9b61e948e7a0277ae45efd48ad8f44aab618
MD5 83b2eba380946dc3e8635a0f7485b64e
BLAKE2b-256 e60ffc990f6a75b1088964e686a684e3e708cf1e91a973fc8fe22e9f13a62c5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for moss_langchain-0.1.0.tar.gz:

Publisher: release.yml on mosscomputing/moss-langchain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file moss_langchain-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: moss_langchain-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for moss_langchain-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3525b6ad52face4df74522a18d0e6b4da8678b5d2b2dd7efe6313ea375f49a80
MD5 3e7d7c841455414a113c1a7e86557bd6
BLAKE2b-256 2dc783ba15d54e2776bbc403e62993443834db662ef76e4ea3aac09f8f6b2018

See more details on using hashes here.

Provenance

The following attestation bundles were made for moss_langchain-0.1.0-py3-none-any.whl:

Publisher: release.yml on mosscomputing/moss-langchain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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