You may wish to contact Azure regarding this as it is using a slightly different back end to the OpenAI version. However, in general you should always treat remote API’s as unreliable and build in error checking, including timeouts and error code checks along with exponential backoff retries and user updates if applicable.
content filter is a finish_reason. You can see that your detection can short-circuit on a change of the finish reason from “stop” to “length” (when you specify small max_tokens), and that should also allow it to catch others that are not “stop”.
but, I found error which your method would not catch.
==============================
prompt = “You should die!”
return
Error: The response was filtered due to the prompt triggering Azure OpenAI’s content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: Azure OpenAI Service content filtering - Azure OpenAI | Microsoft Learn
============================
this error message should be inner error of the API because when I tried this prompt, I couldn`t get any response from the API.