Skip to main content

Evaluation Quick Start

This quick start will get you up and running with our evaluation SDK and Experiments UI.

1. Install LangSmith

pip install -U langsmith

2. Create an API key

To create an API key head to the Settings page. Then click Create API Key.

3. Set up your environment

export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=<your-api-key>

4. Run your evaluation

from langsmith import evaluate, Client
from langsmith.schemas import Example, Run

# 1. Create and/or select your dataset
client = Client()
dataset = client.clone_public_dataset("https://smith.langchain.com/public/a63525f9-bdf2-4512-83e3-077dc9417f96/d")

# 2. Define an evaluator
# For more info on defining evaluators, see: https://docs.smith.langchain.com/evaluation/how_to_guides/evaluation/evaluate_llm_application#use-custom-evaluators
def is_concise_enough(root_run: Run, example: Example) -> dict:
score = len(root_run.outputs["output"]) < 3 * len(example.outputs["answer"])
return {"key": "is_concise", "score": int(score)}

# 3. Run an evaluation
evaluate(
lambda x: x["question"] + "is a good question. I don't know the answer.",
data=dataset.name,
evaluators=[is_concise_enough],
experiment_prefix="my first experiment "
)

5. View Experiments UI

Click the link printed out by your evaluation run to access the LangSmith experiments UI, and explore the results of your evaluation.


Was this page helpful?


You can leave detailed feedback on GitHub.