TR

trulens-evaluation-setup

Setup evaluation feedback functions and input selectors for TruLens to monitor LLM performance.

Install

mkdir -p .claude/skills/trulens-evaluation-setup && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/3472" && unzip -o skill.zip -d .claude/skills/trulens-evaluation-setup && rm skill.zip

Installs to .claude/skills/trulens-evaluation-setup

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Configure feedback functions and selectors for TruLens evaluations
66 charsno explicit “when” trigger
Intermediate

Key capabilities

  • Configure feedback functions for LLM apps
  • Set up evaluation selectors for inputs and outputs
  • Define custom feedback metrics
  • Initialize monitoring for RAG and Agent apps

How it works

It guides the user through selecting appropriate metrics and provides code templates for configuring feedback functions and selectors.

Inputs & outputs

You give it
App type and evaluation criteria
You get back
Python code for feedback function configuration

When to use trulens-evaluation-setup

  • Configure LLM feedback metrics
  • Set up evaluation selectors
  • Define custom feedback functions
  • Initialize Trulens monitoring

About this skill

TruLens Evaluation Setup

Configure feedback functions to evaluate your LLM app's quality.

Interactive Evaluation Selection

Before proceeding, let's determine the right evaluations for your app.

Question 1: What type of app are you building?

Option A: RAG (Retrieval-Augmented Generation)

  • Your app retrieves documents/chunks from a knowledge base
  • It generates responses grounded in the retrieved context
  • Examples: Q&A systems, document search, knowledge assistants

Recommended: RAG Triad metrics

  • Context Relevance
  • Groundedness
  • Answer Relevance

Option B: Agent

  • Your app uses tools to accomplish tasks
  • It may involve multi-step reasoning or planning
  • Examples: research agents, coding assistants, task automation

Recommended: Agent GPA metrics (continue to Question 2)


Question 2 (Agents only): Does your agent do explicit planning?

Yes, my agent creates plans before executing:

  • Agent outputs a plan/strategy before taking actions
  • Agent references its plan during execution

Use all Agent GPA metrics:

  • Logical Consistency
  • Plan Quality
  • Plan Adherence
  • Execution Efficiency
  • Tool Selection
  • Tool Calling
  • Tool Quality

No, my agent acts without explicit planning:

  • Agent takes actions directly without stating a plan
  • Agent uses reactive decision-making

Use Agent GPA metrics (excluding plan metrics):

  • Logical Consistency
  • Execution Efficiency
  • Tool Selection
  • Tool Calling
  • Tool Quality

Question 3: Do you want to add any additional evaluations?

Consider adding these based on your needs:

EvaluationUse Case
CoherenceCheck if output is well-structured and readable
ConcisenessEnsure responses aren't unnecessarily verbose
HarmlessnessDetect potentially harmful content
SentimentAnalyze emotional tone of responses
Custom metricsDomain-specific evaluations (see below)

Creating Custom Metrics

If you need domain-specific evaluations, describe what you want to measure:

What aspect of your app do you want to evaluate?

Examples:

  • "Check if the response follows our brand voice guidelines"
  • "Verify the output contains required legal disclaimers"
  • "Measure technical accuracy for code generation"
  • "Evaluate if customer support responses show empathy"

Template for custom metrics:

def my_custom_metric(input_text: str, output_text: str) -> float:
    """
    Describe what this metric evaluates.

    Returns:
        float: Score between 0.0 (worst) and 1.0 (best)
    """
    # Option 1: Rule-based logic
    # score = 1.0 if "required phrase" in output_text else 0.0

    # Option 2: Use LLM-as-judge
    # provider = OpenAI()
    # response = provider.client.chat.completions.create(
    #     model="gpt-4o",
    #     messages=[{
    #         "role": "user",
    #         "content": f"Rate this response on [YOUR CRITERIA]. Input: {input_text} Output: {output_text}. Return only a number 0-10."
    #     }]
    # )
    # score = float(response.choices[0].message.content) / 10.0

    return score

f_custom = Metric(
    implementation=my_custom_metric,
    name="My Custom Metric",
    selectors={
        "input_text": Selector.select_record_input(),
        "output_text": Selector.select_record_output(),
    },
)

Custom metric with context:

