What is TruLens?
TruLens is an open-source Python library for evaluating and tracking LLM applications and agents. It sits in the Evaluation & Red-Teaming category of the Evaluation & Production Ops tools and is open-source, written in Python and licensed MIT. To get started: install the core package.
Overview
TruLens is an open-source Python library for evaluating and tracking LLM applications and agents. Instead of manually checking outputs by hand, you attach feedback functions that score each run, so you can measure how a prompt, model, or retriever change affects quality and iterate from there.
Its instrumentation is built on OpenTelemetry, so every function call, LLM generation, retrieval, and tool invocation is captured as a structured span. Those traces are interoperable with existing observability backends like Jaeger, Grafana Tempo, Datadog, or any OTLP-compatible system.
It fits the evaluation and testing category as an eval framework for teams building RAG pipelines and agentic systems. It ships agent-specific evaluators, batch and inline evaluation modes, MCP tracing, and connectors for providers such as OpenAI, LiteLLM, Google, Bedrock, Snowflake Cortex, and HuggingFace.
What it does
- OpenTelemetry-based tracing: each retrieval, generation, and tool call is captured as a structured OTEL span you can export to OTLP backends
- Feedback functions to systematically score app runs instead of manually vibe-checking outputs
- Seven agent evaluators including LogicalConsistency, PlanAdherence, ToolSelection, and ToolCalling
- Inline, on existing data, or offline batch evaluation via the Run API
- MCP span type to instrument Model Context Protocol tool calls (name, arguments, output, latency)
- Provider packages for OpenAI/Azure, LiteLLM, Google Gemini, AWS Bedrock, Snowflake Cortex, HuggingFace, and LangChain
Getting started
Install the core package from PyPI, add a provider for feedback evaluation, then instrument your app with OpenTelemetry spans.
Install the core package
Install TruLens core from PyPI.
pip install trulens-coreAdd a provider and framework integration
Install a provider for feedback evaluation and, if needed, an app framework integration.
pip install trulens trulens-providers-openai # OpenAI / Azure OpenAI
pip install trulens trulens-apps-langchain # LangChain / LangGraphInstrument a retrieval span
Decorate your app methods with the OpenTelemetry instrument decorator so each call is captured as a typed span.
from trulens.core.otel.instrument import instrument
from trulens.otel.semconv.trace import SpanAttributes
class MyRAG:
@instrument(
span_type=SpanAttributes.SpanType.RETRIEVAL,
attributes={
SpanAttributes.RETRIEVAL.QUERY_TEXT: "query",
SpanAttributes.RETRIEVAL.RETRIEVED_CONTEXTS: "return",
},
)
def retrieve(self, query: str) -> list:
...Target attributes with the Selector API
Define a metric and point it at the span attributes you want to evaluate.
from trulens.core import Metric, Selector
f_context_relevance = Metric(
name="Context Relevance",
implementation=provider.context_relevance,
selectors={
"input": Selector.select_record_input(),
"context": Selector.select_context(),
},
)Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Measure RAG quality with feedback functions for context relevance and groundedness while iterating on prompts, models, and retrievers
- Debug agent behavior with evaluators for plan adherence, tool selection, and tool calling
- Export LLM traces as OpenTelemetry spans to Jaeger, Grafana Tempo, Datadog, or another OTLP backend
- Run offline batch evaluations over a pre-collected dataset using the Run API
How TruLens compares
TruLens alongside other open-source evaluation & red-teaming tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| Strix | ★ 78.4k | Strix runs autonomous AI agents that act like hackers, dynamically running your code to find vulnerabilities and validate them with real proof-of-concepts. |
| iFixAi | ★ 47.6k | An agent auditor that runs up to 60 inspections across fabrication, manipulation, deception, unpredictability and opacity, and returns an A–F grade judged by a model from a different vendor. |
| promptfoo | ★ 27.9k | A developer-first CLI and library for testing and comparing prompts and models, with red-teaming probes for prompt injection, PII leaks, and other vulnerabilities. |
| OpenAI Evals | ★ 19.8k | A framework and open registry for building and running evaluations of LLMs and LLM-based systems, including prompt chains and tool-using agents. |
| DeepEval | ★ 19.7k | An open-source Python framework that tests LLM apps like unit tests, with 50+ metrics for RAG, agents, chatbots, and safety, and a Pytest integration for CI/CD. |
| Ragas | ★ 16.5k | An evaluation toolkit focused on retrieval-augmented generation that scores answer faithfulness, context precision/recall, and relevancy, often without needing ground-truth labels. |
| Arize Phoenix | ★ 12.5k | An open-source observability and evaluation tool for tracing LLM and agent behavior, running evals on traces, and troubleshooting issues in development and production. |
| TruLens | ★ 3.7k | Trace and evaluate LLM apps and agents with feedback functions on OpenTelemetry |

