Skip to main content

PyPI - Version Azure Build Status GitHub PyPI - Downloads Docs Ask DeepWiki

🦑 TruLens

TruLens

TruLens finds where your agent fails and where you can cut cost without losing quality. Open source, OpenTelemetry-native.

Instrument any app with a decorator, score every step with LLM judges that explain themselves, then compare versions and ship the one that earns it. Tracing is OpenTelemetry-native, so a trace is portable to any OTLP backend, and evaluations run either as traces land or over a dataset after the fact.

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

Trace every step

Latency, inputs, outputs, tokens and cost, recorded per step, so a bad answer has a traceable cause rather than a vibe.

TruLens trace waterfall

Compare versions, ship the frontier

Scores, latency and cost per app version, so the tradeoff is visible instead of guessed. The cheapest version is often not the worst one.

TruLens leaderboard

Don't take our word for it

TruLens judges are graded against human annotations, out of the box.

Result Metric Detail
95% Agent errors caught with Agent GPA on TRAIL/GAIA 267 of 281 human-annotated errors, against 55% for the baseline trace judge (arXiv:2510.08847)
0.81 Groundedness F1 on LLM-AggreFact Ahead of a fine-tuned proprietary model, Bespoke-MiniCheck-7B, on F1, precision and recall over an 11,000-example holdout (RAG triad benchmarks)
0.93 Context relevance NDCG@5 First of five tools on three of four ranking metrics, ahead of WandB Weave, RAGAS, DeepEval and UpTrain (AIMultiple, 23 March 2026)
4.2:1 Context relevance adversarial win-loss Scored the correct passage over a near-copy with one fact swapped 4.2 times for every reversal, against 3.3:1 for the next best tool (AIMultiple)

Adopted by AI teams at

Walmart Global Tech, Cisco, J.P. Morgan Chase, Equinix, VMware by Broadcom, Hitachi Digital Services, Thomson Reuters, phData, HID Global and others. See ADOPTERS.md.

Installation and Setup

Install the trulens pip package from PyPI.

pip install trulens

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 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!

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.14.0.tar.gz (6.8 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.14.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: trulens-2.14.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.16

File hashes

Hashes for trulens-2.14.0.tar.gz
Algorithm Hash digest
SHA256 446b0b81c008e6c3222e48edf2f9c5577b726d9b331b345fbdd5c4c74325c6f1
MD5 39008c3a4f131a32a7cc7174f3bf364e
BLAKE2b-256 143378a9ee1c017181580e074e49ee9dd2e9d16c38dbede4d6bda7bcd49b2e8b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: trulens-2.14.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.16

File hashes

Hashes for trulens-2.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98276b4246218c286c033c8a6fa0a47f775ffe1a19f5b67e9670541c709451ae
MD5 9a7bc671e413dc551fb75917d80e2f3c
BLAKE2b-256 89eb0995c24875f5b0c05eabefb7fbb73fb37871f8ee60c36f4fb6fcf386434e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.14.0 This release

2 files

2.13.1

2 files

2.13.0

2 files

2.12.0

2 files

2.11.0

2 files

2.10.0

2 files

2.9.0

2 files

2.8.1

2 files

2.8.0

2 files

2.7.2

2 files

2.7.1

2 files

2.7.0

2 files

2.6.0

2 files

2.5.3

2 files

2.5.2

2 files

2.5.1

2 files

2.5.0

2 files

2.4.2

2 files

2.4.1

2 files

2.4.0

2 files

2.3.1

2 files

2.3.0

2 files

2.2.4

2 files

2.2.3

2 files

2.2.2

2 files

2.2.1

2 files

2.2.0

2 files

2.1.4

2 files

2.1.2

2 files

2.1.1

2 files

2.1.0

2 files

1.5.3

2 files

1.5.2

2 files

1.5.1

2 files

1.5.0

2 files

1.4.9

2 files

1.4.8

2 files

1.4.7

2 files

1.4.6

2 files

1.4.5

2 files

1.4.4

2 files

1.4.3

2 files

1.4.2

2 files

1.4.1

2 files

1.4.0

2 files

1.3.5

2 files

1.3.4

2 files

1.3.3

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.11

2 files

1.2.10

2 files

1.2.9

2 files

1.2.8

2 files

1.2.7

2 files

1.2.6

2 files

1.2.5

2 files

1.2.4

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.11

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

0.13.4

1 file

0.13.3

1 file

0.13.2

1 file

0.13.1

1 file

0.13.0

1 file

0.12.1

1 file

0.0.12.1

1 file

0.0.12

1 file

0.0.11

1 file

0.0.10

1 file

0.0.9

1 file

0.0.8

1 file

0.0.7

1 file

0.0.6

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page