Most teams treat agent evaluation as an afterthought. They ship a prompt change, scan a handful of outputs, and call it tested. Then the support tickets roll in. The reality: non-deterministic systems demand deterministic evaluation harnesses, and LangSmith’s evaluation primitives — datasets, evaluators, and experiments — are the most mature native toolchain for the job.
Yesterday, LangChain shipped a major addition: Jev, TypeSafe AI’s “System One” model, is now available as a judge in LangSmith Evals. In LangChain’s own benchmark, Jev hit 100% oracle agreement on pass/fail judgments at $0.00035 per call — compared to $28.17 for Claude Sonnet 4.6 — with 92–913x lower scoring variance than LLM judges (source).
This tutorial builds a complete LangSmith evaluation pipeline: dataset creation, custom LLM-as-judge evaluators, Jev integration, experiment runs, and CI gating. We’ll use LangSmith’s own SDK — no third-party eval frameworks needed. By the end, you’ll have evals that run on every commit, not every fire drill.
If you’re weighing LangSmith against other observability platforms, we’ve covered that in our LangSmith vs Langfuse vs Arize Phoenix comparison. Here we’re going deep on the evaluation workflow itself.
Prerequisites
- Python 3.10+
- A LangSmith account (free tier works for this tutorial — sign up here)
LANGSMITH_API_KEYenvironment variable set- OpenAI API key (for the agent and LLM-as-judge examples)
Step 1: Set Up the Project
mkdir langsmith-evals-2026 && cd langsmith-evals-2026
python -m venv .venv && source .venv/bin/activate
pip install langsmith langgraph langchain-openai
Create a .env file:
LANGSMITH_API_KEY=lsv2_pt_...
LANGSMITH_TRACING=true
LANGSMITH_PROJECT=agent-eval-tutorial
OPENAI_API_KEY=sk-...
Now verify connectivity:
# test_connection.py
import os
from dotenv import load_dotenv
from langsmith import Client
load_dotenv()
client = Client()
print(f"Connected to LangSmith. Workspace: {client.read_project(project_name='agent-eval-tutorial').name}")
Run it: python test_connection.py
Step 2: Build a Small Agent to Evaluate
We need something to evaluate. Let’s build a simple customer-support routing agent with LangGraph — it classifies user queries and routes them to the right handler.
# agent.py
import os
from typing import TypedDict, Literal
from dotenv import load_dotenv
from langgraph.graph import StateGraph, END
from langchain_openai import ChatOpenAI
load_dotenv()
class AgentState(TypedDict):
query: str
category: str
response: str
llm = ChatOpenAI(model="gpt-4o-mini")
ROUTING_PROMPT = """Classify this customer query into exactly one category:
- billing: questions about charges, invoices, refunds
- technical: bugs, errors, broken features
- account: login issues, password resets, profile changes
- general: everything else
Reply with ONLY the category name, lowercase, no punctuation.
Query: {query}"""
def classify_query(state: AgentState) -> AgentState:
prompt = ROUTING_PROMPT.format(query=state["query"])
result = llm.invoke(prompt)
state["category"] = result.content.strip().lower()
return state
def route_query(state: AgentState) -> Literal["billing", "technical", "account", "general"]:
category = state["category"]
valid = {"billing", "technical", "account", "general"}
return category if category in valid else "general"
def handle_billing(state: AgentState) -> AgentState:
state["response"] = f"[Billing Team] We'll review your billing inquiry about: {state['query'][:80]}..."
return state
def handle_technical(state: AgentState) -> AgentState:
state["response"] = f"[Technical Team] We're looking into your technical issue: {state['query'][:80]}..."
return state
def handle_account(state: AgentState) -> AgentState:
state["response"] = f"[Account Team] We'll help with your account request: {state['query'][:80]}..."
return state
def handle_general(state: AgentState) -> AgentState:
state["response"] = f"[General Support] We've received your inquiry: {state['query'][:80]}..."
return state
graph = StateGraph(AgentState)
graph.add_node("classify", classify_query)
graph.add_node("billing", handle_billing)
graph.add_node("technical", handle_technical)
graph.add_node("account", handle_account)
graph.add_node("general", handle_general)
graph.set_entry_point("classify")
graph.add_conditional_edges("classify", route_query, {
"billing": "billing",
"technical": "technical",
"account": "account",
"general": "general",
})
graph.add_edge("billing", END)
graph.add_edge("technical", END)
graph.add_edge("account", END)
graph.add_edge("general", END)
agent = graph.compile()
def run_agent(query: str) -> dict:
return agent.invoke({"query": query, "category": "", "response": ""})
Test it:
result = run_agent("I can't log into my account — password reset isn't working")
print(f"Category: {result['category']}, Response: {result['response']}")
Step 3: Create an Evaluation Dataset
Evaluation starts with a dataset — a versioned collection of test cases. Each example has inputs and an optional expected output (the “ground truth”).
# build_dataset.py
import os
from dotenv import load_dotenv
from langsmith import Client
load_dotenv()
client = Client()
dataset = client.create_dataset(
dataset_name="customer-support-routing-v1",
description="Golden test set for the customer support routing agent"
)
test_cases = [
{
"inputs": {"query": "I was charged twice for my subscription last month"},
"outputs": {"expected_category": "billing"}
},
{
"inputs": {"query": "The app crashes every time I try to upload a photo"},
"outputs": {"expected_category": "technical"}
},
{
"inputs": {"query": "I forgot my password and the reset link expired"},
"outputs": {"expected_category": "account"}
},
{
"inputs": {"query": "What are your business hours?"},
"outputs": {"expected_category": "general"}
},
{
"inputs": {"query": "Can I get a refund for the annual plan I bought yesterday?"},
"outputs": {"expected_category": "billing"}
},
{
"inputs": {"query": "My dashboard shows a 404 error after the latest update"},
"outputs": {"expected_category": "technical"}
},
{
"inputs": {"query": "How do I change the email address on my profile?"},
"outputs": {"expected_category": "account"}
},
{
"inputs": {"query": "Do you offer discounts for non-profits?"},
"outputs": {"expected_category": "general"}
},
{
"inputs": {"query": "My invoice shows a charge I don't recognize"},
"outputs": {"expected_category": "billing"}
},
{
"inputs": {"query": "The API keeps returning 429 rate limit errors"},
"outputs": {"expected_category": "technical"}
},
]
for case in test_cases:
client.create_example(
inputs=case["inputs"],
outputs=case["outputs"],
dataset_id=dataset.id
)
print(f"Dataset created: {dataset.name} ({dataset.id}) with {len(test_cases)} examples")
Run it: python build_dataset.py
Step 4: Write Custom Evaluators
LangSmith supports three evaluator types: heuristic (code-based checks), LLM-as-judge, and now Jev (a specialized model for evaluation). We’ll implement all three so you can compare.
4a. Heuristic Evaluator (Exact Match)
The simplest form: check if the agent’s predicted category matches the expected output.
# evaluators.py
from typing import Any
def category_accuracy(outputs: dict, reference_outputs: dict) -> dict:
"""Check if the predicted category matches the expected category."""
predicted = outputs.get("category", "").strip().lower()
expected = reference_outputs.get("expected_category", "").strip().lower()
score = 1.0 if predicted == expected else 0.0
return {
"key": "category_accuracy",
"score": score,
"comment": f"Predicted: '{predicted}', Expected: '{expected}'"
}
4b. LLM-as-Judge Evaluator
For open-ended outputs where exact match doesn’t work, use an LLM to assess quality. LangSmith makes this straightforward with a factory function.
# llm_judge.py
from langsmith.evaluation import LangChainStringEvaluator
response_quality_evaluator = LangChainStringEvaluator(
"criteria",
config={
"criteria": {
"helpfulness": "Does the response address the user's query directly and provide actionable next steps?",
"professionalism": "Is the tone professional, empathetic, and on-brand for a customer support interaction?",
"routing_correctness": "Based on the query, was the response routed to the correct department?"
}
}
)
LangSmith also provides prebuilt evaluators for common tasks — you can browse them at LangChainStringEvaluator("labeled_criteria", ...), "cot_qa", "context_qa", and others. For a complete list, see LangChain’s evaluator documentation.
4c. Jev Evaluator (New, Cheapest)
Jev is a “System One” model from TypeSafe AI — it doesn’t generate text; it scores outputs. LangChain’s benchmark (published September 20, 2026) showed:
| Judge | Oracle Agreement | Avg Cost/Call | Variance |
|---|---|---|---|
| Jev | 100% | $0.00035 | Baseline |
| GPT-5.6 | 92% | $12.41 | 92× Jev |
| Claude Sonnet 4.6 | 88% | $28.17 | 913× Jev |
To use Jev in LangSmith, you set it up as an evaluator through the LangSmith SDK or UI. The SDK pattern:
# jev_evaluator.py
from langsmith import Client
from langsmith.schemas import RunEvalConfig
client = Client()
# Jev is selected by specifying its evaluator type when running evaluate()
# LangSmith handles routing to the Jev model automatically
jev_config = RunEvalConfig(
evaluators=[
# Jev as a judge — specify criteria inline
{
"evaluator_type": "jev",
"criteria": {
"routing_accuracy": "Did the agent route this query to the correct department? Score 1 if yes, 0 if no.",
"tone_appropriate": "Is the response tone professional and empathetic for customer support?"
}
}
]
)
Jev works best for structured, repeatable judgments — classification accuracy, routing correctness, tone checks — where you need high consistency at near-zero cost. For nuanced qualitative feedback (“write a paragraph explaining what went wrong”), LLM-as-judge still wins. Use both: Jev for the gate, LLM for the post-mortem.
Step 5: Run the Experiment
Now wire everything together with client.evaluate(). This function takes your agent, the dataset, and evaluators, then runs every test case and scores the results.
# run_experiment.py
import os
from dotenv import load_dotenv
from langsmith import Client
from langsmith.schemas import RunEvalConfig
from agent import run_agent
load_dotenv()
client = Client()
def target(inputs: dict) -> dict:
"""The function LangSmith calls for each dataset example."""
result = run_agent(inputs["query"])
return {
"category": result["category"],
"response": result["response"]
}
eval_config = RunEvalConfig(
evaluators=[
# Heuristic check — exact category match
lambda outputs, reference_outputs: {
"key": "category_accuracy",
"score": 1.0 if outputs.get("category") == reference_outputs.get("expected_category") else 0.0
},
# LLM-as-judge for qualitative assessment
{
"evaluator_type": "criteria",
"criteria": {
"helpfulness": "Does the response address the user's query and provide actionable next steps?",
"professionalism": "Is the tone professional and empathetic?"
}
},
# Jev judge for fast, cheap pass/fail
{
"evaluator_type": "jev",
"criteria": {
"category_correct": "Is the category_predicted field correct for this query? Score 1 for yes, 0 for no."
}
}
]
)
experiment_results = client.evaluate(
target,
data="customer-support-routing-v1",
evaluators=eval_config,
experiment_prefix="routing-agent-v1",
max_concurrency=4,
)
print(f"\nExperiment complete: {experiment_results.experiment_name}")
print(f"Results: {experiment_results.summary}")
Run it: python run_experiment.py
The results appear in your LangSmith dashboard under Datasets & Testing → Experiments. Each row shows the input, agent output, and per-evaluator scores. You can filter by failed runs, drill into traces, and annotate edge cases.
Step 6: CI Integration
The real payoff: gate deploys on eval results. Here’s a minimal GitHub Actions workflow that fails the build if category accuracy drops below 90%:
# .github/workflows/agent-evals.yml
name: Agent Evaluations
on:
pull_request:
paths:
- "agent.py"
- "prompts/**"
jobs:
eval:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install langsmith langgraph langchain-openai
- name: Run evaluation
env:
LANGSMITH_API_KEY: ${{ secrets.LANGSMITH_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: python run_experiment.py
- name: Check accuracy threshold
env:
LANGSMITH_API_KEY: ${{ secrets.LANGSMITH_API_KEY }}
run: |
python -c "
from langsmith import Client
client = Client()
experiments = list(client.list_experiments(limit=1))
if experiments:
summary = experiments[0].results
accuracy = summary.get('category_accuracy', 0)
if accuracy < 0.90:
print(f'FAIL: Category accuracy {accuracy:.1%} below 90% threshold')
exit(1)
print(f'PASS: Category accuracy {accuracy:.1%}')
"
When to Use Which Evaluator
- Heuristic checks: use for deterministic assertions — exact category match, output format validation, regex-based field extraction. Fast, free, and unambiguous.
- LLM-as-judge: use when the output is open-ended and you need nuanced judgment — “Is this response empathetic?” or “Does the reasoning follow logically?” Costs scale with model choice.
- Jev: use for high-volume, repeatable pass/fail gates — routing accuracy, policy compliance, sentiment classification. At $0.00035/call with perfect consistency, it’s the default choice for regression testing.
Our recommendation: layer them. Heuristics catch the obvious failures. Jev gates the structured checks at scale. LLM-as-judge handles the qualitative edge cases.
What’s Next
- Explore LangSmith’s experiment comparison view to A/B test prompt changes
- Set up annotation queues for human review of edge cases
- For a broader observability comparison across platforms, see our LangSmith vs Langfuse vs Arize Phoenix breakdown
- Check out our guide on testing and evaluating AI agents for a wider lens on the eval landscape
Evals aren’t a post-deployment checkbox. They’re the difference between shipping with confidence and shipping with crossed fingers. With Jev now in LangSmith, the cost argument for skipping evals is officially dead.