Identifying pregnancy episodes and accurately estimating their beginning and end dates are imperative for observational maternal vaccine safety studies using electronic health record (EHR) data. We modified the Vaccine Safety Datalink (VSD) Pregnancy Episode Algorithm (PEA) to include both the International Classification of Disease, ninth revision (ICD-9 system) and ICD-10 diagnosis codes, incorporated additional gestational age data, and validated this enhanced algorithm with manual medical record review. We also developed the new Dynamic Pregnancy Algorithm (DPA) to identify pregnancy episodes in real time. Around 75% of the pregnancy episodes identified by the enhanced VSD PEA were live births, 12% were spontaneous abortions (SABs), 10% were induced abortions (IABs), and 0.4% were stillbirths (SBs). Gestational age was identified for 99% of live births, 89% of SBs, 69% of SABs, and 42% of IABs. Agreement between the PEA-assigned and abstractor-identified pregnancy outcome and outcome date was 100% for live births, but was lower for pregnancy losses. When gestational age was available in the medical record, the agreement was higher for live births (97%), but lower for pregnancy losses (75%). The DPA demonstrated strong concordance with the PEA and identified pregnancy episodes ⩾6 months prior to the outcome date for 89% of live births. The enhanced VSD PEA is a useful tool for identifying pregnancy episodes in EHR databases. The DPA improves the timeliness of pregnancy identification and can be used for near real-time maternal vaccine safety studies. Improving identification of pregnancies in the Vaccine Safety Datalink electronic medical record databases to allow for better and faster monitoring of vaccination safety during pregnancy Introduction: It is important to monitor of the safety of vaccines after they have been approved and licensed by the Food and Drug Administration, especially among women vaccinated during pregnancy. The Vaccine Safety Datalink (VSD) monitors vaccine safety through observational studies within large databases of electronic medical records. Since 2012, VSD researchers have used an algorithm called the Pregnancy Episode Algorithm (PEA) to identify the medical records of women who have been pregnant. Researchers then use these medical records to study whether receiving a particular vaccine is linked to any negative outcomes for the woman or her child.Methods: The goal of this study was to update and enhance the PEA to include the full set of medical record diagnostic codes [both from the older International Classification of Disease, ninth revision (ICD-9 system) and the newer ICD-10 system] and to incorporate additional sources of data about gestational age. To ensure the validity of the PEA following these enhancements, we manually reviewed medical records and compared the results with the algorithm. We also developed a new algorithm, the Dynamic Pregnancy Algorithm (DPA), to identify women earlier in pregnancy, allowing us to conduct more timely vaccine safety assessments.Results: The new version of the PEA identified 2,485,410 pregnancies in the VSD database. The enhanced algorithm more precisely estimated the beginning of pregnancies, especially those that did not result in live births, due to the new sources of gestational age data.Conclusion: Our new algorithm, the DPA, was successful at identifying pregnancies earlier in gestation than the PEA. The enhanced PEA and the new DPA will allow us to better evaluate the safety of current and future vaccinations administered during or around the time of pregnancy.