Skip to content

row

row

Functions:

Name Description
record_record_metrics

Record per-row count, length, and nominal-call metrics from a trace DataFrame.

record_evaluation_metrics

Record sanitized per-row LLM-as-judge verdict metrics from an evaluated trace dataframe.

record_record_metrics(dataframe, *, mode, strategy, text_column, validation_max_entities_per_call)

Record per-row count, length, and nominal-call metrics from a trace DataFrame.

Source code in src/anonymizer/measurement/records/row.py
def record_record_metrics(
    dataframe: pd.DataFrame,
    *,
    mode: str,
    strategy: str,
    text_column: str,
    validation_max_entities_per_call: int,
) -> None:
    """Record per-row count, length, and nominal-call metrics from a trace DataFrame."""
    collector = current_collector()
    if collector is None or not collector.record_level:
        return

    ground_truth_column = next((col for col in _GROUND_TRUTH_ENTITY_COLUMNS if col in dataframe.columns), None)
    columns = set(dataframe.columns)
    for row_index, row in dataframe.iterrows():
        final_entities = _entities_from_raw(row.get(COL_FINAL_ENTITIES))
        collector.record(
            "record",
            **_base_record_fields(
                collector=collector,
                row_index=row_index,
                row=row,
                text_column=text_column,
                mode=mode,
                strategy=strategy,
            ),
            **_entity_record_fields(row, final_entities=final_entities, ground_truth_column=ground_truth_column),
            **_replacement_record_fields(row, columns=columns, final_entities=final_entities),
            **_rewrite_record_fields(row, columns=columns),
            **_original_value_leak_record_fields(row, columns=columns, final_entities=final_entities),
            **_llm_record_fields(
                row,
                columns=columns,
                mode=mode,
                strategy=strategy,
                final_entity_count=len(final_entities),
                validation_max_entities_per_call=validation_max_entities_per_call,
            ),
        )

record_evaluation_metrics(dataframe, *, mode, strategy, text_column)

Record sanitized per-row LLM-as-judge verdict metrics from an evaluated trace dataframe.

Source code in src/anonymizer/measurement/records/row.py
def record_evaluation_metrics(
    dataframe: pd.DataFrame,
    *,
    mode: str,
    strategy: str,
    text_column: str,
) -> None:
    """Record sanitized per-row LLM-as-judge verdict metrics from an evaluated trace dataframe."""
    collector = current_collector()
    if collector is None or not collector.record_level:
        return

    columns = set(dataframe.columns)
    if not _has_evaluation_metrics(columns):
        return

    for row_index, row in dataframe.iterrows():
        collector.record(
            "evaluation_record",
            **_base_record_fields(
                collector=collector,
                row_index=row_index,
                row=row,
                text_column=text_column,
                mode=mode,
                strategy=strategy,
            ),
            **_evaluation_record_fields(row, columns=columns),
        )