code: def _IsValidPath(message_descriptor, path):
    
    parts = path.split('.')
    last = parts.pop()
    for name in parts:
      field = message_descriptor.fields_by_name[name]
      if (field is None or
          field.label == FieldDescriptor.LABEL_REPEATED or
          field.type != FieldDescriptor.TYPE_MESSAGE):
        return False
      message_descriptor = field.message_type
    return last in message_descriptor.fields_by_name
docs: Checks whether the path is valid for Message Descriptor.