It is a rarity for visitors to encounter problems with safety in San Francisco but as with many other major cities in the U.S. it’s advised to be cautious and aware of one's surroundings.
Southeast San Francisco is known to be the area affiliated with crime and gang violence so visitors are advised to be careful when out and about in the southeast neighbourhoods such as Excelsior, Potrero Hill, Sunnydale and Ingleside.
As with many busy major cities petty crime such as pickpocketing does occur so belongings should be kept within close proximity, especially in crowded areas.
Homelessness is a major issue in San Francisco. The city has one of the largest homelessness rates in the U.S., primarily due to the lack of affordable housing. Nearby Union Square and the Tenderloin neighbourhood are safe and filled with people up until around 2AM, after which it is advised to avoid walking alone due to homelessness related crimes.
San Francisco is generally a lively, vibrant and respectful city so once one stays safe it’s extremely rare to encounter any problems.