Skip to main content
Amazon SageMaker is a fully managed service that is used to quickly and easily build, train and deploy machine learning (ML) models.
Amazon SageMaker Experiments is a capability of Amazon SageMaker that lets you organize, track, compare and evaluate ML experiments and model versions.
This notebook shows how LangChain Callback can be used to log and track prompts and other LLM hyperparameters into SageMaker Experiments. Here, we use different scenarios to showcase the capability:
  • Scenario 1: Single LLM - A case where a single LLM model is used to generate output based on a given prompt.
  • Scenario 2: Sequential Chain - A case where a sequential chain of two LLM models is used.
  • Scenario 3: Agent with Tools (Chain of Thought) - A case where multiple tools (search and math) are used in addition to an LLM.
In this notebook, we will create a single experiment to log the prompts from each scenario.

Installation and setup

First, setup the required API keys

LLM Prompt tracking

Scenario 1 - LLM

Scenario 2 - sequential chain

Scenario 3 - Agent with tools

Load log data

Once the prompts are logged, we can easily load and convert them to Pandas DataFrame as follows.
As can be seen above, there are three runs (rows) in the experiment corresponding to each scenario. Each run logs the prompts and related LLM settings/hyperparameters as json and are saved in s3 bucket. Feel free to load and explore the log data from each json path.