Use of D3 and D5 in inverting circuit
My humble opinion is...
Only inverting stage is T2. That's why you have err_out = 1 when err_in = 0. Looking as voltage levels. 
T1 emitter follower adjusts to high impedance of err source circuit, and R18/R20 adjust high level err input (24V) to logic level 5V since obviously power supply of 74AC14 is 5V.

But inverting stage T2 is also constant current sink. 
That's what D2 and D3 are for. 
It will limit T2 base voltage to 1.4V. Since Ube is 0.7V, you will have 0.7 left for R22.
Constant current is 0.7/R22. 0.7/22=31mA
:)