trulens-dataset-curation

0
0
Source

Create and curate evaluation datasets with ground truth for TruLens

Install

mkdir -p .claude/skills/trulens-dataset-curation && curl -L -o skill.zip "https://mcp.directory/api/skills/download/4583" && unzip -o skill.zip -d .claude/skills/trulens-dataset-curation && rm skill.zip

Installs to .claude/skills/trulens-dataset-curation

About this skill

TruLens Dataset Curation

Create evaluation datasets with ground truth to measure your LLM app's performance.

Overview

Ground truth datasets allow you to:

  • Compare LLM outputs against expected responses
  • Evaluate retrieval quality against expected chunks
  • Track performance across app versions
  • Share evaluation data across your team

Prerequisites

pip install trulens pandas

Instructions

Step 1: Initialize TruSession

from trulens.core import TruSession

session = TruSession()

Step 2: Create Ground Truth Data

Structure your data as a pandas DataFrame with these columns:

ColumnRequiredDescription
queryYesThe input query/question
query_idNoUnique identifier for the query
expected_responseNoThe expected/ideal response
expected_chunksNoExpected retrieved contexts (list or string)
import pandas as pd

data = {
    "query": [
        "What is TruLens?",
        "How do I instrument a LangChain app?",
        "What is the RAG triad?",
    ],
    "query_id": ["q1", "q2", "q3"],
    "expected_response": [
        "TruLens is an open source library for evaluating and tracing AI agents.",
        "Use TruChain to wrap your LangChain app for automatic instrumentation.",
        "The RAG triad consists of context relevance, groundedness, and answer relevance.",
    ],
    "expected_chunks": [
        ["TruLens is an open source library for evaluating and tracing AI agents, including RAG systems."],
        ["from trulens.apps.langchain import TruChain", "tru_recorder = TruChain(chain, app_name='MyApp')"],
        ["Context relevance evaluates retrieved chunks", "Groundedness checks if response is supported by context", "Answer relevance measures if the response answers the question"],
    ],
}

ground_truth_df = pd.DataFrame(data)

Step 3: Persist Dataset to TruLens

session.add_ground_truth_to_dataset(
    dataset_name="my_evaluation_dataset",
    ground_truth_df=ground_truth_df,
    dataset_metadata={"domain": "TruLens QA", "version": "1.0"},
)

Step 4: Load Dataset for Evaluation

# Load the persisted ground truth
ground_truth_df = session.get_ground_truth("my_evaluation_dataset")

print(f"Loaded {len(ground_truth_df)} ground truth examples")

Step 5: Use Ground Truth in Evaluations

from trulens.core import Feedback
from trulens.feedback import GroundTruthAgreement
from trulens.providers.openai import OpenAI

provider = OpenAI()

# Create ground truth agreement feedback
ground_truth_agreement = GroundTruthAgreement(
    ground_truth_df,
    provider=provider
)

f_groundtruth = Feedback(
    ground_truth_agreement.agreement_measure,
    name="Ground Truth Agreement",
).on_input_output()

Common Patterns

Creating Dataset from Production Logs

If you have existing logs, convert them to the ground truth format:

# From a list of dictionaries
logs = [
    {"input": "What is X?", "output": "X is...", "retrieved": ["doc1", "doc2"]},
    {"input": "How does Y work?", "output": "Y works by...", "retrieved": ["doc3"]},
]

ground_truth_df = pd.DataFrame({
    "query": [log["input"] for log in logs],
    "expected_response": [log["output"] for log in logs],
    "expected_chunks": [log["retrieved"] for log in logs],
})

Ingesting External Logs with VirtualRecord

For apps logged outside TruLens, use VirtualRecord to ingest data:

from trulens.apps.virtual import VirtualApp, VirtualRecord, TruVirtual
from trulens.core import Select

# Define virtual app structure
virtual_app = VirtualApp()
retriever_component = Select.RecordCalls.retriever
virtual_app[retriever_component] = "retriever"

# Create virtual records from your data
records = []
for row in ground_truth_df.itertuples():
    rec = VirtualRecord(
        main_input=row.query,
        main_output=row.expected_response,
        calls={
            retriever_component.get_context: dict(
                args=[row.query],
                rets=row.expected_chunks if isinstance(row.expected_chunks, list) else [row.expected_chunks]
            )
        }
    )
    records.append(rec)

# Create recorder and ingest
virtual_recorder = TruVirtual(
    app_name="ingested_data",
    app=virtual_app,
    feedbacks=[f_context_relevance, f_groundedness]
)

for record in records:
    virtual_recorder.add_record(record)

Updating Existing Datasets

Add new examples to an existing dataset:

# Load existing
existing_df = session.get_ground_truth("my_evaluation_dataset")

# Add new examples
new_examples = pd.DataFrame({
    "query": ["New question?"],
    "expected_response": ["New answer."],
})

updated_df = pd.concat([existing_df, new_examples], ignore_index=True)

# Re-persist (overwrites)
session.add_ground_truth_to_dataset(
    dataset_name="my_evaluation_dataset",
    ground_truth_df=updated_df,
)

Troubleshooting

  • Dataset not found: Verify the dataset name matches exactly when loading
  • Missing columns: Ground truth DataFrames need at minimum a query column
  • Type errors: Ensure expected_chunks is a list of strings, not a nested list

You might also like

flutter-development

aj-geddes

Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.

263781

drawio-diagrams-enhanced

jgtolentino

Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.

201413

godot

bfollington

This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.

178270

nano-banana-pro

garg-aayush

Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.

205230

ui-ux-pro-max

nextlevelbuilder

"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."

161194

rust-coding-skill

UtakataKyosui

Guides Claude in writing idiomatic, efficient, well-structured Rust code using proper data modeling, traits, impl organization, macros, and build-speed best practices.

159171

Stay ahead of the MCP ecosystem

Get weekly updates on new skills and servers.