Skip to content

Commit c47d352

Browse files
committed
better part checking
1 parent a26126d commit c47d352

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/guardrails/agents.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def _extract_text_from_input(input_data: Any) -> str:
357357

358358
# If it's a list (conversation history), extract the latest user message
359359
if isinstance(input_data, list):
360-
if len(input_data) == 0:
360+
if not input_data:
361361
return "" # Empty list returns empty string
362362

363363
# Iterate from the end to find the latest user message
@@ -374,8 +374,12 @@ def _extract_text_from_input(input_data: Any) -> str:
374374
text_parts = []
375375
for part in content:
376376
if isinstance(part, dict):
377-
# Check for various text field names
378-
text = part.get("text") or part.get("input_text") or part.get("output_text")
377+
# Check for various text field names (avoid falsy empty string issue)
378+
text = None
379+
for field in ['text', 'input_text', 'output_text']:
380+
if field in part:
381+
text = part[field]
382+
break
379383
if text and isinstance(text, str):
380384
text_parts.append(text)
381385
if text_parts:

0 commit comments

Comments
 (0)