Skip to main content
Online evaluations provide real-time feedback on your production traces. This is useful to continuously monitor the performance of your application: identify issues, measure improvements, and ensure consistent quality over time. Code evaluators allow you to write an evaluator in Python or JavaScript directly in LangSmith. Often used for validating structure or statistical properties of your data.
Online evaluators extend trace retention by default. You can opt out for an individual evaluator when the agent environment uses base retention. Other actions can still extend those traces. If extended retention is disabled for the workspace, evaluations continue without new retention upgrades, regardless of saved environment defaults.

View online evaluators

Select your agent, go to Tracing, and select the environment. To view existing online evaluators for that environment, click the Online Evaluators tab.

Configure online evaluators

1. Navigate to online evaluators

Select your agent, go to Tracing, and select the environment. Click the Online Evaluators tab, then click + Evaluator to open the Add Evaluator panel. Then choose one of the following:
  • Create from scratch: Select Code Evaluator.
  • Attach an existing evaluator: Select a code evaluator already in your workspace to reuse it.

2. Name your evaluator

Provide a name for your evaluator. This name will be used when referencing the evaluator in your code, and will also be the name of the feedback that is generated by this evaluator.

3. Create a filter

For example, you may want to apply specific evaluators based on:
  • Runs where a user left feedback indicating the response was unsatisfactory.
  • Runs that invoke a specific tool call. See filtering for tool calls for more information.
  • Runs that match a particular piece of metadata (e.g. if you log traces with a plan_type and only want to run evaluations on traces from your enterprise customers). See adding metadata to your traces for more information.
LangSmith has two filtering experiences, and the one you see can differ between pages. Check the filter controls on the page you are using to see which one applies:
In the evaluator panel, the search bar sits under Trigger On: select Traces or Runs, click + Filter, and write a query. Threads appears only for advanced code evaluators. For the steps, refer to Filter with the search bar. The filter builder sits under Filters. To process feedback from an earlier evaluator, filter this evaluator for the feedback key, then read the score from run["feedback"], or include extended stats to read it from run["feedback_stats"]. For example, to run when the answer_usefulness feedback exists, use feedback.answer_usefulness:* in the search bar or eq(feedback_key, "answer_usefulness") in the filter builder. The filter is based on the feedback key, not the evaluator that produced it, so feedback from any source with that key triggers the code evaluator. For more information, see Chain evaluators.
It’s often helpful to inspect runs as you’re creating a filter for your evaluator. With the evaluator configuration panel open, you can inspect runs and apply filters to them. Any filters you apply to the runs table will automatically be reflected in filters on your evaluator.

4. (Optional) Configure a sampling rate

Configure a sampling rate to control the percentage of filtered runs that trigger the automation action. For example, to control costs, you may want to set a filter to only apply the evaluator to 10% of traces. In order to do this, you would set the sampling rate to 0.1.

5. (Optional) Apply rule to past runs

To apply the rule to past runs, expand Advanced, select Apply to past runs from date… under Backfill, then enter a date. This is only possible upon rule creation. Note: the backfill is processed as a background job, so you will not see the results immediately. To track the backfill’s progress, open the agent environment’s Online Evaluators tab on the Tracing page and click Logs in your evaluator’s row. Online evaluator logs are similar to automation rule logs.
  • Add an evaluator name
  • Optionally filter runs that you would like to apply your evaluator on or configure a sampling rate.
  • Select Apply Evaluator

Write your evaluation function

Code evaluators restrictions.Allowed Libraries: You can import all standard library functions, as well as the following public packages (versions are provided by the bundled Pyodide release):
Network Access: You cannot access the internet from a code evaluator.To install other packages, make network requests, or authenticate with workspace secrets, use an advanced code evaluator. For more information, see Use advanced code evaluators.
Code evaluators must be written inline. We recommend testing locally before setting up your code evaluator in LangSmith. In the UI, you will find a panel that lets you write your code inline, with some starter code. Code evaluators take in one argument:
  • A Run (reference). This represents the sampled run to evaluate.
LangSmith passes a dataset example as a second argument when you test the evaluator against a dataset sample and when the evaluator scores an experiment run. Otherwise, it passes only the run. To handle both cases in Python, define the function as perform_eval(run, example=None). In a default code evaluator, a function that accepts only run fails with TypeError: perform_eval() takes 1 positional argument but 2 were given.
They return a single value:
  • Feedback(s) Dictionary: A dictionary whose keys are the type of feedback you want to return, and values are the score you will give for that feedback key. For example, {"correctness": 1, "silliness": 0} would create two types of feedback on the run, one saying it is correct, and the other saying it is not silly.
The following example shows a function that validates that each run in the experiment has a known JSON field:

Test and save your evaluation function

Before saving, you can test your evaluator function on a recent run by clicking Test Code to make sure that your code executes properly. Once you Save, your online evaluator will run over newly sampled runs (or backfilled ones too if you chose the backfill option). If you prefer a video tutorial, check out the Online Evaluations video from the Introduction to LangSmith Course.