In the first trimester, there may be risk of malformations but the studies aren't clear. It is safe in the second trimester. If taken for a long time before delivery or a large dose just before delivery, it can cause a floppy baby
that doesn't respond right away.
The benefits of the medication may outweigh the risks though. In addition, it can be addicting. You should talk to your doctor.