In any case in which the court or magistrate grants the prosecuting attorney's motion for a reduction of charges or dismissal of counts because there would be no substantial change in sentence, the court or magistrate shall require the prosecuting attorney to put on the record in open court the following:
Before the court can accept the plea agreement, the prosecuting attorney shall present a written declaration to the court, specifying the legal and factual reasons for the agreement, and the court shall acknowledge in writing its acceptance of that declaration. A copy of the declaration and acceptance shall be retained in the case file.
Ca. Pen. Code § 999f