The use site has a (24/7 guarded) attached pharmacy with government-produced clean heroin, meth, etc. Users can trade in their drug, the pharmacist runs it through a mass spec analyzer and dispenses back to them an amount of pharmaceutical-grade drug of interest, the amount dispensed being equal to the fraction that is present in whatever cut/mixed drug sample they handed in.
In addition to the obvious safety benefits of only consuming guaranteed-pure drugs, the drug user gets an on-the-spot and very salient piece of information about the quality of the drug they purchased. This creates a lot of precise and accurate drug quality information and feeds it back into the drug abuse cycle. A user buys from a dealer, and right before their first hit they get a purity score to evaluate their dealer with - and maybe some information about what other drugs their dealer just tried to poison them with.
(To avoid some obvious risks: the tested drug sample should be immediately ejected from the analyzer into a denaturing bath and regularly incinerated, so that handed-in drugs are not a theft or recycling target. You probably need to mandate they can trade in only the dose they are about take, and they have to take it on the spot, so that government supplies do not leak back into the streets. There are certainly other failure modes too, a close eye should be kept on this and further processes brought in as needed.)