@@ -145,11 +145,9 @@ def serialized_output(self) -> Dict[str, Any]:
145145 try :
146146 if self .context .output is None :
147147 return {}
148- if hasattr (self .context .output , "dict" ):
149- return self .context .output .dict ()
150- elif hasattr (self .context .output , "to_dict" ):
151- return self .context .output .to_dict ()
152- return dict (self .context .output )
148+
149+ return self ._serialize_object (self .context .output )
150+
153151 except Exception as e :
154152 raise LangGraphRuntimeError (
155153 "OUTPUT_SERIALIZATION_FAILED" ,
@@ -158,6 +156,31 @@ def serialized_output(self) -> Dict[str, Any]:
158156 UiPathErrorCategory .SYSTEM ,
159157 ) from e
160158
159+ def _serialize_object (self , obj ):
160+ """Recursively serializes an object and all its nested components."""
161+ # Handle Pydantic models
162+ if hasattr (obj , "dict" ):
163+ return self ._serialize_object (obj .dict ())
164+ elif hasattr (obj , "model_dump" ):
165+ return self ._serialize_object (obj .model_dump (by_alias = True ))
166+ elif hasattr (obj , "to_dict" ):
167+ return self ._serialize_object (obj .to_dict ())
168+ # Handle dictionaries
169+ elif isinstance (obj , dict ):
170+ return {k : self ._serialize_object (v ) for k , v in obj .items ()}
171+ # Handle lists
172+ elif isinstance (obj , list ):
173+ return [self ._serialize_object (item ) for item in obj ]
174+ # Handle other iterable objects (convert to dict first)
175+ elif hasattr (obj , "__iter__" ) and not isinstance (obj , (str , bytes )):
176+ try :
177+ return self ._serialize_object (dict (obj ))
178+ except (TypeError , ValueError ):
179+ return obj
180+ # Return primitive types as is
181+ else :
182+ return obj
183+
161184 async def process (self ) -> UiPathRuntimeResult :
162185 """
163186 Process the output and prepare the final execution result.
0 commit comments