Skip to main content
You can fetch datasets from LangWatch using the SDK to use in your offline evaluations or other automated workflows.

Fetching a Dataset

import langwatch

# Initialize the SDK
langwatch.setup()

# Fetch dataset by slug or ID
dataset = langwatch.dataset.get_dataset("your-dataset-slug")

# Convert to pandas DataFrame for easy manipulation
df = dataset.to_pandas()

print(df.head())

Using with Evaluations

Datasets are commonly used to run offline evaluations against your LLM or agent.
import langwatch

langwatch.setup()

# Fetch dataset
df = langwatch.dataset.get_dataset("your-dataset-slug").to_pandas()

# Initialize evaluation
evaluation = langwatch.experiment.init("my-evaluation")

for index, row in evaluation.loop(df.iterrows()):
    # Run your LLM/agent
    output = my_llm(row["input"])
    
    # Log evaluation metrics
    evaluation.log("response_quality", index=index, score=0.9)

Dataset Entry Structure

Each dataset entry contains:
FieldDescription
idUnique identifier for the entry
entryThe actual data (e.g., input, expected_output, contexts)
datasetIdID of the parent dataset
projectIdID of the project
createdAtTimestamp of creation
updatedAtTimestamp of last update

Typed Datasets (TypeScript)

You can define types for your dataset entries for better type safety:
type MyDatasetEntry = {
  input: string;
  expected_output: string;
  contexts?: string[];
};

const dataset = await langwatch.datasets.get<MyDatasetEntry>("my-dataset");

// Now entry.entry is typed as MyDatasetEntry
for (const entry of dataset.entries) {
  console.log(entry.entry.input);  // Typed as string
  console.log(entry.entry.expected_output);  // Typed as string
}

Finding Your Dataset Slug

You can find the dataset slug in the LangWatch UI:
  1. Go to the Datasets page
  2. Click on your dataset
  3. The slug is shown in the URL: app.langwatch.ai/{project}/datasets/{slug}
You can also use the dataset ID (starting with dataset_) which is shown in the dataset details.