This is a type of risk that is hard to hedge, the risk that the government will arrest you on false claims and take away your freedom. I've been thinking more how to minimize this because what is at stake is so high. There are some principles that seem to be important
-Always pledge the 5th(AKA keep your mouth shut to authorities unless its truly necessary to say something)
-When dealing with cops, judges, investigators and other authorities never get angry even if you know they are behaving illegally and are abusing power, always be polite but not weak. Swallow your pride and keep your ego out of this, its better to stand some temporary power abuse rather than have coke planted in your bag and wake up with a 20 year sentence(Or a few additional years in a sentence because the judge didnt 'like you'). I understand some people with more rebelling mindsets might have a problem with this(Heck I do) but its mathematically the right play
-Don't try to save money by hiring a cheap lawyer(This is like selling overpriced options, little gains that lead to disaster one day)
-Learn about law. This one I haven't done yet but I will buy some books on Brazilian law, mainly so I can understand how to judge a lawyer when I need one
There might be other ways but those are from the top off my head