(a) The prosecutor's name shall be endorsed on every indictment, and he shall be compelled to pay all costs and jail fees upon the acquittal or discharge of the person accused when:
(1) The grand jury, by its foreman, on returning "no bill," expresses as its opinion that the prosecution was unfounded or malicious;
(2) A jury on the trial of the prosecution finds it to be malicious; or
(3) The prosecution is abandoned before trial. When it is thus abandoned, the officer who issued the warrant shall enter a judgment against the prosecutor for all the costs and enforce it by an execution in the name of the state or by an attachment for contempt.
(b) A magistrate may, in his discretion, assess costs and jail fees against the person who instigated the prosecution when, at a committal hearing, the action is dismissed for want of probable cause and the magistrate finds that the complaint was unfounded and malicious. This subsection shall not apply to law enforcement personnel.