By Sagar Shankaran, Founder of CallSphere
Set up LangSmith for tracing LangChain runs, analyzing run trees, building evaluation datasets, running automated evaluations, and collecting feedback on LLM outputs.
Key takeaways
LLM applications are notoriously difficult to debug. A chain might call three models, two tools, and a retriever — and when the final answer is wrong, you need to trace exactly which step failed and why. Logging raw inputs and outputs is not enough when calls are nested and asynchronous.
LangSmith is the observability and evaluation platform built specifically for LangChain (and any LLM application). It captures detailed traces of every run, lets you visualize the execution tree, and provides tools for systematic evaluation.
LangSmith tracing requires an API key and two environment variables. Once set, all LangChain operations are traced automatically.
flowchart LR
APP(["Agent or API"])
SDK["OTel SDK<br/>GenAI conventions"]
COL["OTel Collector"]
subgraph BACKENDS["Backends"]
TR[("Traces<br/>Tempo or Honeycomb")]
MET[("Metrics<br/>Prometheus")]
LOG[("Logs<br/>Loki or ELK")]
end
DASH["Grafana plus alerts"]
PAGE(["Pager"])
APP --> SDK --> COL
COL --> TR
COL --> MET
COL --> LOG
TR --> DASH
MET --> DASH
LOG --> DASH
DASH --> PAGE
style SDK fill:#4f46e5,stroke:#4338ca,color:#fff
style DASH fill:#f59e0b,stroke:#d97706,color:#1f2937
style PAGE fill:#dc2626,stroke:#b91c1c,color:#fff
import os
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "lsv2_pt_your_key_here"
os.environ["LANGCHAIN_PROJECT"] = "my-project"
# That is it. All LangChain operations are now traced.
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
chain = (
ChatPromptTemplate.from_template("Explain {topic}")
| ChatOpenAI(model="gpt-4o-mini")
| StrOutputParser()
)
# This call is automatically traced in LangSmith
result = chain.invoke({"topic": "quantum computing"})
Every invocation creates a run in the LangSmith dashboard. You can see the input, output, latency, token usage, and cost for each component in the chain.
A run tree is a hierarchical view of a single invocation. For a RAG chain, the tree might look like:
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
Each node shows timing, inputs, outputs, and any errors. This lets you identify bottlenecks (slow retrievals) and failures (parsing errors) instantly.
Trace any Python function, not just LangChain components.
from langsmith import traceable
@traceable(name="process_order")
def process_order(order_id: str, items: list[str]) -> dict:
# Your business logic
total = calculate_total(items)
result = submit_order(order_id, items, total)
return {"order_id": order_id, "total": total, "status": result}
# This function call appears as a traced run in LangSmith
process_order("ORD-123", ["widget", "gadget"])
@traceable functions nest correctly inside LangChain traces. If a traced function calls a LangChain chain, both appear in the same run tree.
LangSmith lets you create datasets of input-output examples for systematic evaluation.
from langsmith import Client
client = Client()
# Create a dataset
dataset = client.create_dataset(
"customer-support-qa",
description="Questions and expected answers for customer support bot",
)
# Add examples
client.create_examples(
inputs=[
{"question": "How do I reset my password?"},
{"question": "What is your refund policy?"},
{"question": "How do I cancel my subscription?"},
],
outputs=[
{"answer": "Go to Settings > Security > Reset Password."},
{"answer": "Full refund within 30 days of purchase."},
{"answer": "Go to Settings > Subscription > Cancel."},
],
dataset_id=dataset.id,
)
You can also create datasets from traced runs — select successful or failed runs from the dashboard and convert them into evaluation examples.
Evaluators score your chain's outputs against expected results.
from langsmith.evaluation import evaluate, LangChainStringEvaluator
# Define evaluators
correctness = LangChainStringEvaluator("qa") # LLM-based QA evaluator
relevance = LangChainStringEvaluator("criteria", config={
"criteria": "relevance",
})
# Run evaluation
def predict(inputs: dict) -> dict:
result = chain.invoke(inputs)
return {"answer": result}
results = evaluate(
predict,
data="customer-support-qa",
evaluators=[correctness, relevance],
experiment_prefix="v1-gpt4o-mini",
)
print(results.to_pandas())
Each evaluation run creates an experiment in LangSmith. You can compare experiments side by side to measure the impact of prompt changes, model upgrades, or chain modifications.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
Write evaluators for domain-specific quality criteria.
from langsmith.schemas import Run, Example
def check_citation(run: Run, example: Example) -> dict:
"""Check if the response cites a source."""
output = run.outputs.get("answer", "")
has_citation = "source:" in output.lower() or "[" in output
return {
"key": "has_citation",
"score": 1 if has_citation else 0,
}
results = evaluate(
predict,
data="customer-support-qa",
evaluators=[check_citation],
)
LangSmith supports feedback collection on individual runs via the API or dashboard.
from langsmith import Client
client = Client()
# After a user rates a response
client.create_feedback(
run_id="run-uuid-here",
key="user_rating",
score=1, # thumbs up
comment="Accurate and helpful",
)
Feedback data powers fine-tuning datasets and helps identify where your application needs improvement.
No. LangSmith is optional. LangChain works without it. But for any production application, the observability and evaluation capabilities are essential for debugging issues, measuring quality, and iterating on prompts and chains.
LangSmith has a free tier with limited trace retention. Paid tiers offer longer retention, more traces, and team collaboration features. Check the current pricing at smith.langchain.com.
Yes. The @traceable decorator and the LangSmith SDK work with any Python code. You can trace raw OpenAI API calls, custom HTTP requests, or any function. LangSmith is not limited to LangChain applications.
#LangSmith #Observability #LLMEvaluation #Debugging #Python #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
How to actually observe a WebSocket fleet: ping/pong heartbeats, Prometheus metrics that matter, dead-man switches, and the alerts that fire before customers notice.
A 'did the agent answer correctly?' pass/fail hides broken tool calls, wasted tokens, and silent retries. Here is how to evaluate intermediate steps.
How short-term (thread-scoped) and long-term (cross-thread) memory actually work in LangGraph, with code, schemas, and the eviction policies that keep cost predictable.
OpenAI's parallel function calling can cut latency in half — or burn money on dependent calls. The architecture, code, and an eval that proves the win.
Honest principal-engineer comparison of the OpenAI Agents SDK and the legacy Assistants API, with a migration checklist and eval-parity strategy so you don't ship regressions.
How the modern agent eval stack actually flows: instrument, trace, dataset, evaluator, score, CI gate. The full pipeline that keeps agents from regressing.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.
Try Live DemoBook a DemoCalculate Your ROI