Safe drug recommendation systems play a crucial role in minimizing adverse drug reactions and enhancing patient safety. In this research, we propose an innovative approach to develop a safety drug recommendation system by integrating the Salp Swarm Optimization-based Particle Swarm Optimization (SalpPSO) with the GraphSAGE algorithm. The goal is to optimize the hyper parameters of GraphSAGE, enabling more accurate drug-drug interaction prediction and personalized drug recommendations. The research begins with data collection from real-world datasets, including MIMIC-III, Drug Bank, and ICD-9 ontology. The databases provide comprehensive and diverse clinical data related to patients, diseases, and drugs, forming the foundation of a knowledge graph. It represents drug-related entities and their relationships, such as drugs, indications, adverse effects, and drug-drug interactions. The knowledge graph’s integration of patient data, disease ontology, and drug information enhances the system’s accuracy to predict drug-drug interactions as well as identifying potential detrimental drug reactions. The GraphSAGE algorithm is employed as the base model for learning node embeddings in the knowledge graph. To enhance its performance, we propose the SalpPSO algorithm for hyper parameter optimization. SalpPSO combines features from Salp Swarm Optimization and Particle Swarm Optimization, offering a robust and effective optimization process. The optimized hyper parameters lead to more reliable and accurate drug recommendation system. For evaluation, the dataset is split into training and validation sets and compared the performance of the modified GraphSAGE model with SalpPSO-optimized hyper parameters to the standard models. The experimental analysis conducted in terms of various measures proves the efficiency of the proposed safe recommendation system, offering valuable for healthcare experts in making more informed and personalized drug treatment decisions for patients.