code: def geometry_checker(geometry):
      
      if geometry is None:
          # The geometry can be None.
          return False, None
  
      if geometry.isGeosValid():
          return True, geometry
      else:
          new_geom = geometry.makeValid()
          if new_geom.isGeosValid():
              return False, new_geom
          else:
              # Make valid was not enough, the feature will be deleted.
              return False, None
docs: Perform a cleaning if the geometry is not valid.
  
      :param geometry: The geometry to check and clean.
      :type geometry: QgsGeometry
  
      :return: Tuple of bool and cleaned geometry. True if the geometry is
          already valid, False if the geometry was not valid.
          A cleaned geometry, or None if the geometry could not be repaired
      :rtype: (bool, QgsGeometry)