Which part? Understanding how they should follow the law in the real world and the responsibility that brings? They could be wrong or right in any situation (they aren't lawyers and the world doesn't conform to laws) and they should be aware of that.
If the law says by possessing marijuana you are a dealer, but a cop finds someone with a small amount, it's likely for recreation and their possession brings no harm to society or others (what the law wants to prevent). Arresting them may be following the letter of the law, but not the intent (to stop distribution).
Another invented situation: cop pulls over someone driving erratically and too fast, then the driver is a woman who escaped being raped by her date. She was driving erratically because she was emotionally and physically distraught. Is giving her a ticket helping anyone? The cop could say "okay, take it easy and slow while I follow you to make sure you're out of danger and feel safe getting home".
Sorry I can't be more specific, I haven't gotten years of training on such situations.
In both cases, depending on the laws in your country, you can later object the ticket or the arrest. In an ideal world both cases wouldn't be a negative, but an inconvenience at most or even helpful contact with the law and police.
Demanding cops to make decisions on the spot is a situation you want to have less of. The more wiggle room police officers have in regards of construing the law, the more you have a mixture of forces that should be as independent from each other as possible. Otherwise you loose the power to challenge these decisions!
A police officer can have an opinion on laws, but they should never act on these opinions. This is necessary to protect themselves and all other people as well.
You demand them to be some kind of superhero, but these are just regular people. They have opinions and good and bad days and sympathies, etc. You can't demand them to just turn that all off and be some kind of super-human moral apparatus. You can and should demand of them to follow the law, though.
The actual difficult question shouldn't be: "How can I do something that's technically against the law but I think it's okay without the police bothering me?", but: "How can police be constructed in a way that it can still protect the people even when the laws start to actually suck?"
In my opinion that is human rights. Police in every country should have to protect human rights first and the laws of the local government second. Even that's hard to implement since obviously police officers are also simply a product of their society like everybody else.
But at least you have a small fail safe where an officer has a way to not act on a law if this particular officer sees their acting on the law as a human rights violation. There are ways to implement this in training and bureaucracy. Obviously not an easy task. :-) But probably the only one.
But arresting and then having it cleared costs time and energy but adds nothing to society.
Look, I'm not advocating that they should have more freedom. I am saying there is already freedom because the world is not as clear as the law states, so police should be properly trained to be aware of their role.
My general point I think follows from your last paragraph, their role to protect the people comes before following the letter of the law, but they should always try to uphold the intent.