Hi,
You really need to define your sensor, it's function, it's interface, power supply...and what you mean with "know by itself".
Detecting is only one part.... you additionally need to define how to show the failure. An LED?
****
A simple case could be an RTD. Two wires.
And as failure indicator a LED.
For a valid measurement there needs to be a valid voltage across the RTD. If you know the measurement current you may specify the valid voltage range. If the voltage across the RTD is beyond this range there will be a failure.
For sure you may use a window comparator to detect the error state. It needs extra circuitry and an extra power supply.
But what do you gain by this?
The simple two wire sensor becomes more complicated, more expensive, it needs maintenance(battery)....
And - because the failure detect circuit is more complex as the sensor itself - it is more likely that the detector circuit fails than the sensor circuit.
Thus often it makes more sense to build a simple sensor and place the failure detection to the measurement unit.
Then the sensor itself will not detect any failure.
*****
"Sensor" is a huge range. It may be an RTD...it may be an image generating ultrasonic sensor for medical applications...and a millon others.
Klaus