Most farmers will not tolerate this with their valuable livestock at risk, nor should they. Dogs must learn not to herd livestock when they are not supposed to, or they are at risk of being destroyed by producers protecting their livestock! So if you have a herding dog, you will need to make sure he does not try to herd other people's livestock, or your own, when he is not required or directed to do so.
While herding dogs have been bred for generations to want to herd livestock naturally, and this is a great talent that can be harnessed and very useful to farmers, a dog that herds when it is not supposed to is a danger to livestock and himself. Not only can frightened livestock be injured if they fall or are chased through an obstacle or across rough terrain, but the dog is in danger of being destroyed as a nuisance animal or injured by large livestock trying to protect themselves. Herding dogs that are not exposed to livestock may try to herd small animals or children or even adults! Ironically, teaching your dog to herd on command and giving them an outlet for such behavior may be a good way of controlling it, by teaching the dog that they only herd when directed. Other methods of controlling instinctive herding involve teaching your dog a different association and behavior with livestock, such as the 'leave it' command or an alternative behavior so that a dog exposed to livestock, small animals, or children ignores them, backs away, or performs other behavior to receive reinforcement.
You will need lots of treats to teach 'leave it', and alternative behaviors to dogs that are motivated to herd. You will need to contain your dog during training to ensure they do not inadvertently try to run livestock. which is a self-rewarding behavior and will make the habit harder to break. Training to put herding on command is another alternative strategy that will require exposure to livestock, such as sheep that can be herded. Both will take a significant time investment and involve controlling your dog to prevent unsupervised herding, which could result in injury to your dog or to livestock.