LangChain
Overview
LangChain is a framework for building LLM applications. Confident AI provides a CallbackHandler to trace and evaluate LangChain applications.
Tracing Quickstart
Configure LangChain
Provide DeepEval’s CallbackHandler to your LangChain application’s invoke method.
DeepEval’s CallbackHandler extends LangChain’s
BaseCallbackHandler
or LangChain.js’
BaseCallbackHandler.
Run LangChain
Invoke your application by executing the script:
You can directly view the traces on Confident AI by clicking on the link in the output printed in the console.
Advanced Features
Set trace attributes
Confident AI’s LLM tracing advanced features provide teams with the ability to set certain attributes for each trace when invoking your LangChain application.
For example, thread_id and user_id are used to group related traces together, and are useful for chat apps, agents, or any multi-turn interactions. You can learn more about threads here.
You can set these attributes in the CallbackHandler when invoking your LangChain application.
View Trace Attributes
The name of the trace. Learn more.
Tags are string labels that help you group related traces. Learn more.
Attach any metadata to the trace. Learn more.
Supply the thread or conversation ID to view and evaluate conversations. Learn more.
Supply the user ID to enable user analytics. Learn more.
Each attribute is optional, and works the same way as the native tracing features on Confident AI.
Logging prompts
If you are managing prompts on Confident AI and wish to log them, pass your Prompt object to the language model instance’s metadata parameter.
Logging prompts lets you attribute specific prompts to OpenAI Agent LLM spans. Be sure to pull the prompt before logging it, otherwise the prompt will not be visible on Confident AI.
Evals Usage
Online evals
If your LangChain application is in production, and you still want to run evaluations on your traces, use online evals. It lets you run evaluations on all incoming traces on Confident AI’s server.
Create metric collection
Create a metric collection on Confident AI with the metrics you wish to use to evaluate your LangGraph agent. Copy the name of the metric collection.
The current LangChain integration supports metrics that only evaluate Input
and Actual Output in addition to the Task Completion metric.
Run evals
Set the metric_collection name to evaluate various components of your LangChain application.
Agent Span
LLM Span
Tool Span
This is the top level component of your LangChain application. Also a very idle component to evaluate with the Task Completion metric.
All incoming traces will now be evaluated using metrics from your metric collection.
End-to-end evals
Running end-to-end evals on your LangChain agent evaluates your agent locally, and is the recommended approach if your agent is in a development or testing environment.
Similar to online evals, you can only run end-to-end evals on LangChain using
TaskCompletionMetric.
View on Confident AI
You can view the evals on Confident AI by clicking on the link in the output printed in the console.