<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def Uuid(to_uuid=True):
 """ Creates a UUID validator. Will raise an error for non-string types and non-UUID values. The given value will be converted to an instance of ``uuid.UUID`` unless ``to_uuid`` is ``False``. """

    @wraps(Uuid)
    def built(value):
        invalid = Error("Not a valid UUID")

        if isinstance(value, uuid.UUID):
            return value
        elif not isinstance(value, six.string_types):
            raise invalid

        try:
            as_uuid = uuid.UUID(value)
        except (ValueError, AttributeError) as e:
            raise invalid

        if to_uuid:
            return as_uuid
        return value
    return built