Skip to main content

Library to systematically track and evaluate LLM based applications.

Project description

PyPI - Version Azure Build Status GitHub PyPI - Downloads Discourse Docs Open In Colab Ask DeepWiki

🦑 Welcome to TruLens!

TruLens

Don't just vibe-check your LLM app! Systematically evaluate and track your LLM experiments with TruLens. As you develop your app including prompts, models, retrievers, knowledge sources and more, TruLens is the tool you need to understand its performance.

Fine-grained, stack-agnostic instrumentation and comprehensive evaluations help you to identify failure modes & systematically iterate to improve your application.

Read more about the core concepts behind TruLens including Feedback Functions, The RAG Triad, and Honest, Harmless and Helpful Evals.

TruLens in the development workflow

Build your first prototype then connect instrumentation and logging with TruLens. Decide what feedbacks you need, and specify them with TruLens to run alongside your app. Then iterate and compare versions of your app in an easy-to-use user interface 👇

Architecture Diagram

Installation and Setup

Install the trulens pip package from PyPI.

pip install trulens-core

Install with a specific LLM provider for feedback evaluation:

pip install trulens trulens-providers-openai   # OpenAI / Azure OpenAI
pip install trulens trulens-providers-litellm  # LiteLLM (Anthropic, Cohere, Mistral, …)
pip install trulens trulens-providers-google   # Google Gemini
pip install trulens trulens-providers-bedrock  # AWS Bedrock
pip install trulens trulens-providers-cortex   # Snowflake Cortex
pip install trulens trulens-providers-huggingface  # HuggingFace
pip install trulens trulens-providers-langchain    # LangChain models

Install with a specific app framework integration:

pip install trulens trulens-apps-langchain    # LangChain / LangGraph
pip install trulens trulens-apps-llamaindex  # LlamaIndex

Quick Usage

Walk through how to instrument and evaluate a RAG built from scratch with TruLens.

Open In Colab

Key Features

🔭 OpenTelemetry-based tracing

TruLens instrumentation is built on OpenTelemetry. Every function call, LLM generation, retrieval, and tool invocation is captured as a structured OTEL span. This makes TruLens interoperable with existing observability infrastructure — export traces to Jaeger, Grafana Tempo, Datadog, or any OTLP-compatible backend.

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:
        ...

🤖 Agentic evaluations

Seven purpose-built evaluators for agentic systems — each measuring a distinct aspect of agent behavior:

Evaluator What it measures
LogicalConsistency Reasoning coherence; flags hallucinations and unsupported assertions
ExecutionEfficiency Redundant steps, unnecessary retries, wasted computation
PlanAdherence Whether execution followed the stated plan
PlanQuality Intrinsic plan quality — strategy, not outcome
ToolSelection Right tool chosen for each subtask
ToolCalling Argument validity and output interpretation
ToolQuality External tool/service reliability

📊 Batch and inline evaluation

Run evaluations alongside your app, on existing data, or in offline batch mode:

# Inline — evaluate as the app runs
with tru_recorder as recording:
    response = my_app.query("What is TruLens?")

# Batch — evaluate a pre-collected dataset using the TruLens 2.8 Run API
from trulens.core.run import RunConfig

run_config = RunConfig(
    run_name="batch_eval_v1",
    dataset_name="eval_questions",
    source_type="TABLE",
    dataset_spec={"input": "QUESTION"},
    invocation_max_workers=8,
    metric_max_workers=4,
)
run = tru_app.add_run(run_config=run_config)
run.start()
run.compute_metrics([relevance, groundedness])

🔌 MCP support

Instrument Model Context Protocol tool calls with the MCP span type to capture tool name, arguments, output, and latency:

@instrument(span_type=SpanAttributes.SpanType.MCP)
def call_mcp_tool(self, tool_name: str, arguments: dict) -> str:
    ...

🎯 Selector API

Target any span attribute for evaluation using the flexible Selector API:

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(),
    },
)

Supported LLM Providers

Provider Package
OpenAI / Azure OpenAI trulens-providers-openai
LiteLLM (Anthropic, Cohere, Mistral, and more) trulens-providers-litellm
Google Gemini trulens-providers-google
AWS Bedrock trulens-providers-bedrock
Snowflake Cortex trulens-providers-cortex
HuggingFace trulens-providers-huggingface
LangChain models trulens-providers-langchain

💡 Contributing & Community

Interested in contributing? See our contributing guide for more details.

The best way to support TruLens is to give us a ⭐ on GitHub and join our discourse community!

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trulens-2.9.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trulens-2.9.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file trulens-2.9.0.tar.gz.

File metadata

  • Download URL: trulens-2.9.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for trulens-2.9.0.tar.gz
Algorithm Hash digest
SHA256 880953a3b3b6524b2008a247dec6e5cbf894c774316fa7423674471d9bbe351f
MD5 ec013ca382f6323572495a8f4fea3876
BLAKE2b-256 408df5c86546841e759d6f0e6de9867b74cb12de66d2d1da2747c4f335b81159

See more details on using hashes here.

File details

Details for the file trulens-2.9.0-py3-none-any.whl.

File metadata

  • Download URL: trulens-2.9.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for trulens-2.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 142f9816f45f59660449adceedfdff933fca9477a634ad8ff96a2d506900464e
MD5 a9cc29314a2b83eb7abdd2cd2a4cd146
BLAKE2b-256 f41bf469f580ca792f06e903755875c7a04b2b0027b2736d53ae703913933605

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page