def custom_with_context(query: str, context: str, response: str) -> float:
    """Evaluate using query, retrieved context, and response."""
    # Your evaluation logic
    return score

f_custom_context = Metric(
    implementation=custom_with_context,
    name="Custom Context Metric",
    selectors={
        "query": Selector.select_record_input(),
        "context": Selector.select_context(collect_list=True),
        "response": Selector.select_record_output(),
    },
)

Tell me what you want to evaluate and I'll help you create the metric!


Overview

Feedback functions evaluate specific aspects of your app by:

  1. Selecting data from instrumented spans (inputs, outputs, retrieved contexts)
  2. Applying evaluation logic (LLM-as-judge, similarity metrics, etc.)
  3. Returning scores between 0.0 and 1.0

Prerequisites

pip install trulens trulens-providers-openai

Instructions

Step 1: Initialize a Feedback Provider

from trulens.providers.openai import OpenAI

provider = OpenAI(model_engine="gpt-4o")

Step 2: Create Feedback Functions with Selector Shortcuts

TruLens provides shortcuts for common selection patterns:

from trulens.core import Metric, Selector

# Answer relevance: input → output
f_answer_relevance = Metric(
    implementation=provider.relevance_with_cot_reasons,
    name="Answer Relevance",
    selectors={
        "prompt": Selector.select_record_input(),
        "response": Selector.select_record_output(),
    },
)

# Context relevance: input → each context chunk
f_context_relevance = Metric(
    implementation=provider.context_relevance_with_cot_reasons,
    name="Context Relevance",
    selectors={
        "question": Selector.select_record_input(),
        "context": Selector.select_context(collect_list=False),
    },
)

# Groundedness: all contexts → output
f_groundedness = Metric(
    implementation=provider.groundedness_measure_with_cot_reasons,
    name="Groundedness",
    selectors={
        "source": Selector.select_context(collect_list=True),
        "statement": Selector.select_record_output(),
    },
)

Shortcut Reference:

ShortcutSelectsRequired Span Type
on_input()App inputRECORD_ROOT
on_output()App outputRECORD_ROOT
on_context()Retrieved contextsRETRIEVAL

⚠️ IMPORTANT: .on_input() and .on_output() require RECORD_ROOT spans!

These shortcuts look for spans with span_type=SpanAttributes.SpanType.RECORD_ROOT. If you use manual instrumentation with a different span type (like AGENT), the shortcuts will not find any data.

Solutions:

  • Use framework wrappers (TruGraph, TruChain, TruLlama) which create RECORD_ROOT automatically
  • Use explicit @instrument(span_type=SpanAttributes.SpanType.RECORD_ROOT, ...) on your entry point
  • Use explicit Selector objects instead of shortcuts (see Step 3)

Step 3: Using Explicit Selectors

For more control, use Selector to target specific span attributes:

from trulens.core import Metric
from trulens.core.feedback.selector import Selector
from trulens.otel.semconv.trace import SpanAttributes

f_answer_relevance = Metric(
    implementation=provider.relevance_with_cot_reasons,
    name="Answer Relevance",
    selectors={
        "prompt": Selector(
            span_type=SpanAttributes.SpanType.RECORD_ROOT,
            span_attribute=SpanAttributes.RECORD_ROOT.INPUT,
        ),
        "response": Selector(
            span_type=SpanAttributes.SpanType.RECORD_ROOT,
            span_attribute=SpanAttributes.RECORD_ROOT.OUTPUT,
        ),
    },
)

Step 4: Understanding collect_list

The collect_list parameter controls how multiple values are handled:

SettingBehaviorUse Case
collect_list=FalseEvaluate each value individuallyContext relevance (score each chunk)
collect_list=TrueConcatenate all valuesGroundedness (check against all context)
# Evaluate each retrieved context individually (returns multiple scores)
f_context_relevance = Metric(
    implementation=provider.context_relevance_with_cot_reasons,
    name="Context Relevance",
    selectors={
        "question": Selector.select_record_input(),
        "context": Selector(
            span_type=SpanAttributes.SpanType.RETRIEVAL,
            span_attribute=SpanAttributes.RETRIEVAL.RETRIEVED_CONTEXTS,
            collect_list=False,
        ),
    },
)

