In a sensible criminal system the prosecutor, just like the judge is there to ensure justice. It's an asymmetric system, the defence represent an individual but everybody else represents society's interest in justice.
In England for example the prosecutors work for the Crown and make their decision based on the "Full Code Test" which says they shouldn't prosecute unless a bunch of constraints are true, including:
They are convinced the subject is guilty They expect to secure a conviction at trial, meaning they can prove the accusation to the satisfaction of judge and where appropriate jury. The prosecution serves a legitimate public interest The subject hasn't already suffered equivalent or greater consequences for their actions than could be inflicted as punishment for the crime.