LangSmith dashboards explained
Quick answer
LangSmith dashboards provide a visual interface to monitor and analyze AI model interactions and workflows. They display trace data, performance metrics, and error logs, enabling developers to optimize and debug AI applications efficiently using LangSmith tracing features.
PREREQUISITES
Python 3.8+LangSmith API keypip install langsmith
Setup
Install the langsmith Python package and set your API key as an environment variable to start using LangSmith dashboards.
pip install langsmith Step by step
Use the langsmith client to send trace data from your AI application. This example shows how to initialize the client and create a simple trace that will appear in your LangSmith dashboard.
import os
from langsmith import Client, traceable
# Initialize LangSmith client with API key from environment
client = Client(api_key=os.environ["LANGSMITH_API_KEY"])
@traceable
# Define a traced function
def generate_response(prompt: str) -> str:
# Simulate AI response generation
return f"Response to: {prompt}"
# Run the traced function
result = generate_response("Hello LangSmith")
print(result) output
Response to: Hello LangSmith
Common variations
You can integrate LangSmith tracing with OpenAI or Anthropic SDKs to automatically capture all LLM calls. Enable environment variables LANGCHAIN_TRACING_V2 and LANGCHAIN_API_KEY to activate tracing without code changes. LangSmith dashboards support filtering by project, tags, and time range to analyze specific runs or workflows.
import os
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = os.environ["LANGSMITH_API_KEY"]
os.environ["LANGCHAIN_PROJECT"] = "my-project"
from langchain_openai import ChatOpenAI
chat = ChatOpenAI(model="gpt-4o-mini")
response = chat.invoke([{"role": "user", "content": "Hello"}])
print(response.content) output
Hello
Troubleshooting
If you don't see traces in the LangSmith dashboard, verify your LANGSMITH_API_KEY environment variable is set correctly. Ensure LANGCHAIN_TRACING_V2 is enabled for automatic tracing with LangChain. Check network connectivity if traces fail to upload.
Key Takeaways
- Use the langsmith Python SDK to send trace data for AI workflows.
- Enable environment variables to auto-trace LangChain or OpenAI SDK calls.
- LangSmith dashboards provide filtering and detailed insights for debugging and optimization.