Detect Script failure in Docker

Hello Community

I have a problem with a container in which I run a python script.
Sometimes it happens that this python script crashes, but the container is still shown as healthy via docker ps, which means that the container does not restart.
Is there a way to detect such an error message?
Unfortunately I have not found anything yet.

Thanks for your help

Many greetings

A Dockerfile allows declaring a health check for the image:
A compose file allows setting (and overriding an existing) heath checks:

Since there is no generic way to identify the heath state of containerized applications, you will need to implement the mechanics that identify the health state yourself and call them in your health check.