<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def validate_safe_string(value):
 """Ensure the provided string does not have illegal characters."""

    # The following strings are explicitly allowed, despite having otherwise-illegal chars.
    legal_strings_with_special_chars = frozenset({'@rid', '@class', '@this', '%'})

    if not isinstance(value, six.string_types):
        raise TypeError(u'Expected string value, got: {} {}'.format(
            type(value).__name__, value))

    if not value:
        raise GraphQLCompilationError(u'Empty strings are not allowed!')

    if value[0] in string.digits:
        raise GraphQLCompilationError(u'String values cannot start with a digit: {}'.format(value))

    if not set(value).issubset(VARIABLE_ALLOWED_CHARS) and \
            value not in legal_strings_with_special_chars:
        raise GraphQLCompilationError(u'Encountered illegal characters in string: {}'.format(value))