def _build_callable_validator(function):
    """Build a validator that checks the return value of function(data)."""

    def callable_validator(data):
        """Validate by checking the return value of function(data)."""
        try:
            if function(data):
                return data

        except (TypeError, ValueError, NotValid) as ex:
            raise NotValid(ex.args)

        raise NotValid("%r invalidated by '%s'" % (data, _get_repr(function)))

    return callable_validator