def is_valid_loss_function(loss_function):
    """
        Checks if a loss function is valid or not
    """
    # If the loss_function is None returning False
    if not loss_function:
        return False

    try:
        # Calling the get_loss_function method to details of the loss_function
        loss_function_details = loss_function.get_loss_function()

        # Checking the loss_function_details, it should return a dict
        if not isinstance(loss_function_details, dict):
            return False

        # Here im checking all the keys of object returned from the get_loss_function method
        loss_function_arguments = loss_function_details["keyword_arguments"]
        loss_function_function_ref = loss_function_details["loss_function"]

        # Checking the loss_function_arguments, it should return a dict or None
        if loss_function_arguments and not isinstance(loss_function_arguments, dict):
            return False

        # Checking the loss_function_function_ref
        if not loss_function_function_ref:
            return False

        # All good
        return True

    # Handling exception
    # pylint: disable=broad-except
    except Exception:
        return False