LANGSMITH_API_KEY
lsv2_pt_your_api_key_here
Required
LANGSMITH_PROJECT
your-project-name
Check this to know which project has traces
LANGSMITH_WORKSPACE_ID
your-workspace-id
Optional: for org-scoped keys
IMPORTANT:
Always check the environment variables or
.env
file for
LANGSMITH_PROJECT
before querying or interacting with LangSmith. This tells you which project contains the relevant traces and data. If the LangSmith project is not available, use your best judgement to identify the right one.
Python Dependencies
pip
install
langsmith
JavaScript Dependencies
npm
install
langsmith
CLI Tool
curl
-sSL
https://raw.githubusercontent.com/langchain-ai/langsmith-cli/main/scripts/install.sh
|
sh
Dataset Commands
langsmith dataset list
- List datasets in LangSmith
langsmith dataset get
1. Export traces to JSONL files
langsmith trace
export
./traces
--project
my-project
--limit
20
--full
client = Client()
2. Process traces into dataset examples
examples = []
for jsonl_file in Path("./traces").glob("*.jsonl"):
runs = [json.loads(line) for line in jsonl_file.read_text().strip().split("\n")]
root = next((r for r in runs if r.get("parent_run_id") is None), None)
if root and root.get("inputs") and root.get("outputs"):
examples.append({
"trace_id": root.get("trace_id"),
"inputs": root["inputs"],
"outputs": root["outputs"]
})
3. Save locally
with open("/tmp/dataset.json", "w") as f:
json.dump(examples, f, indent=2)
Upload local JSON file as a dataset
langsmith dataset upload /tmp/dataset.json
--name
"My Evaluation Dataset"
Using the SDK Directly
client = Client()
Create dataset and add examples in one step
dataset = client.create_dataset("My Dataset", description="Evaluation dataset")
client.create_examples(
inputs=[{"query": "What is AI?"}, {"query": "Explain RAG"}],
outputs=[{"answer": "AI is..."}, {"answer": "RAG is..."}],
dataset_name="My Dataset",
)
List all datasets
langsmith dataset list
Get dataset details
langsmith dataset get "My Dataset"
Create an empty dataset
langsmith dataset create --name "New Dataset" --description "For evaluation"
Upload a local JSON file
langsmith dataset upload /tmp/dataset.json --name "My Dataset"
Export a dataset to local file
langsmith dataset export "My Dataset" /tmp/exported.json --limit 100
Delete a dataset
langsmith dataset delete "My Dataset"
List examples in a dataset
langsmith example list --dataset "My Dataset" --limit 10
Add an example
langsmith example create --dataset "My Dataset" \ --inputs '{"query": "test"}' \ --outputs '{"answer": "result"}'
List experiments
langsmith experiment list
--dataset
"My Dataset"
langsmith experiment get
"eval-v1"
1. Export traces from LangSmith
langsmith trace export ./traces --project my-project --limit 20 --full
2. Process traces into dataset format (using Python/JS code)
See "Creating Datasets" section above
3. Upload to LangSmith
langsmith dataset upload /tmp/final_response.json --name "Skills: Final Response" langsmith dataset upload /tmp/trajectory.json --name "Skills: Trajectory"
4. Verify upload
langsmith dataset list langsmith dataset get "Skills: Final Response" langsmith example list --dataset "Skills: Final Response" --limit 3
5. Run experiments
langsmith experiment list --dataset "Skills: Final Response" Empty dataset after upload: Verify JSON file contains an array of objects with inputs key Check file isn't empty: langsmith example list --dataset "Name" Export has no data: Ensure traces were exported with --full flag to include inputs/outputs Verify traces have both inputs and outputs populated Example count mismatch: Use langsmith dataset get "Name" to check remote count Compare with local file to verify upload completeness