# '$.function\_call' is invalid. Please help

**URL:** <https://community.openai.com/t/function-call-is-invalid-please-help/266803>\
**Category:** API\
**Tags:** chatgpt\
**Created:** [June 16, 2023, 6:46am UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803 "2023-06-16T06:46:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven.ynie](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@steven.ynie](https://community.openai.com/u/steven.ynie)\
**Post date:** [June 16, 2023, 6:46am UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803/1 "2023-06-16T06:46:46Z")

</div>

Hello everyone, I’m trying to use the new function call:

```auto
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo-0613",
        messages=[{"role": "user", "content": "write me an agenda of a 7 days local food trip to NYC. "}],
        functions=[
            {
                'name': 'write_travel_agenda',
                "description": "Writing agenda to disk",
                "parameters": parameter_dict
             }
        ],
        function_call='{"name": "write_travel_agenda"}',
    )

```

The parameters dict look like this:

```auto
{'definitions': {'Agenda': {'properties': {'afternoonAgenda': {'description': 'describe '
                                                                              'afternoon '
                                                                              'agenda',
                                                               'title': 'Afternoonagenda',
                                                               'type': 'string'},
                                           'eveningAgenda': {'description': 'describe '
                                                                            'dinner '
                                                                            'agenda',
                                                             'title': 'Eveningagenda',
                                                             'type': 'string'},
                                           'morningAgenda': {'description': 'describe '
                                                                            'morning '
                                                                            'agenda',
                                                             'title': 'Morningagenda',
                                                             'type': 'string'},
                                           'title': {'description': 'which day',
                                                     'title': 'Title',
                                                     'type': 'string'}},
                            'required': ['title',
                                         'morningAgenda',
                                         'afternoonAgenda',
                                         'eveningAgenda'],
                            'title': 'Agenda',
                            'type': 'object'}},
 'properties': {'agendas': {'description': 'agenda details',
                            'items': {'$ref': '#/definitions/Agenda'},
                            'title': 'Agendas',
                            'type': 'array'}},
 'required': ['agendas'],
 'type': 'object'}

```

I’m keep getting ‘$.function\_call’ is invalid. from the server. What does that mean?

---

<div class="post-metadata">

**Author:** ![PriNova](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/prinova/32/752175_2.png) [@PriNova](https://community.openai.com/u/PriNova)\
**Post date:** [June 16, 2023, 7:18am UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803/2 "2023-06-16T07:18:12Z")

</div>

It seems you getting a “Bad Request” error, because your Json schema for the `parameters` is not in the correct format.

It should looks like:

```auto
"parameters": {
        "type": "object",
        "properties": {
          "arg1": {
            "type": "string",
            "description": "The first argument in the schema"
          },
          "arg2": {
            "type": "number",
            "description": "The second argument in the schema"
          },
          ...
      }, "required": ["arg1", "arg2", ...] # optional
}

```

---

<div class="post-metadata">

**Author:** ![steven.ynie](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@steven.ynie](https://community.openai.com/u/steven.ynie)\
**Post date:** [June 16, 2023, 3:52pm UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803/3 "2023-06-16T15:52:33Z")

</div>

Thanks! What is the best way to define one of the parameters as input of array of dict?

---

<div class="post-metadata">

**Author:** ![PriNova](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/prinova/32/752175_2.png) [@PriNova](https://community.openai.com/u/PriNova)\
**Post date:** [June 16, 2023, 4:46pm UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803/4 "2023-06-16T16:46:56Z")

</div>

I’ve got it working with the following prompt:

> Call the test\_Code function with the name ‘priory\_Test’ and pass a dictionary with the key/value pairs: [{‘baseID : 32’ and ‘personID : 45’}, {‘strong’ : 100, ‘armor’ : 45}].

The function definition looks like this:

```Json
{
    "name": "test_Code",
    "description": "A function to test a specified code.",
    "parameters": {
        "type": "object",
        "properties": {
          "functionName": {
            "type": "string",
            "description": "The name of the created function to test, e.g. factorial, fibonacci, print, etc"
          },
          "params": {
            "type": "string",
            "description": "An array of dictionaries as parameter to pass to the function for testing, e.g. [{x1: int, y1: int}, {x2: int, y2: int }]."
          }
        },
        "required": ["functionName", "params"]
    }
}

```

And the output is:

> ‘function\_call’: {‘name’: ‘test\_Code’, ‘arguments’: ‘{\n “functionName”: “priory\_Test”,\n “params”: “[{'baseID': 32, 'personID': 45}, {'strong': 100, 'armor': 45}]”\n}’}}, ‘finish\_reason’: ‘stop’}], ‘usage’: {‘prompt\_tokens’: 258, ‘completion\_tokens’: 44, ‘total\_tokens’: 302}}

I used a temperature setting of 0.0  
And the GPT-3 model.

I hope this helps

---

<div class="post-metadata">

