chore: Avoid rendering empty columns as part of detailed results rendering of eval results

It is common for expected response and expected tool calls column to be empty for user simulated conversations. So, we don't render those.

Co-authored-by: Ankur Sharma <ankusharma@google.com>
PiperOrigin-RevId: 826202867
This commit is contained in:
Ankur Sharma
2025-10-30 15:08:07 -07:00
committed by Copybara-Service
parent b8a2b6c570
commit 5cb35db921
+22 -8
View File
@@ -214,14 +214,16 @@ def pretty_print_eval_result(eval_result: EvalCaseResult):
expected_invocation = per_invocation_result.expected_invocation expected_invocation = per_invocation_result.expected_invocation
row_data = { row_data = {
"prompt": _convert_content_to_text(actual_invocation.user_content), "prompt": _convert_content_to_text(actual_invocation.user_content),
"expected_response": _convert_content_to_text( "expected_response": (
expected_invocation.final_response if expected_invocation else None _convert_content_to_text(expected_invocation.final_response)
if expected_invocation
else None
), ),
"actual_response": _convert_content_to_text( "actual_response": _convert_content_to_text(
actual_invocation.final_response actual_invocation.final_response
), ),
"expected_tool_calls": _convert_tool_calls_to_text( "expected_tool_calls": (
expected_invocation.intermediate_data _convert_tool_calls_to_text(expected_invocation.intermediate_data)
if expected_invocation if expected_invocation
else None else None
), ),
@@ -252,11 +254,23 @@ def pretty_print_eval_result(eval_result: EvalCaseResult):
) )
click.echo("Invocation Details:") click.echo("Invocation Details:")
df = pd.DataFrame(data) df = pd.DataFrame(data)
# Identify columns where ALL values are exactly None
columns_to_keep = []
for col in df.columns: for col in df.columns:
if df[col].dtype == "object": # Check if all elements in the column are NOT None
df[col] = df[col].str.wrap(40) if not df[col].apply(lambda x: x is None).all():
click.echo(tabulate(df, headers="keys", tablefmt="grid")) columns_to_keep.append(col)
click.echo("\n\n") # Few empty lines for visual clarity
# Select only the columns to keep
df_result = df[columns_to_keep]
for col in df_result.columns:
if df_result[col].dtype == "object":
df_result[col] = df_result[col].str.wrap(40)
click.echo(tabulate(df_result, headers="keys", tablefmt="grid"))
click.echo("\n\n") # Few empty lines for visual clarity
def get_eval_sets_manager( def get_eval_sets_manager(