Loading...
Loading...
INVOKE THIS SKILL when creating evaluation datasets, uploading datasets to LangSmith, or managing existing datasets. Covers dataset types (final_response, single_step, trajectory, RAG), CLI management commands, SDK-based creation, and example management. Uses the langsmith CLI tool.
npx skill4agent add langchain-ai/langsmith-skills langsmith-datasetLANGSMITH_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.envLANGSMITH_PROJECTpip install langsmithnpm install langsmithcurl -sSL https://raw.githubusercontent.com/langchain-ai/langsmith-cli/main/scripts/install.sh | shlangsmith dataset listlangsmith dataset get <name-or-id>langsmith dataset create --name <name>langsmith dataset delete <name-or-id>langsmith dataset export <name-or-id> <output-file>langsmith dataset upload <file> --name <name>langsmith example list --dataset <name>langsmith example create --dataset <name> --inputs <json>langsmith example delete <example-id>langsmith experiment list --dataset <name>langsmith experiment get <name>--limit N--yes--yes--yesinputsoutputs# 1. Export traces to JSONL files
langsmith trace export ./traces --project my-project --limit 20 --full</python>
<typescript>
```typescript
import { Client } from "langsmith";
import { readFileSync, writeFileSync, readdirSync } from "fs";
import { join } from "path";
const client = new Client();
// 2. Process traces into dataset examples
const examples: Array<{trace_id?: string, inputs: Record<string, any>, outputs: Record<string, any>}> = [];
const files = readdirSync("./traces").filter(f => f.endsWith(".jsonl"));
for (const file of files) {
const lines = readFileSync(join("./traces", file), "utf-8").trim().split("\n");
const runs = lines.map(line => JSON.parse(line));
const root = runs.find(r => r.parent_run_id == null);
if (root?.inputs && root?.outputs) {
examples.push({ trace_id: root.trace_id, inputs: root.inputs, outputs: root.outputs });
}
}
// 3. Save locally
writeFileSync("/tmp/dataset.json", JSON.stringify(examples, null, 2));# Upload local JSON file as a dataset
langsmith dataset upload /tmp/dataset.json --name "My Evaluation Dataset"</python>
<typescript>
```typescript
import { Client } from "langsmith";
const client = new Client();
// Create dataset and add examples
const dataset = await client.createDataset("My Dataset", {
description: "Evaluation dataset",
});
await client.createExamples({
inputs: [{ query: "What is AI?" }, { query: "Explain RAG" }],
outputs: [{ answer: "AI is..." }, { answer: "RAG is..." }],
datasetName: "My Dataset",
});{"trace_id": "...", "inputs": {"query": "What are the top genres?"}, "outputs": {"response": "The top genres are..."}}{"trace_id": "...", "inputs": {"messages": [...]}, "outputs": {"content": "..."}, "metadata": {"node_name": "model"}}{"trace_id": "...", "inputs": {"query": "..."}, "outputs": {"expected_trajectory": ["tool_a", "tool_b", "tool_c"]}}{"trace_id": "...", "inputs": {"question": "How do I..."}, "outputs": {"answer": "...", "retrieved_chunks": ["..."], "cited_chunks": ["..."]}}# 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"inputslangsmith example list --dataset "Name"--fullinputsoutputslangsmith dataset get "Name"