def is_valid_unicode(text):
  """Check if a string is valid unicode. Did we slice on an invalid boundary?"""
  try:
    text.decode("utf-8")
    return True
  except UnicodeDecodeError:
    return False
Check if a string is valid unicode. Did we slice on an invalid boundary?
language/canine/tydiqa/debug.py