That is a good question and really subjective to opinion. The only true way to answer that is to contact the local police stations for their official crime statistics or use apps like Trulia's crime map:
I have lived in the Richmond District and found it to be incredible quiet and safe. I am originally from NY, however, so all SF neighborhoods seem safe to me.
http://www.sf-police.org/index.aspx?page=1618 (you must "agree" to the terms before going to the map).
If you are thinking of moving to one of these two neighborhoods, since their safety is similar, I'd consider other factors such as schools, walkability, parking, shops and restaurants, public transportation, and commute times (of course this all depends on your personal needs). Ultimately, between these two locations, it's all going to come down to what makes you feel most at home.
Let me know if you'd like to discuss this further!
Downing & Co Real Estate Services
The short answer is that parts of the richmond will be safer than parts of the sunset and vice versa. San Francisco is very much a block by block city. The best thing you can do is to look at the SFPD crime mapping site using a particular address, and then talk with the local precinct for background and context.
Here is the url for the site:
If you want some input about a particular area of either neighborhood, contact info is below:
Lance King/Owner-Managing Broker
King Realty Group