DEPRECATED: LangChain integration is now included in the main braintrust package. Install braintrust instead.
Deprecated. Its authors have deprecated it and no longer maintain it.
pip install braintrust-langchainbraintrust-langchain (DEPRECATED)
SDK for integrating Braintrust with LangChain. This package provides a callback handler to automatically log LangChain executions to Braintrust.
This package is deprecated. The LangChain integration is now included in the main
braintrustpackage.
Migration
- Remove
braintrust-langchainfrom your dependencies - Install or upgrade
braintrust:pip install --upgrade braintrust - Update your imports:
# Before from braintrust_langchain import BraintrustCallbackHandler, set_global_handler # After (option 1: same explicit callback API from the main package) from braintrust.integrations.langchain import BraintrustCallbackHandler, set_global_handler # After (option 2: helper that initializes Braintrust and installs the global handler) from braintrust.integrations.langchain import setup_langchain setup_langchain(project_name="your-project-name")
The callback API is the same - no code changes are needed beyond the package/import path.
Installation
pip install braintrust-langchain
Requirements
- Python >= 3.10
- LangChain >= 0.3.27
Quickstart
First, make sure you have your Braintrust API key set in your environment:
export BRAINTRUST_API_KEY="your-api-key"
import asyncio
from braintrust import init_logger
from braintrust_langchain import BraintrustCallbackHandler, set_global_handler
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
async def main():
# Initialize the logger with your project
init_logger(project="your-project-name")
# Create the callback handler and set it globally for all LangChain components
handler = BraintrustCallbackHandler()
set_global_handler(handler)
# Initialize your LangChain components
prompt = ChatPromptTemplate.from_template("What is 1 + {number}?")
model = ChatOpenAI()
# Create a simple chain
chain = prompt | model
# Use LangChain as normal - all calls will be logged to Braintrust
response = await chain.ainvoke({"number": "2"})
if __name__ == "__main__":
asyncio.run(main())