Skip to main content

raindrop-langchain

Raindrop integration for LangChain (Python). Automatically captures LLM calls, tool usage, chains, and retrievers via LangChain's callback system.

Installation

pip install raindrop-langchain langchain-core

Quick Start

from raindrop_langchain import RaindropLangchain
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage

raindrop = RaindropLangchain(
    api_key="rk_...",
    user_id="user-123",
)

model = ChatOpenAI(model="gpt-4o")

result = model.invoke(
    [HumanMessage(content="Hello!")],
    config={"callbacks": [raindrop.handler]},
)

raindrop.flush()

Factory Function (alternative)

from raindrop_langchain import create_raindrop_langchain

raindrop = create_raindrop_langchain(api_key="rk_...", user_id="user-123")
model = ChatOpenAI(model="gpt-4o")
result = model.invoke("Hello!", config={"callbacks": [raindrop.handler]})
raindrop.flush()

Projects

Route events to a specific project by passing its slug as project_id:

raindrop = RaindropLangchain(
    api_key="rk_...",
    project_id="support-prod",
)

project_id sets the X-Raindrop-Project-Id header on every event. Omit it (or pass "default") to use your org's default Production project, which is the existing behavior. The same option is accepted by the create_raindrop_langchain(...) factory. Invalid slugs are ignored with a warning and no header is sent.

What Gets Captured

  • LLM calls — model name, input, output, token usage, finish reason
  • Tool calls — tool name, input arguments, output, duration (via interaction.track_tool() spans)
  • Chains — execution tracking
  • Retrievers — query and document count
  • Errors — error type and message captured in event properties
  • Extended token categories — cached tokens (ai.usage.cached_tokens) and reasoning tokens (ai.usage.thoughts_tokens) when available from the provider (e.g. OpenAI)
  • Finish reason — captured as ai.finish_reason in event properties (e.g. "stop", "length")

Debug Mode

Enable verbose logging with debug=True:

raindrop = RaindropLangchain(
    api_key="rk_...",
    debug=True,
)

Identify Users

Associate events with a user after initialization:

raindrop.identify("user-123", {"name": "Alice", "plan": "pro"})

Track Signals

Send feedback, edits, or custom signals:

raindrop.track_signal(
    event_id="evt-abc",
    name="thumbs_up",
    signal_type="feedback",
    sentiment="POSITIVE",
)

Flushing and Shutdown

raindrop.flush()     # flush pending data
raindrop.shutdown()  # flush + release resources

API Reference

RaindropLangchain

Parameter Type Default Description
api_key Optional[str] None Raindrop API key. If None, telemetry is disabled
user_id Optional[str] None Associate all events with a user
convo_id Optional[str] None Group events into a conversation
project_id Optional[str] None Route events to a specific project (slug); omit for the default Production project
trace_chains bool True Track chain execution
trace_retrievers bool True Track retriever calls
filter_langgraph_internals bool True Filter LangGraph-internal chain events and deduplicate LLM callbacks
event_name str "ai_generation" Event name applied to every event (the event field in the dashboard)
tracing_enabled bool True Enable distributed tracing
bypass_otel_for_tools bool True Bypass OTEL for tool spans
debug bool False Enable debug logging

Methods

Method Description
handler Property — the LangChain callback handler to pass into config={"callbacks": [...]}
flush() Flush all pending events to the Raindrop API
shutdown() Flush remaining events and release resources
identify(user_id, traits) Identify a user with optional traits
track_signal(event_id, name, ...) Track a signal event

Async Support

The callback handler inherits from LangChain's AsyncCallbackHandler and works with both synchronous and asynchronous LangChain invocations.

result = await model.ainvoke(
    [HumanMessage(content="Hello!")],
    config={"callbacks": [raindrop.handler]},
)

LangGraph Support

Works with LangGraph out of the box. The handler automatically filters LangGraph-internal chain events and deduplicates LLM callbacks. Pass the handler to the model inside your LLM node — not to graph.invoke(). See examples/langchain-langgraph-python-basic/ for a full example.

LangSmith Coexistence

Raindrop and LangSmith can run simultaneously. Set LANGSMITH_TRACING=false to disable LangSmith if you only want Raindrop.

Payload size bounds

Payloads the handler serializes itself — multi-modal chat content lists and agent-action tool inputs — are bounded to 1,000,000 characters with a ...[truncated by raindrop] marker. The bound is enforced during serialization (cost proportional to the cap, not the payload), so a multi-MB content list (e.g. base64 image parts) can't stall your event loop inside a synchronous callback. Plain-string prompts and tool outputs are capped by the Raindrop SDK's own per-field limit (max_text_field_chars, raindrop-ai

= 0.0.51).

Known Limitations

  • Multi-LLM chain data: In ReAct loops with multiple child LLMs, only the last child's data survives (Python SDK uses one-shot track_ai vs TS's accumulative EventShipper.patch).
  • Error-path input loss: On LLM errors, the input captured during on_llm_start is not forwarded to the finalized event.

Testing

cd packages/langchain-python
pip install -e .
python -m pytest tests/ -v

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

raindrop_langchain-0.0.11.tar.gz (37.8 kB view details)

Uploaded Source

Built Distribution

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

raindrop_langchain-0.0.11-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file raindrop_langchain-0.0.11.tar.gz.

File metadata

  • Download URL: raindrop_langchain-0.0.11.tar.gz
  • Upload date:
  • Size: 37.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for raindrop_langchain-0.0.11.tar.gz
Algorithm Hash digest
SHA256 619520359d2c62592b8ab16cb2e7d2b72c4a77dd32faef84ed3ecc2c6a91632d
MD5 a35252bc89570bbd6806722c732ee4c7
BLAKE2b-256 665d8647fb6f668bfd5b3126baf008f38366315647b8758032e1e56b21613214

See more details on using hashes here.

File details

Details for the file raindrop_langchain-0.0.11-py3-none-any.whl.

File metadata

File hashes

Hashes for raindrop_langchain-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 23a8ff07ebe154bf1c42b513e8d8d65ba00e336578931af649b564636f15adae
MD5 11612fc73812def7ee3ef511efa371c2
BLAKE2b-256 da1ee0c2ebae3b72ea89964f611bf296a297cc1fe234e6d93efc754658d434fc

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 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