Courts have always recognized the special role of prosecutors in the criminal justice system. In a 1935 case, for instance, the U.S. Supreme Court described the prosecutor as "the servant of the law, the twofold aim of which is that guilt shall not escape or innocence suffer." Other courts have made similar comments, even remarking that prosecutors, as representatives of an impartial government, are held to a higher standard than other attorneys. (Berger v. United States, 295 U.S. 78 (1935); see People v. Hill, 17 Cal. 4th 800 (overruled on other grounds).)
The heightened ethical standard for prosecutors is nowhere more relevant than at the charging stage of a criminal case. A criminal record can be devastating. But even the filing of charges that don't result in conviction can have a tremendous impact on the defendant's life. (Courts often use words like "embarrassment," "ordeal," and "expense" when describing criminal prosecution.)
It's common for rules to set at least broad standards for when prosecutors should—and should not—pursue cases. For example, the California Rules of Professional Conduct require that prosecutors not file charges when they know or should know that there isn't probable cause to support the charges. The relevant rule also demands that the attorney responsible for prosecuting the case notify the court soon after becoming aware that there really isn't probable cause. (Cal. Rules Prof. Conduct, Rule 5-110 (2016).)
Despite the ethical requirements for government attorneys and the seriousness of criminal prosecution, prosecutors tend to have a lot of latitude regarding charging decisions. That a crime occurred typically doesn't mean that the prosecution has to file charges. Similarly, courts normally don't second-guess the decision to prosecute even if the decision was questionable.
Prosecutors also have a good deal of elbow room when it comes to decisions about which charges to file and the severity of the sentence to seek. The charging attorney gets to consider factors like:
For example, a prosecutor who thinks a jury could convict a defendant of grand theft might choose to charge only joyriding. On the flip side, it's not uncommon for the prosecution to charge a defendant with a serious offense, then use that charge as leverage to get the defendant to plead guilty to a lesser crime. A district attorney might, for instance, charge grand theft with the goal of getting the defendant to plead to joyriding.
If you want to know the rules in your jurisdiction and how the law applies to your situation, make sure to consult an experienced criminal defense attorney. A knowledgeable lawyer will be able to advise you about the relevant procedure and your options.