I have a good book the title of which will surely come back to me any time now... (It's at home.)
Generally, the idea is to only lock someone up if there is no alternative whatsoever and the risk is deemed real.
For the rest, use rehabilitation, restaurative approaches, mental health care, house arrest, community service... There are options! The current system just tortures people to produce more criminals.