**Author:** ![PriNova](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/prinova/32/752175_2.png) [@PriNova](https://community.openai.com/u/PriNova)\
**Post date:** [June 16, 2023, 8:49pm UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803/5 "2023-06-16T20:49:19Z")

</div>

I got array working. It needs to define the items additionally.

This is the syntax for:

```plaintext
(left out for brevity)
"params": {
            "type": "array",
            "description": "An array of strings to pass to the function for testing, e.g. ['Hello', 'World'].",
            "items" : {
                "type" : "string"
            }
          }

```

And for the use case of an array of dictionaries, the function definition looks like:

```plaintext
(left out for brevity)
"params": {
            "type": "array",
            "description": "An array of dictionaries to pass to the function for testing.",
            "items" : {
                "type" : "object",
                "properties" : {}
            }
          }

```

You can of course define the value types of the dictionary keys with the properties schema.

---

<div class="post-metadata">

**Author:** ![landonbconnell](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/landonbconnell/32/157692_2.png) [@landonbconnell](https://community.openai.com/u/landonbconnell)\
**Post date:** [June 19, 2023, 3:28pm UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803/6 "2023-06-19T15:28:26Z")

</div>

I’m having a lot of trouble getting arrays working, if you could take a look at my code and get it working, I will buy you a coffee:

```
model: 'gpt-3.5-turbo-0613',
        messages: [
            { role: 'system', content: "You are a helpful assistant that generates creative playlist ideas." },
            { role: 'user', content: "I'm trying to organize a list of songs into playlists. Based on some common moods/emotions that music tries to evoke in its listeners, generate a creative and unique playlist name and a corresponding description." }
        ],
        functions: [
            {
                name: "getNamesAndDescriptions",
                description: "Generates playlist names and descriptions",
                parameters: {
                    type: "array",
                    description: "An array of objects representing playlists",
                    items: {
                        type: "object",
                        properties: {
                            id: {
                                type: "number",
                                description: "A random five-digit number denoting the playlist id"
                            },
                            name: {
                                type: "string",
                                description: "A creative name for the playlist"
                            },
                            description: {
                                type: "string",
                                description: "A creative description of the playlist"
                            }
                        }
                    },
                    required: ["id", "name", "description"]
                },
            }                
        ],            
        function_call: "auto",
        temperature: 1.5
    })

```

---

<div class="post-metadata">

**Author:** ![landonbconnell](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/landonbconnell/32/157692_2.png) [@landonbconnell](https://community.openai.com/u/landonbconnell)\
**Post date:** [June 19, 2023, 4:37pm UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803/7 "2023-06-19T16:37:36Z")

</div>

Nevermind, I figured it out on my own. If anybody else is having the same exact issue as me, the outermost type in parameters must be “object”. Anything within that object may have the type “array”. Example below:

```auto
const completion = await openai.createChatCompletion({
            model: 'gpt-3.5-turbo-0613',
            messages: [
                { role: 'system', content: "You are a helpful assistant that generates creative playlist ideas." },
                { role: 'user', content: "I'm trying to organize a list of songs into playlists. Based on some common moods/emotions that music tries to evoke in its listeners, generate 5 creative and unique playlist names and their corresponding descriptions." }
            ],
            functions: [
                {
                    name: "getNamesAndDescriptions",
                    description: "Generates playlist names and descriptions",
                    parameters: {
                        type: "object",
                        properties: {
                            playlists: {
                                type: "array",
                                description: "An array of objects representing playlists",
                                items: {
                                    id: {
                                        type: "null",
                                        description: "A unique identifier for the playlist, initially set to null"
                                    },
                                    playlist_name: {
                                        type: "string",
                                        description: "A creative name for the playlist"
                                    },
                                    playlist_description: {
                                        type: "string",
                                        description: "A creative description of the playlist"
                                    }
                                }
                            }
                        },
                        required: ["id", "playlist_name", "playlist_description"]
                    },
                }                
            ],            
            function_call: "auto",
            temperature: 1.2
        })

```

---

<div class="post-metadata">

**Author:** ![PriNova](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/prinova/32/752175_2.png) [@PriNova](https://community.openai.com/u/PriNova)\
**Post date:** [June 19, 2023, 5:13pm UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803/8 "2023-06-19T17:13:17Z")

</div>

Bravo.

You are right, the properties key must be typed as ‘object’.

If you are getting trouble with the id of the items, then better set it as ‘integer’ with a sentinel value of -1. Usually you will validate this in the function code. GPT might be confused to read that it is initially at ‘null’.

Good luck and have fun.

---

<div class="post-metadata">

**Author:** ![arichards4814](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/arichards4814/32/162495_2.png) [@arichards4814](https://community.openai.com/u/arichards4814)\
**Post date:** [June 29, 2023, 7:41pm UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803/9 "2023-06-29T19:41:31Z")

</div>

Hey came here to solve this problem turned out it was just my structure. But I can’t find this in the docs **why must properties have the key value pair “type”: “object”** , what is typed as an object, is this the return value of the function? I just don’t get what it is referring to.

---

<div class="post-metadata">

**Author:** ![aaron5](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/aaron5/32/11333_2.png) [@aaron5](https://community.openai.com/u/aaron5)\
**Post date:** [June 29, 2023, 8:10pm UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803/10 "2023-06-29T20:10:03Z")

</div>

Thanks for providing the answer to your question. Definitely helps those of us who were hoping there would be one.

---

<div class="post-metadata">

**Author:** ![EricGT](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ericgt/32/20571_2.png) [@EricGT](https://community.openai.com/u/EricGT)\
**Post date:** [December 17, 2023, 4:18pm UTC](https://community.openai.com/t/function-call-is-invalid-please-help/266803/11 "2023-12-17T16:18:56Z")

</div>


