The recent discovery of N-nitrosodimethylamine (NDMA), a mutagenic N-nitrosamine, in pharmaceuticals has adversely impacted the global supply of relevant pharmaceutical products. Contamination by N-nitrosamines diverts resources and time from research and development or pharmaceutical production, representing a bottleneck in drug development. Therefore, predicting the risk of N-nitrosamine contamination is an important step in preventing pharmaceutical contamination by DNA-reactive impurities for the production of high-quality pharmaceuticals. In this study, we first predicted the degradation pathways and impurities of model pharmaceuticals, namely gliclazide and indapamide, in silico using an expert-knowledge software. Second, we verified the prediction results with a demonstration test, which confirmed that Nnitrosamines formed from the degradation of gliclazide and indapamide in the presence of hydrogen peroxide, especially under alkaline conditions. Furthermore, the pathways by which degradation products formed were determined using ranitidine, a compound previously demonstrated to generate NDMA. The prediction indicated that a ranitidine-related compound served as a potential source of nitroso groups for NDMA formation. In silico software is expected to be useful for developing methods to assess the risk of N-nitrosamine formation from pharmaceuticals.