# Evaluate against all contexts combined (returns single score)
f_groundedness = Metric(
    implementation=provider.groundedness_measure_with_cot_reasons,
    name="Groundedness",
    selectors={
        "source": Selector(
            span_type=SpanAttributes.SpanType.RETRIEVAL,
            span_attribute=SpanAttributes.RETRIEVAL.RETRIEVED_CONTEXTS,
            collect_list=True,
        ),
        "statement": Selector.select_record_output(),
    },
)

Step 5: Aggregating Multiple Scores

When collect_list=False produces multiple scores, aggregate them:

import numpy as np

f_context_relevance = Metric(
    implementation=provider.context_relevance_with_cot_reasons,
    name="Context Relevance",
    selectors={
        "question": Selector.select_record_input(),
        "context": Selector.select_context(collect_list=False),
    },
    agg=np.mean,
)

Common aggregation functions:

  • np.mean - Average score
  • np.min - Worst score (conservative)
  • np.max - Best score (optimistic)

Common Patterns

RAG Triad Setup

import numpy as np
from trulens.core import Metric, Selector
from trulens.providers.openai import OpenAI

provider = OpenAI()

# Context Relevance: Is each retrieved chunk relevant to the query?
f_context_relevance = Metric(
    implementation=provider.context_relevance_with_cot_reasons,
    name="Context Relevance",
    selectors={
        "question": Selector.select_record_input(),
        "context": Selector.select_context(collect_list=False),
    },
    agg=np.mean,
)

# Groundedness: Is the response grounded in the retrieved context?
f_groundedness = Metric(
    implementation=provider.groundedness_measure_with_cot_reasons,
    name="Groundedness",
    selectors={
        "source": Selector.select_context(collect_list=True),
        "statement": Selector.select_record_output(),
    },
)

# Answer Relevance: Does the response answer the original question?
f_answer_relevance = Metric(
    implementation=provider.relevance_with_cot_reasons,
    name

---

*Content truncated.*

When not to use it

  • When the user is not evaluating LLM application quality
  • When the application does not use instrumented spans

Prerequisites

trulenstrulens-providers-openai

Limitations

  • Shortcuts require RECORD_ROOT span types
  • Requires instrumentation of the application

How it compares

It provides interactive selection of metrics based on app type rather than requiring manual metric definition.

Compared to similar skills

trulens-evaluation-setup side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
trulens-evaluation-setup (this skill)13moReviewIntermediate
langchain268moReviewIntermediate
cocoindex69moReviewIntermediate
rag-implementation102moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

langchain

zechenzhangAGI

Framework for building LLM-powered applications with agents, chains, and RAG. Supports multiple providers (OpenAI, Anthropic, Google), 500+ integrations, ReAct agents, tool calling, memory management, and vector store retrieval. Use for building chatbots, question-answering systems, autonomous agents, or RAG applications. Best for rapid prototyping and production deployments.

26138

cocoindex

cocoindex-io

Comprehensive toolkit for developing with the CocoIndex library. Use when users need to create data transformation pipelines (flows), write custom functions, or operate flows via CLI or API. Covers building ETL workflows for AI data processing, including embedding documents into vector databases, building knowledge graphs, creating search indexes, or processing data streams with incremental updates.

6116

rag-implementation

wshobson

Build Retrieval-Augmented Generation (RAG) systems for LLM applications with vector databases and semantic search. Use when implementing knowledge-grounded AI, building document Q&A systems, or integrating LLMs with external knowledge bases.

10101

llamaindex

davila7

Data framework for building LLM applications with RAG. Specializes in document ingestion (300+ connectors), indexing, and querying. Features vector indices, query engines, agents, and multi-modal support. Use for document Q&A, chatbots, knowledge retrieval, or building RAG pipelines. Best for data-centric LLM applications.

357

similarity-search-patterns

wshobson

Implement efficient similarity search with vector databases. Use when building semantic search, implementing nearest neighbor queries, or optimizing retrieval performance.

349

senior-ml-engineer

davila7

World-class ML engineering skill for productionizing ML models, MLOps, and building scalable ML systems. Expertise in PyTorch, TensorFlow, model deployment, feature stores, model monitoring, and ML infrastructure. Includes LLM integration, fine-tuning, RAG systems, and agentic AI. Use when deploying ML models, building ML platforms, implementing MLOps, or integrating LLMs into production systems.

634

Search skills

Search the agent skills registry