transcribe

Run LLM Evals with Pytest and LangSmith

LangChain · 15m · transcribed Jul 2026
More from LangChain Business
𝕏 Share ▶ YouTube 📥 PDF 🤖 .md

Section Insights

# 0:00

Introduction to Lang Smith and Pytest Integration

Why should developers use the Lang Smith integration with Pytest for LLM applications?

The Lang Smith integration with Pytest enhances the testing experience for LLM applications by maintaining familiar features while adding powerful debugging and evaluation capabilities.

  • Lang Smith integration makes testing LLM applications easier and more efficient.
  • It retains the familiar Pytest commands and functions.
  • The integration allows for better tracking and debugging of evaluation results.
# 3:10

Team Collaboration in LLM Development

How does the integration facilitate team collaboration in LLM application development?

The integration provides a shared platform for teams, including non-technical stakeholders, to view evaluation results, which is essential for quick iterations and improvements.

  • Collaboration is key in LLM development, involving various roles beyond developers.
  • A centralized location for evaluation results aids in team communication and decision-making.
  • Built-in evaluation functions streamline measuring LLM app performance.
# 6:21

Logging Inputs and Outputs

How can developers log inputs and outputs in their tests using Lang Smith?

Developers can use the logging methods provided by Lang Smith to track inputs and outputs during testing, which helps in understanding the behavior of the LLM applications.

  • Logging inputs and outputs enhances visibility into test cases.
  • Developers can choose to log optional reference outputs for better tracking.
  • Feedback logging allows for detailed analysis without breaking the test flow.
# 9:31

Using Decorators for Feedback Logging

What is the purpose of using decorators in the Lang Smith integration?

Decorators in Lang Smith are used to encapsulate feedback logging, allowing developers to separate application traces from feedback traces for clearer insights.

  • Decorators help in organizing and managing feedback logging.
  • They allow for detailed tracking of application performance and feedback separately.
  • Using context managers enhances the clarity of logged information.
# 12:42

Reviewing Test Results and Metrics

What features does Lang Smith provide for reviewing test results?

Lang Smith allows users to view detailed results, including scores and metrics, and provides a trace view for debugging and comparison with previous runs.

  • Users can track various metrics and scores for their LLM applications.
  • The trace view feature aids in debugging by showing exact inputs and outputs.
  • Lang Smith facilitates sharing results with colleagues for collaborative analysis.

Transcript

0:01 if you've written software before you've probably written tests for that software and if you're using python you've probably used P test to do so if you're building applications that use llms you probably want to write tests for those applications and those features it makes a ton of sense to use P tests to do so to evaluate those llm applications because you get all the conveniences of running it in a way that you're already familiar with today we're excited to announce a

0:31 lang Smith integration with a p test SDK this will make running evals and tests for your llm applications 10 times better in addition to getting an output like this you can also get an output like this this will track all the results of your evals over time it will let you dive in and debug which ones are going wrong it'll let you share them with non-technical

1:03 stakeholders and it will let you log metrics besides just the past fail in this video I'll walk through why you should care about this and why you should use this and then I'll show a simple example of how to set this up let's dive in all right so why should you use the Lang Smith P test integration first and foremost it's worth emphasizing that this keeps the exact same features and development experience as you get with p

1:29 P test so you get all of the commands all of the helper functions all of the command line ability that you are used to when you use pest this is super handy it allows you to run your software testing evals with the same Tex stack as you're using to run your llm tests in eval so it keeps it in a centralized spot but there are additional things that you get by using Lang Smith so first you get tracing of specific runs

1:56 to Lang Smith so this is great for allowing you to debug while failures occur if I'm looking at a p test output I often just get the past failure but I want to dive in and see more and this is especially important in llm applications where it's crucial to look at your data it's crucial to know exactly what's going in and coming out of each step and so the Lang Smith integration lets you do this and it gives you a superior

2:19 debugging experience secondly it allows you to log metrics not just pass and fail when building llm applications you might want to log a variety of numerical or categorical metrics for a particular run there may not be a clear-cut pass fail criteria but there may be some metrics that you want to log and then you want to track the average of this over time and that gets into the third point it allows you to track results over time

2:46 when you're evaluating llm applications it's often times not just a simple pass fail for each test case rather there's some gradient of success and what you care about is moving that success metric up up and up and making it better and better over time and so our Lang Smith integration lets you track this next it allows you to share these results with others this is really important because building llm applications is not just a single developer or even just developers

3:16 that are doing it rather it's a whole team effort we see subject matter experts and product managers getting involved all the time and so having a shared spot where they can look at the results of these evaluations is crucial for allowing the team to iterate quick and finally we have buil-in evaluation functions that help speed up and give you San defaults for when you're trying to measure the success of how your llm apps are performing let's now take a look at some

