For 2≤s<t, the Erdős-Rogers function fs,t(n) measures how large a Ks-free induced subgraph there must be in a Kt-free graph on n vertices. There has been an extensive amount of work towards estimating this function, but until very recently only the case t=s+1 was well understood. A recent breakthrough of Mattheus and Verstraëte on the Ramsey number r(4,k) states that f2,4(n)≤n1/3+o(1), which matches the known lower bound up to the o(1) term. In this paper we build on their approach and generalize this result by proving that fs,s+2(n)≤n4s−52s−3+o(1) holds for every s≥2. This comes close to the best known lower bound, improves a substantial body of work and is the best that any construction of similar kind can give.