Upon a plea of guilty before a committing magistrate as provided in Section 859a, to a crime or attempted crime divided into degrees, when consented to by the prosecuting attorney in open court and approved by such magistrate, such plea may specify the degree thereof and in such event, the defendant cannot be punished for a higher degree of the crime or attempted crime than the degree specified.
Ca. Pen. Code § 1192.2