Unreliable and unexpected response

I’m new in AI and I’m confused about responses I get.
this is search:

        $search = "
            Check ad\n
            Text: $text\n
            Category: $category\n\n
            Analyze the provided ad text and determine its suitability based on the following criteria:\n
            - profanity_check: Return true if profanity is found in the ad.\n
            - spam_check: Return true if the ad is identified as spam.\n
            - wrong_category: Return true if the ad is not suitable for the chosen category.\n
            - other_reason: Return true if the ad is deemed unsuitable for any other reason.\n
            Note: This prompt is for ads seeking to hire tradespersons, not for tradespersons posting their own ads.\n

And this is my request details:

          ->post("https://api.openai.com/v1/chat/completions", [
                "model" => "gpt-3.5-turbo",
                'messages' => [
                        "role" => "system",
                        "content" => $search
                'max_tokens' => 1000,
                'temperature' => 0.0,
                'stop' => ['\n'],

I don’t know what doing wrong but on such $text = ‘sadsf ds ds dsf fds fsd fdsfdsf dsfd fds’
I get response like this:

  'model' => 'gpt-3.5-turbo-0613',
  'choices' => 
  array (
    0 => 
    array (
      'index' => 0,
      'message' => 
      array (
        'role' => 'assistant',
        'content' => '{
  "profanity_check": false,
  "spam_check": false,
  "wrong_category": false,
  "other_reason": false
      'finish_reason' => 'stop',

which is not expect by me.
Any ideas what I do wrong?

The actual AI language you are getting back is within “content”:

  "profanity_check": false,
  "spam_check": false,
  "wrong_category": false,
  "other_reason": false

That is a python dictionary output, a good backend output when the AI has to guess what you want for output because it is not specified.

The garbage text might be “wrong category” to you, but there’s not enough instruction for the AI to really understand.

You are providing everything in a system role message? That’s not the best way to guide the chat AI.

Try to rewrite:
System role: contains instructions and examples of what the processor does
User role: contains the changing data that the AI will analyze

A stop on any carriage return is not a good idea unless you have explicitly crafted one-line output.

Thank you very much! for the advises!