You can steer clear of a lot of the bad elements of SF, except the homeless. Homeless people are pretty easy to explain to young kids. The ballpark is pretty easy to get to and avoids lots of the negative elements of the city.
Castro is pretty easy to avoid. I’ve only been there a few times, and that was on purpose just to see what it was like. It’s been decades since I’ve driven through that area.
I don’t know why a school would take a school group through the Castro district.
I guess there is something about that name CASTRO, that American liberals just love, period!
Seeing that the only reason I would have for being in SF at all would be to attend a SF Giant’s or SF 49er game, I have no problems avoiding the rest of that cesspool.