GenAIHub
← Back to Technical Section

LangSmith

LLM Observability, Tracing, Evaluation & Debugging Platform

What is LangSmith?

LangSmith is an all-in-one platform for building production-grade LLM applications. Developed by the LangChain team, it provides comprehensive tools for tracing, debugging, evaluating, and monitoring your AI workflowsβ€”bridging the gap between prototype and production.

"LangSmith acts as a detective for your LLM appsβ€”recording every step, revealing the decision-making process, and helping you quickly pinpoint and fix issues."

Tracing

Full execution logs

Debugging

Find root causes

Evaluation

LLM-as-a-judge

Monitoring

Production insights

Core Features

Tracing

LangSmith records every operation in your LLM chainβ€”prompt inputs, tool calls, memory reads, and model outputs. Traces reveal the internal decision-making process, helping you understand why the model chose specific actions.

Nested Calls Token Usage Latency Cost Tracking

Debugging

When something goes wrong, LangSmith helps pinpoint the exact step where failures occur. Answer questions like: "Why did the agent loop infinitely?" or "Which tool returned bad data?"

Error Traces Step-by-Step Replay Input/Output Inspection

Evaluation

Test your LLM outputs against curated datasets using built-in or custom evaluators. LangSmith supports LLM-as-a-judge for assessing quality, accuracy, and coherence automatically.

Datasets Custom Evaluators LLM-as-Judge A/B Testing

Production Monitoring

Real-time dashboards for monitoring latency, token usage, costs, and errors in production. Set up alerts and track trends to ensure your LLM app stays healthy.

Real-time Metrics Cost Analytics Alerts

Quick Start

Getting started with LangSmith is simple. Set your API key and traces are automatically captured:

# 1. Install LangSmith
pip install langsmith

# 2. Set environment variables
export LANGCHAIN_TRACING_V2="true"
export LANGCHAIN_API_KEY="your-langsmith-api-key"
export LANGCHAIN_PROJECT="my-project"

# 3. Run your LangChain code - traces are automatic!
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4")
response = llm.invoke("Hello, how are you?")
print(response.content)

# View traces at: https://smith.langchain.com

What You'll See in LangSmith Dashboard

πŸ“Š Trace: ChatOpenAI
β”œβ”€β”€ Input: "Hello, how are you?"
β”œβ”€β”€ Output: "I'm doing well, thank you! How can I help you today?"
β”œβ”€β”€ Model: gpt-4
β”œβ”€β”€ Tokens: 25 (prompt: 12, completion: 13)
β”œβ”€β”€ Latency: 1.2s
└── Cost: $0.0015

Custom Tracing with @traceable

Use the @traceable decorator to trace any Python function:

from langsmith import traceable
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4")

@traceable(name="process_query")
def process_user_query(query: str) -> str:
    """Process a user query with context."""
    
    # This will appear as a child span
    context = fetch_context(query)
    
    # LLM call is automatically traced
    prompt = f"Context: {context}\n\nQuestion: {query}"
    response = llm.invoke(prompt)
    
    return response.content

@traceable(name="fetch_context")
def fetch_context(query: str) -> str:
    # Simulated database lookup
    return "Relevant context from database..."

# Run it
result = process_user_query("What is LangSmith?")
print(result)

Trace Hierarchy in LangSmith

πŸ“Š process_query (2.1s)
β”œβ”€β”€ πŸ“¦ fetch_context (0.05s)
β”‚   β”œβ”€β”€ Input: "What is LangSmith?"
β”‚   └── Output: "Relevant context from database..."
β”‚
└── πŸ€– ChatOpenAI (2.0s)
    β”œβ”€β”€ Input: "Context: Relevant context..."
    β”œβ”€β”€ Output: "LangSmith is an observability platform..."
    β”œβ”€β”€ Tokens: 156
    └── Cost: $0.0089

Evaluation Example

Create a dataset and run evaluations to test your LLM's quality:

from langsmith import Client
from langsmith.evaluation import evaluate

client = Client()

# Create a dataset
dataset = client.create_dataset("qa-examples")
client.create_examples(
    inputs=[
        {"question": "What is Python?"},
        {"question": "What is JavaScript?"},
    ],
    outputs=[
        {"answer": "A programming language"},
        {"answer": "A scripting language"},
    ],
    dataset_id=dataset.id,
)

# Define your target function
def answer_question(inputs: dict) -> dict:
    response = llm.invoke(inputs["question"])
    return {"answer": response.content}

# Run evaluation
results = evaluate(
    answer_question,
    data="qa-examples",
    evaluators=["correctness", "helpfulness"],
)
print(results)

LangSmith vs LangFuse

Aspect LangSmith LangFuse
License Closed-source (SaaS) Open-source (MIT)
Self-Hosting Enterprise only Free for all
LangChain Integration Deep native integration Good integration
Evaluation Tools Built-in LLM-as-judge Model-based evals
Free Tier 5,000 traces/month 50,000 observations/month
Best For LangChain/LangGraph users Mixed stack, self-hosting needs

πŸ’‘ Tip: LangSmith is ideal if you're already using LangChain. Choose LangFuse for self-hosted or multi-framework setups.

Pricing

Developer

Free

  • 1 user
  • 5,000 traces/month
  • 14-day retention

Plus

$39/user/month

  • Up to 10 users
  • 10,000 traces/user
  • Email support

Enterprise

Custom

  • Unlimited users
  • Self-hosted option
  • SSO, SLA, dedicated support

Key Metrics to Track

Latency

P50, P95, P99 response times

Cost

$ per trace, per user

Tokens

Input / Output per call

Errors

Failure rate, error types

Resources & References

Related Topics