@@ -481,6 +481,27 @@ def _get_input_ids_loss_mask(
481481 return input_ids , loss_mask
482482
483483
484+ def _parse_conv_tools (conv_tools : object , idx : int ) -> list | None :
485+ """Parse the tools JSON string for one conversation; warn and return None
486+ on invalid JSON or unexpected types."""
487+ if not conv_tools :
488+ return None
489+ if not isinstance (conv_tools , str ):
490+ log .warning (
491+ f"Non-string value in tools column for conversation { idx } : "
492+ f"{ type (conv_tools ).__name__ } , proceeding without tools"
493+ )
494+ return None
495+ try :
496+ return json .loads (conv_tools )
497+ except json .JSONDecodeError as e :
498+ log .warning (
499+ f"Invalid JSON in tools column for conversation { idx } : { e } , "
500+ "proceeding without tools"
501+ )
502+ return None
503+
504+
484505def _preprocess_batch (
485506 examples : dict ,
486507 processor : ProcessorLike ,
@@ -521,22 +542,7 @@ def _preprocess_batch(
521542 if not normalized_conv :
522543 continue
523544
524- # Parse tools JSON string if present; warn and skip tools on invalid JSON
525- parsed_tools = None
526- if conv_tools :
527- if isinstance (conv_tools , str ):
528- try :
529- parsed_tools = json .loads (conv_tools )
530- except json .JSONDecodeError as e :
531- log .warning (
532- f"Invalid JSON in tools column for conversation { idx } : { e } , "
533- "proceeding without tools"
534- )
535- else :
536- log .warning (
537- f"Non-string value in tools column for conversation { idx } : "
538- f"{ type (conv_tools ).__name__ } , proceeding without tools"
539- )
545+ parsed_tools = _parse_conv_tools (conv_tools , idx )
540546
541547 try :
542548 input_ids , loss_mask = _get_input_ids_loss_mask (
0 commit comments