BackgroundDepression that does not respond to antidepressants is treatment‐resistant depression (TRD). TRD definitions include assessments of treatment response, dose and duration, and implementing these definitions in claims databases can be challenging. We built a data‐driven TRD definition and evaluated its performance.MethodsWe included adults with depression, ≥1 antidepressant, and no diagnosis of mania, dementia, or psychosis. Subjects were stratified into those with and without proxy for TRD. Proxies for TRD were electroconvulsive therapy, deep brain, or vagus nerve stimulation. The index date for subjects with proxy for TRD was the procedure date, and for subjects without, the date of a randomly selected visit. We used three databases. We fit decision tree predictive models. We included number of distinct antidepressants, with and without adequate doses and duration, number of antipsychotics and psychotherapies, and expert‐based definitions, 3, 6, and 12 months before index date. To assess performance, we calculated area under the curve (AUC) and transportability.ResultsWe analyzed 33,336 subjects with no proxy for TRD, and 3,566 with the proxy. Number of antidepressants and antipsychotics were selected in all periods. The best model was at 12 months with an AUC = 0.81. The rule transported well and states that a subject with ≥1 antipsychotic or ≥3 antidepressants in the last year has TRD. Applying this rule, 15.8% of subjects treated for depression had TRD.ConclusionThe definition that best discriminates between subjects with and without TRD considers number of distinct antidepressants (≥3) or antipsychotics (≥1) in the last year.