Skip to main content

LangInsight callback handler for LangChain - Monitor and trace your LangChain LLM applications

Project description

LangInsight LangChain Integration

LangChain integration for LangInsight observability platform.

Installation

pip install langinsight-langchain

Or with Poetry:

poetry add langinsight-langchain

Usage

from langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate
from langinsight_langchain import CallbackHandler

# Create the LangInsight callback handler
handler = CallbackHandler(
    api_key="your-api-key",
    endpoint="https://api.langinsight.io",
    user_id="user-123",
    session_id="session-456",
)

# Create your chain with LangInsight handler
prompt = ChatPromptTemplate.from_messages(["Tell me a joke about {animal}"])

model = ChatAnthropic(
    model="claude-3-7-sonnet-20250219",
    callbacks=[handler],
)

chain = prompt | model
response = chain.invoke({"animal": "bears"})

Environment Variables

You can also configure using environment variables:

import os
from langinsight_langchain import CallbackHandler

handler = CallbackHandler(
    api_key=os.environ["LANGINSIGHT_API_KEY"],
    endpoint=os.environ.get("LANGINSIGHT_ENDPOINT", "https://api.langinsight.io"),
    user_id="user-123",
    session_id="session-456",
)

Development

# Install dependencies
poetry install

# Run example
poetry run python examples/basic_usage.py

License

MIT

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

langinsight_langchain-0.0.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

langinsight_langchain-0.0.1-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file langinsight_langchain-0.0.1.tar.gz.

File metadata

  • Download URL: langinsight_langchain-0.0.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/24.6.0

File hashes

Hashes for langinsight_langchain-0.0.1.tar.gz
Algorithm Hash digest
SHA256 eec4c8126b35d816b68322d1bca3bfa47d918d1280df385e8ec69a2d3086ddd6
MD5 1ceff465be7b2108fdce31b36af5dc47
BLAKE2b-256 b21a5aea03b516df34af1cb26ecb0a7c5edc96dbef0816c5eac23b92299ac927

See more details on using hashes here.

File details

Details for the file langinsight_langchain-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langinsight_langchain-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d4916a92e6500e360b66a54825b0a9253eed8e97d1490f1f0ecb7659e12895d6
MD5 17fc4adc7e941f22467f242deefddd85
BLAKE2b-256 d62e476bdc18ab289a1b223ae90bda83ee2949420ba50b77f20196e68d896077

See more details on using hashes here.

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