Many medical experts say that these laws are based on exaggerated perceptions of the risks to newborns and are medically counterproductive.

In 2011, the American College of Obstetricians and Gynecologists said that “incarceration and threat of incarceration have proved to be ineffective in reducing the incidence of alcohol or drug abuse” and that mandated testing and reporting lead women to avoid prenatal care that “greatly reduces the negative effects of substance abuse during pregnancy.”

Dr. Cresta W. Jones, an obstetrician and a fetal medicine specialist at the Medical College of Wisconsin who sees many women with histories of drug or alcohol abuse, said that even sporadic detentions had sowed fear.

“The women are scared to come in if they have dependency problems,” she said. “When you allow them to be honest you get better outcomes in their pregnancies.”

She and other experts said that while fetal alcohol syndrome is a proven but unpredictable threat, the impact of illegal drug use on newborns is generally less serious and more treatable than is popularly believed.

Ms. Beltran thought she was being helpful when, in her first prenatal visit, on July 2, to a clinic at St. Joseph’s Hospital, she discussed her medical history. Ms. Beltran, who worked as a bartender and waitress and became pregnant by a boyfriend who remains close, told the physician assistant that she had become addicted last year to Percocet, a painkiller. But she had willed herself off it the previous fall, even going to the hospital in November for withdrawal symptoms.

She said she was unable to afford a prescription for Suboxone, which blocks other opiates and is widely used in treatment, including during pregnancy. So she obtained some from a friend and, on her own, reduced the dosage over time, stopping altogether three days before her appointment at St. Joseph’s. She said that in May, before she knew she was pregnant, she had taken one Vicodin tablet for a toothache.