delivered a concurring opinion.
This case demonstrates the wisdom of a rule that all immunity agreements must be in writing, signed by the defendant, his counsel, the prosecutor, and the trial judge. Indeed, the Legislature might consider enacting a statute outlining the procedures regulating the grant of transactional or use immunity. That said, I concur with the result reached by the majority in this particular instance, although I disagree with some of the reasoning. I conclude that, under these special circumstances, a defendant should not be made to suffer the disastrous consequences of a district attorney’s inadvertent failure to inform the trial judge and to obtain his consent to what both original contracting parties agreed was a valid immunity agreement.
I.
The testimony taken during appellant’s pretrial hearing on his Motion to Enforce Agreement with Prosecutor shows that, in 1990, appellant, along with five co-defendants, was indicted for the capital murder of Hilton Raymond Merriman. Early in his investigation of the burglary-murder, the Randall County District Attorney decided that he might need the cooperation and testimony of one of the defendants to prosecute the cases successfully.
Appellant’s attorney and the district attorney, as well as an assistant district attorney, began lengthy negotiations concerning a possible immunity agreement with appellant. After almost two years, these negotiations culminated in an oral immunity agreement1 and dismissal of the pending indictment against appellant. Appellant’s attorney testified to the basic terms of the agreement: Appellant would *857give a full interview to the district attorney’s office, answer any questions the prosecutors might have, and “if they determined that [appellant’s] answers were truthful and if he would agree to testify against any of the other Defendant’s [sic] in the cases arising out of Mr. Merriman’s death, that they would dismiss the case against him and would not seek to prosecute him on any further cases out of, and resulting from, the death of Mr. Merri-man.” The former district attorney and the prosecutor who dealt most with appellant during the de-briefing period both testified at the hearing and they confirmed that this was the essence of their agreement.
The appellant gave a full, videotaped interview to the primary prosecutor, in which he waived his Fifth Amendment right not to incriminate himself, even though he was then under indictment for capital murder. The primary prosecutor testified that he kept the videotape and continued to investigate to confirm or contradict the facts as stated by appellant. This confirmatory process took about ten months, at which point the prosecutor was satisfied that appellant had told the truth “as we could discern it,” and the State had successfully tried one of the co-defendants for capital murder. Although appellant, as promised, kept himself available as a witness for his co-defendants’ trials, the State did not request his testimony.
The district attorney and the primary prosecutor then agreed to dismiss the pending capital murder charges against appellant. It was their understanding that this dismissal would end any possible charges against appellant for his involvement in the Merriman burglary and murder.2 The district attorney explicitly testified that he eventually agreed to the dismissal because appellant “had complied with all the terms of the agreement I had with” appellant’s attorney. The district attorney made that decision after consulting with the primary prosecutor and the investigators, and determining that appellant’s statement was consistent with “every piece of evidence” and lead that had been investigated. It was the district attorney’s understanding that, with the dismissal of the charges, “[t]here was no question that [appellant’s attorney] understood that if [appellant] was willing to do this [i.e., give the videotaped statement, cooperate with the prosecution, and testify if requested at the co-defendants’ trials], and we had entered into that agreement, that no charges would be brought up again.”
The district attorney told appellant’s attorney to draft a dismissal motion. Appellant’s attorney did so. That dismissal mo*858tion, however, as drafted by appellant’s attorney, said nothing about any immunity agreement. It merely recited that the charges were being dismissed “in the interests of justice and based upon the evidence.” The trial court signed the dismissal motion. According to the district attorney, “I felt like the agreement was complete.... And once I signed the dismissal it was a done deal as far as I was concerned.”
Approximately two years later a new district attorney reopened the investigation, apparently having decided that appellant had not been completely truthful in his videotaped statement and cooperation with the former prosecutors.3 He found evidence that he said contradicted appellant’s statement concerning his lack of involvement in the offense.4 Therefore, he filed murder charges against appellant. After the trial court denied appellant’s Motion to Enforce Agreement with the Prosecutor, the case went to trial. Appellant was convicted of murder and sentenced to ten years in prison, probated, and a $10,000 fíne.
Appellant appealed, complaining that the trial court erred in refusing to enforce the immunity agreement. The court of appeals affirmed the conviction, holding that, as a matter of law, there was no binding immunity agreement because the trial court did not know or approve of it. Smith v. State, 979 S.W.2d 379 (Tex.App.—Amarillo 1998). This Court granted review to decide whether an immunity agreement may be valid even if: 1) the dismissal order does not explicitly state that the indictment is dismissed “with prejudice”; or 2) the trial court is not aware of the specific terms of the agreement at the time he signs the dismissal order.5
II.
Appellant has been tried and convicted of murder for want of a written record of *859the immunity agreement,6 one duly signed by the district judge, that he and the former district attorney both agreed they made. The majority concludes that “it is the prosecutor who initiates a dismissal and sets the reasons for the dismissal, [thus] it is the prosecutor who is responsible for crafting the conditions of an immunity agreement.” I agree wholeheartedly with this proposition. I respectfully disagree, however, with the subsequent proposition that “[pjrovided the judge approves the dismissal that results from an immunity agreement, the judge does not have to be aware of the specific terms of a fulfilled immunity agreement for it to be enforceable.” This conclusion eviscerates the very rationale for requiring judicial knowledge and approval of immunity agreements.
Instead, I would conclude that in this particular (and highly unusual) case the State is now estopped from complaining that the immunity agreement to which it had agreed was invalid and unenforceable because it had failed to memorialize it and obtain the trial court’s consent. I do not suggest that either the former or present district attorney were derelict in their duties, lacking in good faith, or acting less than honorably. Nonetheless, appellant is surely not at fault, and he ought not bear the severe consequences of the innocent mistakes of the State’s representatives.
Like the dissent, I believe that a bright-line rule — the court must approve the immunity agreement — is the right rule. The exchange of rights represented by immunity agreements is a serious matter, one which is best served by obtaining the trial court’s written approval on the record. The written record, being immutable and accessible, protects those like appellant, and saves them from subsequent trials, hearings, and appeals simply to return to that place the written record should have shown they were in the first place: immunity ticket in pocket in return for the relinquishment of their valued Fifth Amendment right against self-incrimination.
III.
The Supreme Court has stated that: “[a]mong the necessary and most important of the powers of the States as well as the Federal Government to assure the effective functioning of government in an ordered society is the broad power to compel residents to testify in court or before grand juries or agencies.”7 This “power to compel testimony, and the corresponding duty to testify,” are embedded in the Sixth Amendment.8 “But the power to compel is not absolute,” and is subject to “the Fifth Amendment privilege against compulsory self-incrimination.”9
When these two rights — society’s need for a witness’ testimony and that witness’ right not to incriminate himself — collide, the immunity doctrine comes to the rescue.10 The government may compel the *860witness to testify, but in return for his testimony, the State must offer immunity from prosecution or from any use of that evidence.11
Initially, Congress, the courts, and the states flip-flopped as to just what kind of immunity was required to substitute for the right against self-incrimination. Witnesses were alternatively granted the narrow “testimonial” immunity (immunity from in-court use of compelled testimony in subsequent criminal prosecution); the broad “transactional” immunity (immunity from prosecution for offenses to which compelled testimony relates); or the middle-of-the-road “use and derivative use” immunity (immunity from the use of the compelled testimony and any evidence derived therefrom). Under the federal constitution, a witness is entitled to at least “use and derivative use” immunity.12
In some jurisdictions, such as Texas, the trial court must endorse prosecutorial grants of immunity. The requirement that the trial court be involved may be made explicit by statute13 or, as in Texas, by case law.14 This requirement serves several valuable purposes. It memorializes the existence and terms of any immunity agreement. It ensures that a legally enforceable agreement is set out, not only for the bénefít of the contracting parties, but for any court, other prosecutorial agency,15 and other defendants or prospective defen*861dants. It ensures that the parties may measure performance against the explicit terms of the agreement. Most importantly for purposes of this appeal, it avoids later disputes over the existence and terms of the agreement when some of the parties change.
The trial court’s role is very limited in this context. Immunity, after all, is the coin the government must pay to obtain the waiver of a person’s right against self-incrimination and the information that he has about some crime. Thus, only the government can decide how much information it wants to “buy” and how much it is willing to pay for it in terms of either “use” or “transactional” immunity. The trial court’s function is largely ministerial.16 It simply memorializes the exchange in which a defendant or prospective defendant gives up his Fifth Amendment right in return for immunity. Ideally, the trial judge should approve the immunity agreement before, and not after, the defendant speaks. The dismissal of charges or filing of the nolle prosequi is simply the final event in a transactional immunity agreement, the acknowledgment that both parties have fulfilled their obligations under the agreement. There is no required litany language for the dismissal form itself, and it need not contain the phrase “with prejudice,” although there may be much benefit to its inclusion.
It is true that occasionally equity will enforce a promise not to prosecute which was made without the trial court’s knowledge and approval.17 In those cases, it is the simple notion of fairness — that a witness, having performed on his side, is entitled to specific performance from the prosecutor — that is appealed to.18 Principles of fairness and public policy have also been *862used to enforce such a promise made by a district attorney on that district attorney’s successor.19 Nevertheless, the general rule in Texas is that the courts must approve any formal grant of immunity. The reason behind the general rule was well stated by Judge Cardozo as he addressed a witness’ refusal to testify despite the grant of a non-statutorily authorized promise of immunity:
The witness is within his privilege in insisting that the basis for his immunity shall be something more substantial than the grace or favor of the prosecutor who may bring him to the bar of justice .... To uphold a finding that his [the witness’] conduct amounted to a contempt it must appear that in refusing to answer he was violating a legal, and not merely a moral obligation. The immunity like the obligation must have its source and sanction in the law. An “equitable right to * * * clemency” — a mere “gesture” of benevolence — is not a substitute for protection against indictment and conviction.20
Thus, by design, requiring the trial court to approve an immunity agreement pro*863tects the prospective witness’ Fifth Amendment rights. He cannot be compelled to testify against himself unless the trial court has ordered him to speak under a grant of immunity. Then he cannot refuse.
It seems illogical that a rule intended to protect a defendant’s right against self-incrimination may then be used by the State as a sword against him. I would conclude that, in this particular case, the State is estopped from claiming that the immunity agreement that its representative, the then District Attorney of Randall County, entered into with appellant cannot be a valid immunity agreement because that district attorney failed to obtain the trial court’s knowledgeable approval of the agreement.21 It was the prosecution’s responsibility to obtain the trial court’s consent for its immunity agreement, and the defendant should not now be forced to bear the burden of the State’s inadvertent failure to follow the required procedure.
I cannot join the majority opinion, although I agree with most of its reasoning. I believe that the majority’s ultimate conclusion, that, if there is a dismissal, a trial court need not be aware of an immunity agreement’s existence or content, will only lead to further confusion in this area of the law. Therefore, I concur in the court’s judgment.
. Appellant’s attorney testified that he had dealt with this district attorney for twenty years and that neither required the other to reduce agreements to writing. Although "handshake” agreements show commendable trust by the contracting parties, they are ill-advised in the context of legally binding immunity agreements.
. The primary prosecutor testified that, with the dismissal of the charges, "I thought it was completely over for Sean Smith as far as anything to do with the Merriman homicide or burglary.... [TJhere has to be an end to cases. And, in my opinion, once the case was dismissed, that was the final conclusion that the truth had been told, we had investigated as much as we could and that the case was over.” When asked whether the oral immunity agreement was the equivalent of a contract, the prosecutor responded: "I think it has contractual aspects, and maybe, even a little bit above that. I think that a government official, when they give their word about what they will do, they’re bound by that word.” The district attorney testified similarly, stating "because at some point you have to have a closure, and sometimes you make decisions .... I mean we struggled with this for months to be sure we ran every possible lead down. But when the defense attorney makes a deal with you at some point where you need his [a defendant’s] testimony, because you later don’t need it, you can’t back up on the deal. I don’t know about anybody else; I can’t. You — there was no doubt in my mind or [appellant’s attorney’s] mind; once I signed that agreement [dismissal motion], it was over with.”
. The trial judge, concentrating upon the sole issue of whether a legally enforceable immunity agreement had ever existed, declined to allow the new district attorney to offer evidence on the issue of whether appellant had broken an otherwise valid immunity agreement.
. At the hearing, the position of the new district attorney was not so much that appellant never had an immunity agreement, but that he had broken that agreement by giving a statement that was false. His not unreasonable position was that:
If the Defendant breached the contract, then the contract is broken. And again, we are prepared to present, in spite of the incredible evidence heard in this hearing, that the Defendant lied with impunity throughout the video tape. That he was active, voluntarily participating....
To suggest that the Defendant can bind the State to a promise, but breach his end of the agreement and lie with impunity, is to send a message to every defendant in this state and I guess in the world, that the key to success in criminal endeavors, is simply to make the prosecutor believe a lie, and then you are home free. There is nothing they can do to you.
.This Court granted review of the following questions:
1) If a Defendant and the State enter into an agreement that an indictment returned against the Defendant will be dismissed with prejudice, and if the Defendant upholds his end of the bargain, can a subsequent indictment charging the same transaction be brought against the Defendant solely because the order of dismissal signed by the Court did not state the dismissal was with prejudice?
2) If a Defendant and the State enter into an agreement that an indictment returned against the Defendant will be dismissed with prejudice, and if the Defendant upholds his end of the bargain, can a subsequent indictment charging the same transaction be brought against the Defendant solely because the Court was not aware of the specific terms of the agreement not to prosecute?
. One is reminded of the Mother Goose rhyme, "For want of a nail ... the kingdom was lost,” in which the consequences were even more severe for want of a much more mundane item.
. Murphy v. Waterfront Comm’n, 378 U.S. 52, 93-94, 84 S.Ct. 1594, 12 L.Ed.2d 678 (1964) (Justice White, concurring).
. Kastigar v. United States, 406 U.S. 441, 444-45, 92 S.Ct. 1653, 32 L.Ed.2d 212 (1972).
. Id. at 444, 92 S.Ct. 1653.
. The first federal statute provided immunity to anyone testifying before either house of Congress for any fact or act upon which his testimony touched. See 11 Stat. 155-156 (1857). Much earlier, however, state immu*860nity statutes were employed to prosecute consensual crimes that are otherwise difficult to detect without the testimony of persons involved in the crimes, such as gambling, bribery, dueling, and usury. Witt, Making the Fifth: The Constitutionalization of American Self-Incrimination Doctrine, 1791-1903, 77 Tex. L.Rev. 825, 846 (1999).
. Murphy, 378 U.S. at 79, 84 S.Ct. 1594.
. In 1892, the Supreme Court struck down a federal testimonial immunity statute as failing to provide immunity as broad as the Self Incrimination Clause required and ruled that the Fifth Amendment required “transactional” immunity. Counselman v. Hitchcock, 142 U.S. 547, 586, 12 S.Ct. 195, 35 L.Ed. 1110 (1892). That constitutional rule lasted until 1972, when the Supreme Court held that the newly enacted federal immunity statute, 18 U.S.C. §§ 6002, which required the in-between "use and derivative use" or "use plus use-fruits" immunity, satisfied the Fifth Amendment. Kastigar, 406 U.S. at 453, 92 S.Ct. 1653. Such immunity from use and derivative use is "coextensive with the privilege" and suffices to supplant it. This Court has agreed. See Ex Parte Shorthouse, 640 S.W.2d 924 (Tex.Crim.App.1982) (rejecting assertion that only absolute, complete, full or transactional immunity is permissible under Texas law; concluding that testimonial or use and derivative use immunity is constitutional); State v. Boyd, 38 S.W.3d 155 (Tex.Crim.App.2001). The privilege and immunity are like two coins with the same value, only one of which the witness may keep. Transactional immunity may still be granted, but it is not required by the United States Constitution. It is, in essence, an additional coin.
. See e.g., 18 U.S.C. §§ 6002-6003.
. See e.g., Bowden v. State, 1 Tex.App. 137 (1876); Vincent v. State, 55 S.W. 819, 820 (Tex.Crim.App.1900); Ex parte Gibson, 42 Tex.Crim. 653, 62 S.W. 755 (1901); Reagan v. State, 49 Tex.Crim. 443, 93 S.W. 733 (1906); Ex parte Higgins, 71 Tex.Crim. 618, 160 S.W. 696 (1913); Dollar v. State, 92 Tex.Crim. 254, 242 S.W. 733 (1922); Washburn v. State, 164 Tex.Crim. 448, 299 S.W.2d 706 (1956); Zani v. State, 701 S.W.2d 249 (Tex.Crim.App.1985); Graham v. State, 994 S.W.2d 651 (Tex.Crim.App.1999).
. Once the immunity agreement is consummated, all other prosecutorial entities — in Texas, the federal system, and other states— must abide by it, at least to the extent of use immunity. In Murphy v. Waterfront Comm’n, 378 U.S. 52, 79, 84 S.Ct. 1594, 12 L.Ed.2d 678 (1964), the Supreme Court explained why that rule — that state and federal witnesses, compelled to testify in the face of the assertion of a privilege, must be granted both state and federal immunity — is necessary. Most, if not all of the policies and purposes of the constitutional privilege against self-incrimina*861tion are defeated if a witness can be "whipsawed” into incriminating himself under both state and federal law but only one of them provides the witness immunity while the other is free to prosecute based upon his immunized testimony. Id. at 55-56, 84 S.Ct. 1594.
. See United States v. Leyva, 513 F.2d 774, 776 (5th Cir.1975); In Re Grand Jury Investigation, 486 F.2d 1013, 1016 (3rd Cir.1973); In Re Perlin, 589 F.2d 260, 269 (7th Cir.1978). As the Ninth Circuit explained in Urasaki v. United States Dist. Court, Cent. Dist., 504 F.2d 513, 514 (9th Cir.1974):
In passing upon an immunity application, the [federal district] court is confined to an examination of the application and the documents accompanying it for the purpose only of deciding whether or not the application meets the procedural and substantive requirements of the authorizing statute.
The question before the trial court is not the wisdom of the agreement, but the clarity and completeness of its terms.
. See Robert M. Schoenhaus, Annotation, Prosecutor’s Power to Grant Prosecution Witness Immunity Prom Prosecution, 4 A.L.R.4th 1221 (1981) (noting the differences between "some jurisdictions — Texas particularly— which require the full participation of the courts before a grant of immunity will be deemed valid, and have denied legitimacy to the grants of immunity made by prosecutors acting without the courts’ cooperation,” and jurisdictions like California, "where equity has, in many circumstances, carried over to situations in which a prosecutor has acted without the court’s knowledge or approval to secure testimony under the promised protection of immunity from prosecution.”).
. See e.g., Hardin v. State, 12 Tex.App. 186, 189 (1882):
If the State, through her officers, makes a solemn compact with her citizen, this contract should be enforced in the courts, in exact compliance with its terms. The agreement or contract (the defendant complying faithfully with his part) is in effect that the defendant should not be prosecuted. Upon what principle of justice is he driven from the court to his excellency the governor for an enforcement of this compact? We are of the opinion that common honesty and public justice demand that when such a contract is made and the party faithfully complies, as far as is within his *862power, the court in which the breach is attempted should interpose and prevent the breach by enforcing the contract, and should not drive the party out of the court to seek relief elsewhere.
See also Carlisle v. State, 138 Tex.Crim. 530, 137 S.W.2d 782 (1940) (holding that when district attorney promises use immunity to an accused in exchange for his testimony against a co-defendant, such an agreement is enforceable without regard to the general rule that no immunity may be extended without the approval of the court; when the prosecution makes a promise of immunity, it is obliged to respect the agreement); Camron v. State, 32 Tex.Crim. 180, 182, 22 S.W. 682, 682 (1893) (“If the State can make a contract with the defendant for immunity from prosecution for his offense, it is due to her own dignity that the contract be carried out in perfect faith” even though trial court had not approved agreement).
. See State v. Hanson, 249 Ga. 739, 295 S.E.2d 297 (1982). The facts in Hanson are similar to those here. Hanson was arrested for possession and sale of methaqualone. In exchange for furnishing information concerning drug and gambling investigations, the district attorney gave Hanson a letter in which he purported to grant immunity from prosecution. The judge signed a postscript to the letter which noted that the letter had been called to his attention. At the same time, the district attorney dismissed the charges pending against Hanson. Although the dismissal was noted on the file, the notation gave no reason for the dismissal. The district attorney was later defeated in his bid for re-election, and the new district attorney re-indicted Hanson for possession and sale of methaqual-one. Hanson’s attorney filed a motion to quash the indictment, relying upon the letter from the former district attorney. There was no copy of this letter in the case file. The trial court denied the motion, and the Court of Appeals reversed, holding that the promises of the public prosecutor and the public faith pledged by him must be kept. Id. at 299. The Georgia Supreme Court affirmed, finding that the original promise was enforceable and binding on the district attorney’s successor because ”[t]he integrity of the office of the district attorney demands that promises made by the district attorney are binding on his successor to the extent that they are valid and enforceable.” Id. at 302.
. Doyle v. Hofstader, 257 N.Y. 244, 265-66, 177 N.E. 489, 497 (1931). Doyle was subpoenaed to a legislative committee investigating various New York City departments because "[tjhere had been preliminary testimony from the lips of other witnesses that fees of extraordinary magnitude had been paid for his services [at the Board of Standards and Appeals] during a period of years.” Id. at 249, 177 N.E. at 490. Doyle refused to answer questions concerning whether he had divided these fees with anyone else, in furtherance of a concerted plan of bribery and corruption, and whether he had paid any part of them as a bribe to any public officer. Id. Chief Justice Cardozo concluded that Doyle could not be compelled to answer potentially self-incriminatory questions without formal immunity or legislative amnesty.
. It is a well-settled principle of law that a party cannot invite error and then complain of it. Ex parte Guerrero, 521 S.W.2d 613, 614 (Tex.Crim.App.1975). The rule applies when the party is the "moving factor” creating the error. Id. See also Capistran v. State, 759 S.W.2d 121, 124 (Tex.Crim.App.1982) (when a party invites error, he can not later complain of or attempt to gain an advantage based upon that error). Although the "invited error” doctrine is usually applied against the defendant, there is no logical or legal reason why the same doctrine ought not apply to the State in an appropriate circumstance. See, e.g., State v. Manning, 833 S.W.2d 322, 323 (Tex.App.—Waco 1992, no pet.) (State could not complain on appeal about dismissal that it invited by making motion to dismiss). It is true, as Justice Holmes stated, that "[m]en must turn square comers when they deal with the Government.” Rock Island, A. & L. R. Co. v. United States, 254 U.S. 141, 143, 41 S.Ct. 55, 65 L.Ed. 188 (1920). But, as Justice Jackson noted, "there is no reason why the square corners should constitute a one-way street.” Federal Crop. Ins. Corp. v. Merrill, 332 U.S. 380, 387-88, 68 S.Ct. 1, 92 L.Ed. 10 (1947) (Jackson, J., dissenting). Here, when the original district attorney told appellant's attorney to draft the dismissal motion when it was the prosecutor’s duty to memorialize the immunity agreement and obtain the consent of the trial court, he unintentionally invited the error that occurred.