Based on the comments, it appears you are interested in a mechanism for preemptively declaring that your conduct is not wrongful without waiting for someone to bring charges or a lawsuit against you.
In most common-law jurisdictions, a litigant who learned that a prosecutor was preparing charges against him, or that someone else was preparing a lawsuit against him, would have the option of bringing an action for a declaratory judgment, which asks the court to examine the facts or the parties' relationship and actions to determine the legal consequences.
In New Zealand, for instance,
Declaratory judgments are available to make binding declarations of right
.... The effect of a declaratory order is to the same effect as the like declaration in a judgment in an action. It is binding on the person making the application and on all persons on whom the summons has been served, and on all other persons who would have been bound by the said declaration if the proceedings wherein the declaration is made had been an action.
The jurisdiction under the Declaratory Judgments Act enables anyone whose
conduct or rights depend on the effect or meaning of an instrument, including an agreement, to obtain an authoritative ruling.
Mandic and Dohnt v The Cornwall Park Trust Board (Inc)  NZSC 135 (11 November 2011)
The exact relief available through a declaratory judgment will vary from one jurisdiction to the next, but for illustration purposes, Party A might bring a declaratory-judgment action against Party B seeking a declaration that:
Party B is in breach of their contract, and that Party A is therefore free to stop performing;
Party B's patent/trademark/copyright is not valid, and that Party A is therefore free to copy without infringing;
Party A's proposed course of conduct is not a violation of governmental Party B's criminal or administrative laws.
Having obtained that judgment, Party A would be free to proceed, and a subsequent action by Party B would be barred as res judicata.
If what you're looking for is a mechanism to prevent a court from even allowing an opposing party to file the lawsuit or charges against you at all, there probably isn't any way to do that.