Yes. Test. There are fentanyl test kits.
And bioassay. Whenever you're using a new batch, test with a few percent of the recommended dose. Then adjust accordingly. Even if your test kit reports that it's OK.
Also, it's the damn drug war that's arguably responsible for the fentanyl problem. Fentanyl is about 50 times as potent as heroin. So if you want a kilogram of "heroin", you can mix 20 gm fentanyl with 980 gm lactose. And it's lots easier to smuggle 20 gm than 1000 gm.
The problem, though, is that uniformly mixing 20 gm into a kilogram is much harder than you might think. Just one little bit of clumping, and you have a lethal dose.