In a perfect world, there wouldn't be, but inmates swallow drugs, or shove them up their ass that they get on visits, and unless you specifically see it, it's a done deal. You can't accompany them into the bathroom in the visiting room, and when you have a large visiting room full of inmates, and their visitors every weekend, you can't see everything that happens 100% of the time. There's only a certain number of officers assigned to the visiting room. Sometimes you're lucky if you have two officers, and the State won't approve overtime to beef up security presence. We can't frisk visitors, and we can't frisk civilian employees, who are just as capable of bringing in drugs and other contraband as uniformed staff is.
When a tip is given that an inmate may have swallowed a balloon of drugs on a visit, there is a specific procedure that has to be be followed. In the end, no pun intended, the inmate will be put in a special housing cell, and an officer will sit outside his cell, keeping the inmate in view at all times. The water will be shut off in the cell so he can't flush the toilet, and after 3 days (I think that may be the time limit), if he hasn't crapped by then, he's sent back to his unit. If he does crap, the officer has to search through his crap to find whatever he swallowed. And if he has swallowed drugs, he's then charged with possession of a controlled substance, but he's usually only charged based on prison rules, not outside criminal charges.
It would be almost impossible to maintain a sterile environment within a prison, with the only exception being the Super Max. However, we should expect public employees to not contribute to the contraband flow into prisons.