Skip to content

trulens.core.metric.selector

trulens.core.metric.selector

Classes

Selector dataclass

Attributes
is_dataset_selector property
is_dataset_selector: bool

Whether this selector reads from a tabular dataset column.

Functions
from_column staticmethod
from_column(
    column_name: str,
    *,
    collect_list: bool = True,
    ignore_none_values: bool = False
) -> Selector

Returns a Selector that reads its value from a dataset column.

This is used for batch/offline evaluation with BatchEvaluator, where metrics are run over a pre-collected dataset (a pandas DataFrame or a list of dicts) instead of over spans produced by a live app. Batch results are returned in-memory only and are not persisted to the dashboard; for dashboard-visible evaluation of pre-collected data, use Run with mode=Mode.LOG_INGESTION.

PARAMETER DESCRIPTION
column_name

The name of the dataset column to read the value from.

TYPE: str

collect_list

Only relevant when the column holds list values. If True (default), the whole list is passed to the metric in a single call. If False, the metric is called once per item in the list and the results are aggregated.

TYPE: bool DEFAULT: True

ignore_none_values

If True, skip evaluation for rows where the selected value is None (or missing).

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Selector

A Selector that selects from the given tabular column.

select_conversation staticmethod
select_conversation() -> Selector

Return a selector for ordered records in a conversation.

select_conversation_input staticmethod
select_conversation_input() -> Selector

Return a selector for ordered inputs in a conversation.

select_conversation_output staticmethod
select_conversation_output() -> Selector

Return a selector for ordered outputs in a conversation.

select_record_input staticmethod
select_record_input(
    ignore_none_values: bool = True,
) -> Selector

Returns a Selector that gets the record input.

PARAMETER DESCRIPTION
ignore_none_values

If True, skip evaluation when the input is None. Defaults to True to prevent errors on missing data.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Selector

Selector that gets the record input.

select_record_output staticmethod
select_record_output(
    ignore_none_values: bool = True,
) -> Selector

Returns a Selector that gets the record output.

PARAMETER DESCRIPTION
ignore_none_values

If True, skip evaluation when the output is None. Defaults to True to prevent errors on missing data.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Selector

Selector that gets the record output.

select_context staticmethod
select_context(
    *, collect_list: bool, ignore_none_values: bool = True
) -> Selector

Returns a Selector that tries to retrieve contexts.

PARAMETER DESCRIPTION
collect_list

Assuming the returned Selector describes a list of strings, whether to call the feedback function: 1. [if collect_list is True]: Once giving the entire list as input. 2. [if collect_list is False]: Separately for each entry in the list and aggregate the results.

TYPE: bool

ignore_none_values

If True, skip evaluation when contexts are None. Defaults to True to prevent errors on missing data.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Selector

Selector that tries to retrieve contexts.

Trace dataclass

Functions
to_compressed_json
to_compressed_json(default_handler: Callable = str) -> str

Convert trace events to compressed JSON format. This reduces token usage while preserving essential information.

PARAMETER DESCRIPTION
default_handler

Function to handle non-serializable objects

TYPE: Callable DEFAULT: str

RETURNS DESCRIPTION
str

Compressed JSON string representation of the trace