Skip to main content
The Galileo LangChain integration allows you to automatically log all LangChain and LangGraph interactions with LLMs, including prompts, responses, and performance metrics. The Galileo SDK has a custom callback that is passed to LangChain or LangGraph.

GalileoCallback - Python

The Python Galileo Synchronous LangChain SDK reference.

GalileoAsyncCallback - Python

The Python Galileo Asynchronous LangChain SDK reference.

GalileoCallback - TypeScript

The TypeScript Galileo LangChain SDK reference.

Basic usage

The integration is based on the GalileoCallback class, which implements LangChain’s callback interface. To use it, create an instance of the callback and pass it to your LangChain components:
The GalileoCallback captures various LangChain events, including:
  • LLM starts and completions
  • Chat model interactions
  • Chain executions
  • Tool calls
  • Retriever operations
  • Agent actions
For each of these events, the callback logs relevant information to Galileo, such as:
  • Input prompts and messages
  • Output responses
  • Model information
  • Timing data
  • Token usage
  • Error information (if any)
The GalileoCallback automatically handles nested chains and agents, creating a hierarchical trace that reflects the structure of your LangChain application.

Asynchronous callbacks

In Python, there are separate callbacks for synchronous and asynchronous code. If you are using the asynchronous LangChain or LangGraph API, use the GalileoAsyncCallback callback handler. In TypeScript, the standard GalileoCallback handles async natively — no separate class is needed.

Use a custom logger

When initializing the GalileoCallback, you can optionally specify a Galileo logger instance, either by creating a new logger, or by using the current logger from the Galileo context:
This is particularly useful if you want to call your LangChain code from inside a function decorated with the log decorator, or from inside an experiment.

Session and trace support

Every time you invoke a chain or an LLM call, a new session and trace is created. If you want to manually manage sessions or traces, you can do this using by passing a Galileo logger instance to the callback. To add the chain or LLM call invocation as a new trace to an existing session, create the session first using the logger instance that was used to create the callback:
To add the chain or LLM call invocation to an existing trace, ensure the trace is started, and set the start_new_trace parameter to False (Python) or false (TypeScript).

Use with LangChain chains

You can also use the callback with LangChain chains. Make sure to pass the callback to both the LLM and the chain.

Add metadata

You can add custom metadata and tags to your logs by including them in the metadata and tags parameters of a LangChain runnable configuration when invoking a chain or LLM.
This metadata will be attached to the logs in Galileo, making it easier to filter and analyze your data. A chain node in a trace with metadata attached

Best practices

  1. Pass callbacks consistently: Make sure to pass the callback to all LangChain components (LLMs, chains, agents, etc.) to ensure complete logging.
  2. Include meaningful metadata: Add relevant metadata to your invocations to make it easier to filter and analyze your logs.

Next steps

Basic logging components

Galileo logger

Log with full control over sessions, traces, and spans using the Galileo logger.

Log decorator

Quickly add logging to your code with the log decorator and wrapper.

Galileo context

Manage logging using the Galileo context manager.

Cookbooks

Monitor LangChain Agents with Galileo

Learn how to build and monitor a LangChain AI Agent using Galileo for tracing and observability.

Add evaluations to a multi-agent LangGraph application

Learn how to add evaluations to a multi-agent LangGraph chat bot using Galileo