LangSmith for tracing and evals
LangSmith is LangChain's platform for seeing what your LLM app actually did and measuring whether it is getting better. It is a hosted product (with hybrid and self hosted options) plus open source SDKs, and despite the name it works with any code: you can trace raw OpenAI or Anthropic calls, LlamaIndex, or your own functions. I treat it as the "logging and testing" layer of an AI system, the same way you would treat Datadog plus a test runner for a normal service.
Why it matters
LLM apps fail quietly. The model returns a confident, well formatted answer that happens to be wrong, or an agent takes eleven tool calls where three would do. You will not see that in HTTP status codes. You need:
- Traces: every model call, tool call and retrieval step, with inputs, outputs, latency, tokens and cost, nested the way your code is nested.
- Datasets: a curated set of inputs (and ideally reference outputs) that represent what users really ask.
- Evaluators: code or LLM as judge functions that score outputs.
- Experiments: a run of your app over a dataset, scored, so you can compare prompt or model changes side by side.
- Online evaluation and alerts: evaluators that run on sampled production traffic, plus dashboards and alerts.
LangSmith bundles all of these. The SDK (langsmith on PyPI, on the 0.14 line as of October 2026) is what you use from code.
How it works
Tracing is turned on with environment variables. Inside LangChain and LangGraph it is automatic; elsewhere you decorate functions with @traceable or wrap a provider client. Each decorated call becomes a "run", and nested calls become child runs of one trace.
Rendering diagram…
The loop I recommend: ship with tracing on, look at real traces every week, add interesting or failing ones to a dataset, write an evaluator for the failure, and run an experiment on every prompt or model change. Over time your dataset becomes your regression suite.
Reference architecture
Rendering diagram…
Data governance matters here: traces contain user inputs. Decide early whether you use the cloud, a hybrid setup or self hosting, and whether you need to mask fields before they leave your process.
Code
Tracing a non LangChain app and running an evaluation, using the langsmith SDK. First, environment variables:
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY="<your-langsmith-api-key>"
export OPENAI_API_KEY="<your-openai-api-key>"
Then the app and the experiment:
from langsmith import Client, traceable
from langsmith.wrappers import wrap_openai
from openai import OpenAI
oai = wrap_openai(OpenAI()) # every call is now traced
client = Client()
@traceable(name="answer_question")
def answer(inputs: dict) -> dict:
resp = oai.chat.completions.create(
model="gpt-5.4-mini",
messages=[
{"role": "system", "content": "Answer in one short sentence."},
{"role": "user", "content": inputs["question"]},
],
)
return {"answer": resp.choices[0].message.content}
# 1. A tiny dataset (in practice, built from real traces)
dataset = client.create_dataset(dataset_name="capitals-smoke", description="Smoke test")
client.create_examples(
dataset_id=dataset.id,
examples=[
{"inputs": {"question": "Capital of France?"}, "outputs": {"answer": "Paris"}},
{"inputs": {"question": "Capital of Japan?"}, "outputs": {"answer": "Tokyo"}},
],
)
# 2. A deterministic evaluator
def contains_reference(outputs: dict, reference_outputs: dict) -> bool:
return reference_outputs["answer"].lower() in outputs["answer"].lower()
# 3. Run the experiment
results = client.evaluate(
answer,
data="capitals-smoke",
evaluators=[contains_reference],
experiment_prefix="baseline-prompt",
)
print(results)
For fuzzier criteria (correctness, helpfulness, groundedness), the LangSmith quickstart uses the open source openevals package to build LLM as judge evaluators with prompts such as CORRECTNESS_PROMPT. Start with deterministic checks where you can; they are cheaper and do not drift.
Trade-offs and pitfalls
- It is a hosted dependency. Cloud is easiest, but regulated teams may need the hybrid or self hosted option, which is more to operate. Check where your data lives.
- Traces include sensitive data. Mask or redact before sending if you handle PII. Do not assume the default is safe for your compliance regime.
- LLM as judge needs its own evaluation. A judge prompt can be biased or inconsistent. Spot check it against human labels before trusting a score.
- Tiny datasets lie. Ten examples catch crashes, not quality regressions. Grow toward a few hundred representative cases.
- Sampling and cost. Tracing every call at high volume costs money and storage. Sample in production, keep full tracing in staging.
- Lock in is moderate. The SDK supports OpenTelemetry, which helps if you later move to another backend, but datasets and experiment history live in the platform.
When to pick it: you use LangChain or LangGraph (tracing is essentially free), you want tracing, datasets, experiments and annotation queues in one tool, or you want a managed product rather than assembling one.
When not to: you are standardized on another observability stack and only need basic spans (plain OpenTelemetry may be enough), you cannot send data to a third party and do not want to self host, or you prefer an open source tool such as Langfuse or Arize Phoenix.
Checklist
- Turn on tracing in development from the first day.
- Wrap provider clients or decorate entry points with
@traceableoutside LangChain. - Decide on cloud, hybrid or self hosted before sending real user data.
- Build datasets from real traces, not invented examples.
- Prefer deterministic evaluators, and validate any LLM judge.
- Run experiments in CI on prompt, model and retrieval changes.
- Sample production traces and attach online evaluators to the critical paths.