Implementation:Truera Trulens Streamlit Page Renderer
| Knowledge Sources | |
|---|---|
| Domains | Dashboard, Visualization |
| Last Updated | 2026-02-14 08:00 GMT |
Overview
The main Streamlit page rendering module that provides public-facing functions for displaying TruLens leaderboards, feedback details, and trace views.
Description
The streamlit module is the primary entry point for rendering TruLens dashboard pages using Streamlit. It exposes several key functions that can be embedded into any Streamlit application or used by the built-in TruLens dashboard:
- init_from_args() -- Parses command-line arguments (
--database-url,--database-prefix) and initializes aTruSessionsingleton. This ensures all subsequent session references share the same configuration.
- FeedbackDisplay -- A Pydantic
BaseModelthat holds a feedback score (float), a list ofFeedbackCallobjects, and an icon string. Used to structure feedback data for rendering.
- trulens_leaderboard(app_ids) -- Renders a full leaderboard page showing all tracked applications. For each app, it displays metrics including record count, average latency, total cost (USD), total tokens, and per-feedback-column averages with color-coded category indicators (pass/fail icons and delta colors). Applications are grouped by
app_name - app_versionand separated by horizontal rules.
- trulens_feedback(record) -- Decorated with
@st_fragment(run_every=2)for live auto-refresh. Accepts either aRecordobject or arecord_idstring. Renders clickable feedback pills for all feedback columns associated with the selected record. When a pill is clicked, the detailed feedback call data is displayed below using_render_feedback_call.
- trulens_trace(record) -- Displays the trace view for a record. For non-OTel records, it uses the standard
record_viewercomponent. For OTel-based records (identified by passing a string record_id), it fetches OTel spans via_get_event_otel_spansand renders them withrecord_viewer_otel. When SiS (Streamlit in Snowflake) compatibility is enabled, trace view is disabled with a warning.
The module also sets the asyncio event loop at import time to work around a known llama_index compatibility issue.
Usage
Use these functions when building a custom Streamlit dashboard for TruLens data, or rely on them indirectly through the built-in tru.run_dashboard() command. The trulens_leaderboard function is ideal for overview pages, while trulens_feedback and trulens_trace are designed for record-detail pages.
Code Reference
Source Location
- Repository: Truera_Trulens
- File: src/dashboard/trulens/dashboard/streamlit.py
- Lines: 1-308
Signature
class FeedbackDisplay(BaseModel):
score: float = 0
calls: List[feedback_schema.FeedbackCall]
icon: str
def init_from_args(): ...
def trulens_leaderboard(app_ids: Optional[List[str]] = None): ...
@streamlit_compat.st_fragment(run_every=2)
def trulens_feedback(record: Union[record_schema.Record, str]): ...
def trulens_trace(record: Union[record_schema.Record, str]): ...
Import
from trulens.dashboard.streamlit import trulens_leaderboard
from trulens.dashboard.streamlit import trulens_feedback
from trulens.dashboard.streamlit import trulens_trace
from trulens.dashboard.streamlit import init_from_args
from trulens.dashboard.streamlit import FeedbackDisplay
I/O Contract
Inputs
init_from_args:
| Name | Type | Required | Description |
|---|---|---|---|
| (none -- reads from sys.argv) | -- | -- | Parses --database-url and --database-prefix from the command line.
|
trulens_leaderboard:
| Name | Type | Required | Description |
|---|---|---|---|
| app_ids | Optional[List[str]] | no | A list of application IDs to filter the leaderboard. If None, all apps are shown.
|
trulens_feedback:
| Name | Type | Required | Description |
|---|---|---|---|
| record | Union[record_schema.Record, str] | yes | A TruLens Record object (non-OTel) or a record_id string (OTel).
|
trulens_trace:
| Name | Type | Required | Description |
|---|---|---|---|
| record | Union[record_schema.Record, str] | yes | A TruLens Record object (non-OTel) or a record_id string (OTel).
|
Outputs
| Name | Type | Description |
|---|---|---|
| (rendered UI) | Streamlit widgets | All functions render directly to the active Streamlit page; they do not return values. |
| FeedbackDisplay.score | float | The numeric feedback score. |
| FeedbackDisplay.calls | List[FeedbackCall] | The list of individual feedback call records. |
| FeedbackDisplay.icon | str | The category icon string (e.g., pass/fail indicator). |
Usage Examples
# Using trulens_leaderboard in a custom Streamlit app
import streamlit as st
from trulens.dashboard.streamlit import trulens_leaderboard
st.title("My LLM App Dashboard")
trulens_leaderboard()
# Displaying feedback pills and trace for a specific record
from trulens.dashboard.streamlit import trulens_feedback, trulens_trace
with tru_app as recording:
response = my_app.invoke("Tell me about AI safety")
record, response = recording.get()
# Render interactive feedback pills (auto-refreshes every 2 seconds)
trulens_feedback(record=record)
# Render the full trace tree
trulens_trace(record=record)
# Using with OTel record IDs (string-based)
from trulens.dashboard.streamlit import trulens_feedback, trulens_trace
record_id = "abc123-def456"
trulens_feedback(record=record_id)
trulens_trace(record=record_id)