@@ -370,6 +370,9 @@ def _extract_text_from_input(input_data: Any) -> str:
370370 if isinstance (content , str ):
371371 return content
372372 elif isinstance (content , list ):
373+ if not content :
374+ # Empty content list returns empty string (consistent with no text parts found)
375+ return ""
373376 # Extract text from content parts
374377 text_parts = []
375378 for part in content :
@@ -385,6 +388,8 @@ def _extract_text_from_input(input_data: Any) -> str:
385388 text_parts .append (text )
386389 if text_parts :
387390 return " " .join (text_parts )
391+ # No text parts found, return empty string
392+ return ""
388393 # If content is something else, try to stringify it
389394 elif content is not None :
390395 return str (content )
@@ -452,8 +457,12 @@ class DefaultContext:
452457
453458 def _create_individual_guardrail (guardrail ):
454459 """Create a function for a single specific guardrail."""
455- async def single_guardrail (ctx : RunContextWrapper [None ], agent : Agent , input_data : str ) -> GuardrailFunctionOutput :
456- """Guardrail function for a specific guardrail check."""
460+ async def single_guardrail (ctx : RunContextWrapper [None ], agent : Agent , input_data : str | list ) -> GuardrailFunctionOutput :
461+ """Guardrail function for a specific guardrail check.
462+
463+ Note: input_data is typed as str in Agents SDK, but can actually be a list
464+ of message objects when conversation history is used. We handle both cases.
465+ """
457466 try :
458467 # Extract text from input_data (handle both string and conversation history formats)
459468 text_data = _extract_text_from_input (input_data )
0 commit comments