LangChain LangSmith Observability
LangSmith is the observability and evaluation platform from the LangChain team. With LangChain observability turned on, every chain, agent step, prompt, tool call, token count and latency is recorded as a trace you can inspect in a web UI.
Enabling Tracing
Create a free account at smith.langchain.com, generate an API key, and set environment variables. No code changes are needed:
# .env
LANGSMITH_TRACING=true
LANGSMITH_API_KEY=lsv2_your_key_here
LANGSMITH_PROJECT=langchain-tutorial(after running any chain, traces appear in the "langchain-tutorial" project)
Naming and Tagging Runs
from dotenv import load_dotenv
load_dotenv()
result = chain.invoke(
{"x": "caching"},
config={"run_name": "explain-topic", "tags": ["tutorial", "v2"], "metadata": {"user": "u42"}},
)(trace "explain-topic" shows prompt, model input, output and timing)
Tracing Your Own Functions
from langsmith import traceable
@traceable
def clean_question(q: str) -> str:
return q.strip().rstrip("?") + "?"
clean_question(" what is rag ")(a "clean_question" run appears in LangSmith)
What to Look For in Traces
- The exact prompt sent after templates were filled.
- Which documents a retriever returned for a question.
- Each agent tool call, its arguments and output.
- Latency and token usage per step.
- Errors with the full input that caused them.
Evaluation
LangSmith lets you save examples into datasets and run your app over them with evaluators (exact match, LLM-as-judge, or your own functions). Run evaluations whenever you change a prompt, model or chunk size to catch regressions.
Privacy and Alternatives
Tracing sends prompts and outputs to LangSmith. For sensitive data, mask inputs, use a self-hosted deployment, or use open-source tools such as Langfuse or Arize Phoenix, which also integrate with LangChain through callbacks or OpenTelemetry.
Frequently asked questions
Is LangSmith free?
There is a free developer tier with a monthly trace allowance. Paid plans add more traces, seats and retention.
Do I need LangSmith to use LangChain?
No. It is optional, but it makes debugging much easier.
Does LangSmith work with local Ollama models?
Yes. Tracing records the calls your code makes regardless of the model provider.