This project has been archived by its maintainers, and is no longer receiving any updates.
braintrust-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())
Passing Handlers Explicitly
If you'd prefer to pass the callback handler to specific LangChain calls instead of setting it globally, you can do so using the callbacks config option:
async def main():
handler = BraintrustCallbackHandler()
# Pass the handler to specific calls
response = await chain.ainvoke(
{"number": "2"},
config={"callbacks": [handler]}
)
# Or initialize components with the handler
model = ChatOpenAI(callbacks=[handler])
Supported Features
The callback handler supports logging for:
- LLM calls (including streaming)
- Chat model interactions
- Chain executions
- Tool/Agent usage
- Memory operations
- State management (LangGraph)
Review the LangChain documentation for more information on how to use callbacks.
Documentation
- Braintrust docs: https://www.braintrust.dev/docs
- Braintrust Python SDK docs: https://www.braintrust.dev/docs/reference/sdks/python
- LangChain callback docs: https://python.langchain.com/docs/modules/callbacks/
Metadata
Release files for braintrust-langchain 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| braintrust_langchain-0.3.0.tar.gz | 3.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| braintrust_langchain-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.5 kB
Release files / braintrust_langchain-0.3.0.tar.gz
| Download URL | braintrust_langchain-0.3.0.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89d017ce71ab2570c631f69d43d3f9b47716312239658ec8ca18ad7e0d19d867
|
|
BLAKE2b-256 checksum How to use checksums |
409f595066dce79c672a4b28c4188f6a11c28fbcb3677dce8e60e3da6cae3515
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.8
|
Release files / braintrust_langchain-0.3.0-py3-none-any.whl
| Download URL | braintrust_langchain-0.3.0-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a661c56c79bb7d07ea28db13f4ba1d2ca2997d8963c9f475ec8853699ffb5c3
|
|
BLAKE2b-256 checksum How to use checksums |
9b828418db2207955f2d3bccb5ec8f3215f3498d2ac90454b6501bb9a0bc8c9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.8
|