Background: Major depressive disorder (MDD) is common and often has sub-optimal response to treatment. Difficult-to-treat depression (DTD) is a new concept that describes ‘depression that continues to cause significant burden despite usual treatment efforts’. Aims: To identify patients with likely DTD in UK secondary care and examine demographic, disease and treatment data as compared with ‘non-DTD’ MDD patients. Methods: Anonymised electronic health records (EHRs) of five specialist mental health National Health Service (NHS) Trusts in the United Kingdom were analysed using a natural language processing model. Data on disease characteristics, comorbidities and treatment histories were extracted from structured fields and using natural language algorithms from unstructured fields. Patients with MDD aged ⩾18 years were included in the analysis; those with presumed DTD were identified on the basis of MDD history (duration and recurrence) and number of treatments prescribed. Results: In a sample of 28,184 patients with MDD, 19% met criteria for DTD. Compared to the non-DTD group, patients with DTD were more likely to have severe depression, suicidal ideation, and comorbid psychiatric and/or physical illness, as well as higher rates of hospitalisation. They were also more likely to be in receipt of unemployment and sickness/disability benefits. More intensive treatment strategies were used in the DTD group, including higher rates of combination therapy, augmentation, psychotherapy and electroconvulsive therapy. Conclusion: This study demonstrates the feasibility of identifying patients with probable DTD from EHRs and highlights the increased burden associated with MDD in these patients.