We had a session on this and it’s really hard.
As above, you have to think if the defender has control of the ball before the challenge.
At higher levels this is easier as it’s usually obvious what the defender is trying to do, and they can do it, and a mistake, like bad control that allows a challenge, is obvious.
But lower down, mixed ability, where players don’t have complete ability... I think the smart thing is to err a bit on the defender’s side if there’s some miscontrol and a challenge comes in quick from an offside position. It’s obscure, it’s a horrible judgement call to make close to goal...
Thankfully over 300 games in (maybe 4) and I’ve never faced this in the flesh!