ImportanceTertiary lymphoid structures (TLSs) are associated with a favorable prognosis and improved response to cancer immunotherapy. The current approach for evaluation of TLSs is limited by interobserver variability and high complexity and cost of specialized imaging techniques.ObjectiveTo develop a machine learning model for automated and quantitative evaluation of TLSs based on routine histopathology images.Design, Setting, and ParticipantsIn this multicenter, international diagnostic/prognostic study, an interpretable machine learning model was developed and validated for automated detection, enumeration, and classification of TLSs in hematoxylin-eosin–stained images. A quantitative scoring system for TLSs was proposed, and its association with survival was investigated in patients with 1 of 6 types of gastrointestinal cancers. Data analysis was performed between June 2021 and March 2022.Main Outcomes and MeasuresThe diagnostic accuracy for classification of TLSs into 3 maturation states and the association of TLS score with survival were investigated.ResultsA total of 1924 patients with gastrointestinal cancer from 7 independent cohorts (median [IQR] age ranging from 57 [49-64] years to 68 [58-77] years; proportion by sex ranging from 214 of 409 patients who were male [52.3%] to 134 of 155 patients who were male [86.5%]). The machine learning model achieved high accuracies for detecting and classifying TLSs into 3 states (TLS1: 97.7%; 95% CI, 96.4%-99.0%; TLS2: 96.3%; 95% CI, 94.6%-98.0%; TLS3: 95.7%; 95% CI, 93.9%-97.5%). TLSs were detected in 62 of 155 esophageal cancers (40.0%) and up to 267 of 353 gastric cancers (75.6%). Across 6 cancer types, patients were stratified into 3 risk groups (higher and lower TLS score and no TLS) and survival outcomes compared between groups: higher vs lower TLS score (hazard ratio [HR]; 0.27; 95% CI, 0.18-0.41; P < .001) and lower TLS score vs no TLSs (HR, 0.65; 95% CI, 0.56-0.76; P < .001). TLS score remained an independent prognostic factor associated with survival after adjusting for clinicopathologic variables and tumor-infiltrating lymphocytes (eg, for colon cancer: HR, 0.11; 95% CI, 0.02-0.47; P = .003).Conclusions and RelevanceIn this study, an interpretable machine learning model was developed that may allow automated and accurate detection of TLSs on routine tissue slide. This model is complementary to the cancer staging system for risk stratification in gastrointestinal cancers.