Processes vary greatly from country to country on this matter.
In the U.S., most courts (including the federal courts) cannot issue advisory opinions that are binding, subject to some narrow exceptions in fact patterns different from those you are envisioning.
But, if there is a "bona fide dispute" involving an actual case or controversy between two or more well defined parties, it is sometimes possible to get a declaratory judgment from a court regarding what a law means, or the meaning of contract.
For example, if you are in a position where you have no choice but to administer a law one way or the other in a particular upcoming case, you can usually ask a court for guidance.
Also, some administrative agencies can enter into binding agreements with citizens regarding how it will treat a particular activity (the comments give the example that is typical of the IRS issuing a private letter ruling to a taxpayer) in advance.
Sometimes an agency charged with enforcing a law (e.g. a prosecutor's office) can likewise make a binding interpretation of the law that people to whom the binding interpretation of it are legally entitled to rely upon.
Furthermore, even when these options are not available, something called an opinion letter from an attorney in the U.S., while not binding courts in later litigation, can mitigate the harm suffered from breaking the law because you will usually be found to have acted in good faith in interpreting the law even if you are wrong, and may shift some of the exposure to monetary harm from a misinterpretation of the law to the author of the opinion letter if you are a person whose reliance on the opinion letter is expressly intended by the author of the opinion letter.