The study evaluated the validity of an algorithm to estimate gestational length and determine prenatal medication exposure based on electronic health plan data. The algorithm underestimated gestational length by an average of 5.5 days and underestimated the prevalence of preterm births compared to measures from linked birth certificates. The algorithm correctly classified exposure status for most women taking antidepressants but had poorer performance for antibiotics due to their sporadic use. While the algorithm provided reasonable estimates, its accuracy may vary for other medications beyond the two antidepressants and two antibiotics evaluated in this study.