Implementation:Truera Trulens UX Components
| Knowledge Sources | |
|---|---|
| Domains | Dashboard, Visualization |
| Last Updated | 2026-02-14 08:00 GMT |
Overview
Streamlit UI components module providing reusable functions for rendering selectors, call frames, metadata, LLM details, agent details, tool details, and prompt information in the TruLens dashboard.
Description
The components module in trulens.dashboard.ux provides a collection of Streamlit rendering functions used throughout the TruLens dashboard to display application internals, call traces, and component metadata. Key functions include:
Content Display:
- write_or_json(st, obj) -- Smart dispatcher that renders a string as
st.jsonif it parses into a non-string JSON structure (e.g., a dict), or asst.writeotherwise. Handles parse failures gracefully by falling back tost.write.
Selector Rendering:
- copy_to_clipboard(path) -- Stores a selector path string in
st.session_state.clipboardfor copy-to-clipboard functionality. - draw_selector_button(path) -- Renders a Streamlit button labeled with the dashboard-formatted selector path. Clicking the button copies the path to the clipboard. Uses
random.random()for unique widget keys. - render_selector_markdown(path) -- Returns a markdown-formatted string with the selector path rendered for dashboard display, enclosed in backticks and brackets.
Call Frame Rendering:
- render_call_frame(frame, path) -- Formats a
RecordAppCallframe as a markdown string showing the method name and its fully-qualified class path (module and class name), using bold formatting.
Metadata Display:
- dict_to_md(dictionary) -- Converts a dictionary into a Markdown table string with a single header row and single data row. Returns
"No metadata."for empty dictionaries. - draw_metadata_and_tags(metadata, tags) -- Merges tags into the metadata dictionary, renames internal column names (e.g.,
EXTERNAL_APP_COL_NAMEto "External App?",PINNED_COL_NAMEto "Pinned?") for user-friendliness, and renders as a Markdown table.
Call Tree Rendering:
- draw_call(call) -- Renders a single
RecordAppCallas a Streamlit expander. The expander label shows the method name, class, and selector path. Inside, it displays the call stack (via frames), input arguments (as JSON or write), and output returns. - draw_calls(record, index) -- Iterates through all calls in a record and renders only the call matching the given step
indexusingdraw_call.
Component Detail Panels:
- draw_prompt_info(query, component) -- Renders prompt details for a component as expandable sections, filtering out
None, empty, and non-serializable values. Each section is labeled with its key and the corresponding selector path. - draw_llm_info(query, component) -- Renders LLM component details as a Streamlit table. Handles nested dictionary columns by flattening them into separate columns. Redacts columns whose names indicate secrets (via
key_utils.should_redact_key). - draw_agent_info(query, component) -- Renders agent details using the same pattern as
draw_prompt_info. - draw_tool_info(query, component) -- Renders tool details using the same pattern as
draw_prompt_info.
Usage
Use these functions when building custom dashboard pages that need to display TruLens application internals. The draw_call and draw_calls functions are central to the record detail/trace views. The draw_llm_info, draw_prompt_info, draw_agent_info, and draw_tool_info functions are used by the app detail pages to render component configurations.
Code Reference
Source Location
- Repository: Truera_Trulens
- File: src/dashboard/trulens/dashboard/ux/components.py
- Lines: 1-327
Signature
def write_or_json(st, obj): ...
def copy_to_clipboard(path, *args, **kwargs): ...
def draw_selector_button(path) -> None: ...
def render_selector_markdown(path) -> str: ...
def render_call_frame(
frame: record_schema.RecordAppCall, path=None,
) -> str: ...
def dict_to_md(dictionary: dict) -> str: ...
def draw_metadata_and_tags(
metadata: types_schema.Metadata, tags: types_schema.Tags,
) -> str: ...
def draw_call(call: record_schema.RecordAppCall) -> None: ...
def draw_calls(record: record_schema.Record, index: int) -> None: ...
def draw_prompt_info(
query: serial_utils.Lens, component: core_app.ComponentView,
) -> None: ...
def draw_llm_info(
query: serial_utils.Lens, component: core_app.ComponentView,
) -> None: ...
def draw_agent_info(
query: serial_utils.Lens, component: core_app.ComponentView,
) -> None: ...
def draw_tool_info(
query: serial_utils.Lens, component: core_app.ComponentView,
) -> None: ...
Import
from trulens.dashboard.ux.components import write_or_json
from trulens.dashboard.ux.components import draw_selector_button
from trulens.dashboard.ux.components import render_selector_markdown
from trulens.dashboard.ux.components import render_call_frame
from trulens.dashboard.ux.components import draw_metadata_and_tags
from trulens.dashboard.ux.components import draw_call
from trulens.dashboard.ux.components import draw_calls
from trulens.dashboard.ux.components import draw_prompt_info
from trulens.dashboard.ux.components import draw_llm_info
from trulens.dashboard.ux.components import draw_agent_info
from trulens.dashboard.ux.components import draw_tool_info
I/O Contract
Inputs
write_or_json:
| Name | Type | Required | Description |
|---|---|---|---|
| st | module | yes | The Streamlit module reference (passed explicitly). |
| obj | Any | yes | The object to display. If a JSON-parseable string that yields a dict, rendered as st.json.
|
draw_selector_button:
| Name | Type | Required | Description |
|---|---|---|---|
| path | serial_utils.Lens | yes | A Lens selector path to display on the button and copy to clipboard. |
render_call_frame:
| Name | Type | Required | Description |
|---|---|---|---|
| frame | record_schema.RecordAppCall | yes | A single call frame from the record call stack. |
| path | Optional[serial_utils.Lens] | no | Override path. Defaults to frame.path if not provided.
|
draw_call:
| Name | Type | Required | Description |
|---|---|---|---|
| call | record_schema.RecordAppCall | yes | The call record to render with its stack, args, and rets. |
draw_calls:
| Name | Type | Required | Description |
|---|---|---|---|
| record | record_schema.Record | yes | The full record containing all calls. |
| index | int | yes | The 1-based step index of the call to render. |
draw_llm_info / draw_prompt_info / draw_agent_info / draw_tool_info:
| Name | Type | Required | Description |
|---|---|---|---|
| query | serial_utils.Lens | yes | The Lens path identifying this component within the app. |
| component | core_app.ComponentView | yes | The component view containing the JSON details to display. |
draw_metadata_and_tags:
| Name | Type | Required | Description |
|---|---|---|---|
| metadata | types_schema.Metadata | yes | The metadata dictionary for the app. |
| tags | types_schema.Tags | yes | The tags string for the app. |
Outputs
| Name | Type | Description |
|---|---|---|
| write_or_json | None | Renders content directly to the Streamlit page. |
| draw_selector_button | None | Renders a button to the Streamlit page; copies path to session state on click. |
| render_selector_markdown | str | Returns a markdown-formatted selector string (e.g., [`Select.RecordCalls.retrieve`]).
|
| render_call_frame | str | Returns a markdown string describing the call frame method and class. |
| dict_to_md | str | Returns a Markdown table string representation of a dictionary. |
| draw_metadata_and_tags | str | Returns a Markdown table string with metadata and tags combined. |
| draw_call / draw_calls | None | Renders call details directly to the Streamlit page. |
| draw_llm_info / draw_prompt_info / draw_agent_info / draw_tool_info | None | Renders component detail panels directly to the Streamlit page. |
Usage Examples
from trulens.dashboard.ux.components import write_or_json
import streamlit as st
# Display a JSON string as formatted JSON
write_or_json(st, '{"key": "value", "nested": {"a": 1}}')
# Display a plain string as text
write_or_json(st, "This is a plain text response.")
from trulens.dashboard.ux.components import draw_calls
# Render a specific call step from a record
record = session.get_record(record_id="rec_abc123")
draw_calls(record, index=2) # Renders the 2nd call step
from trulens.dashboard.ux.components import draw_metadata_and_tags
# Render metadata as a help tooltip
metadata = {"model": "gpt-4", "temperature": 0.7}
tags = "production,v2"
help_text = draw_metadata_and_tags(metadata, tags)
st.header("My App v2", help=help_text)
from trulens.dashboard.ux.components import draw_llm_info
from trulens.core.schema.select import Select
# Render LLM details for a specific component
query = Select.App.llm
component = app_json["components"][0]
draw_llm_info(query, component)