I have stayed in the Union Square area of San Francisco many times over many years. At midnight and later the "Street People" are particularly dangerous. SFO is a very tough city for non-locals. Do not take unnecessary risks. At the very least, call the hotel Concierge in advance and get advice. My opinion...at the time of night you are mentioning...take a taxi from airport and cut corners somewhere else.