python api return code. when task fails

I am running the python api to develop an inhouse script but the script returns always 0 even if a task failed. how can we capture the task exit code.?

the python script always returns 0 even per instance there is a copy tasks that failed to validate. i get on stdout that the task failed however the rc code of the script is still 0!

I am using this example to copy a file to remote hosts it works fine but not when the copy is unsuccessful…
https://docs.ansible.com/ansible/2.9/dev_guide/developing_api.html

tasks do not use return codes, their status is reflected in the return
data dictionary as keys.