3:44 code before and after integrating Lang Smith so this is a pretty standard test file here I can see that I have two tests and here I'm pretending that I'm building basically a marketing agent so I have two tests one for writing a tweet about llms and one for writing a LinkedIn post about llms I can see here that I'm importing this function called generate marketing copy this is the llm application that I'm building if I go in

4:10 here it's just a single call to an llm although you can imagine that this is a more complex agent down the line and and and that's actually a place where this integration shines but for now it's just a simple llm call and you can see here that the system prompt I gave it is you are an expert technical marketer and then I give it the request so I have these to requests that I'm looking at write a tweet about

4:32 LMS write a LinkedIn post about llms I call this function and then I start asserting things so I assert that the length of the response is less than 280 for the tweet and I assert that it's greater than 280 for the LinkedIn post for the LinkedIn post I also assert that there are multiple new lines because I like to have that in my LinkedIn posts and then I have this function score marketing copy this is actually an llm

4:54 as a judge evaluator so if I go into utils I have the score marketing copy function and here I can see that I'm passing it into another model and asking it to score it on a scale of 1 to 10 then back here I am taking the result of that and I'm asserting that the score is greater than eight these are still just totally vanilla P test things so I can evaluate them by going to my command line and

5:20 Running P test tests I can see that it starts running it's logging the output as a normally does with P test and I can see that it fails and so the first one here fails where I have a tweet that's longer than 280 characters great so this is what the normal development experience looks like and for all the reasons mentioned before this can be improved with the Lang Smith integration so let's take a look at how

5:51 I would do that because it's pretty easy I've got the documentation for doing this Lang Smith and Pi test integration here let's scroll down and I'll see that it's pretty easy to add it in here the first thing I'm going to do is Mark the test cases as a lsmith test case and so I can do that by doing this and I can see that I'm going to have to do import P test to make that real

6:17 awesome what next let's go back here and I can see that I start logging inputs and so here I have this line which I'm going to import here and so I'm going to do from lsmith import testing I can then do the log inputs method so let's grab this let's do testing. log

6:50 inputs and the reason I'm doing this is this will show up in the test cases that'll be in the Lang Smith UI all right awesome now I can do the same thing with the result but instead of log inputs I'm going to do log outputs all right easy what's next after that I can see that in this example I

7:21 log the reference outputs so this is useful when I have an expected answer that I want the generation to be in this case I don't so I'm actually going to skip this so all of these are are optional I don't have to do it if I don't want to then I can see that I do this log feedback so I am going to do this and this is going to start logging feedback to lsmith so the first thing I might

7:41 want to log is stuff to do with the length of the response so here I can see that I test that the response is less than 280 characters so I'm actually going to log a few things the first thing I'm going to log is just the overall length of the generation so let's change this to that all right awesome I'm just logging the overall length of the application and next I'm going to log a Boolean so let's do

8:09 Twitter length and this is going to assert the length of the response is less than 280 so I'm taking the same assertion here and I'm just putting it as a feedback key that I'm logging note that I could keep this assert here the reason to keep the assert here would be to break basically if I don't want to go past this so it's still log everything up to this spot but then when I hit this assertion I would break here I just want

8:35 to log things I don't actually want to break or error if if this fails so I'm going to remove this but again that's totally just my choice here I'm going to do the same thing except I'm going to change it to greater than 280 because it's a LinkedIn post and I'm going to change that to LinkedIn length I'm going to remove that all right I can see that here I test that there's the these new lines so

8:57 let me do that again and I will do new lines and the score will be a Boolean here and you know what I'm going to add in another numerical score because that's part of the value of using the Lang Smith integration is that I can log things that are not just Boolean pass fail and so new lines count and I'm just going to do response. count the new lines great all right and so now I have this

9:26 final bit which is the score marketing copy so one thing that I want to do and and so remember this is calling an llm as a judge evaluator so what I want to do is I want to actually wrap this in a special type of decorator so here I can see that there's a section on logging feedback and I can use this context manager to basically encapsulate any traces that belong not to the application but rather to the feedback

9:57 so we haven't talked about it yet but I'm going to make a few simple changes to this LM application as well so I can start tracing it so I can see the full kind of like trajectory of what happens I also call an llm here and so I don't want to conflate those two things I don't want those to be treated as the same so what I'm going to do is I'm going to do this decorator or sorry this

10:15 context manager I'm going to call this and then inside this context manager and we'll see why this is important in a little bit but inside this context manager I'm just going to log the feedback of score and I'll just do score. score there we go perfect and I'm going to do the same thing here except we can notice that I pass in LinkedIn post here all right awesome and then the last thing is

10:48 as I mentioned I am going to decorate my code in the Lang Smith traceables so you'll notice here that I'm not using Lang chain or anything like that but I want to trace this I want to know what's going on so what I'm going to do is I'm going to do from Lang Smith import traceable and then I'm going to decorate it traceable there and I'm going to do the same thing in my llm as a

