Skip to content

Commit f1265e6

Browse files
committed
fix(logging): handle missing id and task in verbose logs (#1343)
Update verbose logging to safely handle cases where log records may not have 'id' or 'task' attributes. Prevents potential AttributeError and improves robustness of LLM and prompt log output formatting.
1 parent acf5263 commit f1265e6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

nemoguardrails/logging/verbose.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def emit(self, record) -> None:
5454
skip_print = True
5555
if verbose_llm_calls:
5656
console.print("")
57-
console.print(f"[cyan]LLM {title} ({record.id[:5]}..)[/]")
57+
id_str = getattr(record, "id", None)
58+
id_display = f"({id_str[:5]}..)" if id_str else ""
59+
console.print(f"[cyan]LLM {title} {id_display}[/]")
5860
for line in body.split("\n"):
5961
text = Text(line, style="black on #006600", end="\n")
6062
text.pad_right(console.width)
@@ -66,9 +68,10 @@ def emit(self, record) -> None:
6668
if verbose_llm_calls:
6769
skip_print = True
6870
console.print("")
69-
console.print(
70-
f"[cyan]LLM Prompt ({record.id[:5]}..) - {record.task}[/]"
71-
)
71+
id_str = getattr(record, "id", None)
72+
id_display = f"({id_str[:5]}..)" if id_str else ""
73+
task_str = getattr(record, "task", "unknown")
74+
console.print(f"[cyan]LLM Prompt {id_display} - {task_str}[/]")
7275

7376
for line in body.split("\n"):
7477
if line.strip() == "[/]":

0 commit comments

Comments
 (0)