Abstract Background Sodium-glucose cotransporter 2 inhibitors (SGLT2i) are widely used to reduce cardiovascular risk in patients with type 2 diabetes. However, certain patient subgroups, including younger individuals or those with lower body mass index (BMI), have been underrepresented in previous randomized clinical trials. Therefore, the consistency of the effectiveness of SGLT2i has not been thoroughly investigated. Purpose This research aims to investigate the individual benefit of SGLT2i on cardiovascular risk reduction across the diverse patient population with type 2 diabetes Methods We investigated the effectiveness of SGLT2i versus active comparators (dipeptidyl peptidase 4 inhibitors [DPP4i]) using a target trial emulation framework, prevalent new-user design, and a nationwide insurer-based database covering more than 30 million working-age citizens in Japan. Participants were identified using data from April 2015 to March 2022 and were followed until March 2023. The primary endpoint was the composite of all-cause death, myocardial infarction, stroke, or heart failure. We then applied the machine learning causal forest algorithm to the emulated trial cohort to predict the individualized benefit of SGLT2i in reducing cardiovascular outcomes. After describing the characteristics of patients with predicted benefits above the median (high-benefit group) and those with predicted benefits below the median (low-benefit group), we compared the long-term survival outcomes between the high-benefit group and the low-benefit group using adjusted Cox proportional hazard models. Results The study included 274,886 participants (SGLT2i, n=137,443; DPP4i, n=137,443) with a mean age of 55.7 years, 17.3% (n=47,517) female, and a mean BMI of 27.3kg/m2. Over a median follow-up of 36 months, 3.6% (n=9,896) experienced the primary outcome. SGLT2i were associated with a reduced incidence of the primary endpoint in the entire cohort (hazard ratio [HR] = 0.94 [95% confidence interval (95%CI): 0.90–0.97]). The causal forest model showed that the effects of SGLT2i were heterogeneous across individuals. Patients in the low-benefit group were characterized by older age, female gender, lower BMI, lower blood pressure, worse kidney function, and milder diabetes status than those in the high-benefit group. While we found the preventive effect of SGLT2i on long-term cardiovascular outcomes in the high-benefit group (HR [95%CI] = 0.86 [0.82–0.90]), the effect was not observed in the low-benefit group (HR [95%CI] = 1.05 [1.00–1.11]; p-for-interaction < 0.001). Conclusion By applying a machine-learning causal forest to a target trial emulation cohort in the general population, we found heterogeneity in the effect of SGLT2i on cardiovascular outcomes, and identified characteristics of patients who are less likely to benefit from SGLT2i. The findings suggest personalized treatment strategies for cardiovascular risk reduction in patients with type 2 diabetes.Graphical summary