11:21 judge and then I can also see here that we have this wrapper for the open AI SDK which automatically logs things to Lang Smith so again this is no Lang chain this is just logging directly from the open AI SDK and so I am going to do that here and do the same thing in my agent great so that's all it takes to do

11:51 the Lang Smith integration what I did was I just marked these as lsmith test cases I explicitly logged the inputs outputs and feedback and then I decorated my code to get the tracing now let's see how I run this and how I log results to lsmith so the way that I run this is exactly the same I can just run P test tests I'll notice that this fails at start because I have not exported my link Smith API key so let me do that and

12:20 then I'll come right back all right I'm back I exported that let's run it again all right I get another error I need to set Langs Smith tracing equals to True great let's run it again awesome and I can see that it's

12:51 running now after it finishes running I can go to Lang Smith to check out the results I can see that I've got this new row here of result I can see that I'm tracking certain results up top such as the score of the llm greater the length of the text Etc I can click in to a given run and I can see that I have my two results here I have the input and the outputs and then if I also open it

13:22 up in this detailed view I can see the variety of different metrics that I left scores for so I can see the length L the L the the Boolean for whether it is longer than 280 this is the LinkedIn length score the number of new lines and then whether this is greater than two and then the score overall so this got graded in eight and then I can also see the input and the output here if I

13:46 click into the output I have this view Trace button let's click in there and I can see that I load this Trace here this is the function that I called and inside this function this is the direct call to open Ai and if I load this up I can see the exact prompt that went in including my system message and the exact output that came out so now this is super handy because I can view the results here I can see the

14:10 scores I can share this with a colleague because this is all on hosted on the on the web I can look at the traces I can debug what's going wrong and I can compare them to previous runs and I can start to track success over time or narrow in when things are failing we're really excited about this Langs Smith py test integration because we think it brings the best of Two Worlds together it brings the software

14:35 engineering World which uses Pi test to run unit tests integration tests all of that together with some of the ML and data science cetric evaluation tools that we see people using to really dig into these probabilistic and non-deterministic applications there's a lot of additional functionality in this integration such as how to trace intermediate calls grouping tests into test Suites naming experiments caching so you don't have to make repeated calls to an llm and of

15:05 course you can use all of these with existing P test features like parameterize xist async iio and watch there's also a really cool local mode that will run it locally in print out results let's see what this looks like so I just pass output equals LS here and then it'll print out some intermediate outputs and even better I'll get an awesome little local report right in my terminal at the end and so I

15:37 can see a little bit about the inputs and outputs but then also more importantly all the feedback that's left the duration that it took and other information give it a try and let us know what you think thanks

Summary

The video introduces a new integration between Lang Smith and the Pytest SDK, designed to enhance testing for applications utilizing large language models (LLMs). This integration allows developers to maintain their familiar testing workflow while gaining advanced features for tracking, debugging, and sharing results, ultimately improving the evaluation of LLM applications.

- Lang Smith integration with Pytest improves testing for LLM applications by maintaining familiar features while adding new capabilities.
- It allows for detailed tracking of evaluation results over time, facilitating better debugging and analysis.
- Users can log various metrics beyond simple pass/fail outcomes, which is crucial for nuanced LLM performance evaluation.
- The integration supports collaboration by enabling sharing of results with non-technical stakeholders.
- Built-in evaluation functions streamline the process of measuring LLM application performance.
- Developers can easily implement the integration by marking test cases and logging inputs, outputs, and feedback.
- The integration includes features for tracing intermediate calls and grouping tests, enhancing overall testing efficiency.
- A local mode is available for running tests and generating immediate reports directly in the terminal.

Questions Answered

Why should developers use the Lang Smith integration with Pytest for LLM applications?

The Lang Smith integration with Pytest enhances the testing experience for LLM applications by maintaining familiar features while adding powerful debugging and evaluation capabilities.

How does the integration facilitate team collaboration in LLM application development?

The integration provides a shared platform for teams, including non-technical stakeholders, to view evaluation results, which is essential for quick iterations and improvements.

How can developers log inputs and outputs in their tests using Lang Smith?

Developers can use the logging methods provided by Lang Smith to track inputs and outputs during testing, which helps in understanding the behavior of the LLM applications.

What is the purpose of using decorators in the Lang Smith integration?

Decorators in Lang Smith are used to encapsulate feedback logging, allowing developers to separate application traces from feedback traces for clearer insights.

What features does Lang Smith provide for reviewing test results?

Lang Smith allows users to view detailed results, including scores and metrics, and provides a trace view for debugging and comparison with previous runs.

© transcribe · For agents Built with care and craft by Gokul Rajaram