Incorrect JSON format from function calling

Hi all!
Is anyone else having issues with incorrectly formatted JSON as an output from function calling?

I’m calling this function which should return an array of objects. But somehow it returns an invalid JSON response. Note: I do get a response and the API call succeeds but the completion itself (function arguments) are incorrectly formatted.

[{"name":"email_formatting","description":"Extract information and format emails accordingly","parameters": {"type":"object","properties": {"Fundraising": {"type":"array","items": {"type":"object","properties": {"Stage": {"type":"string","enum": ["Series A","Series B","Series C","Series D","Series E","Series F","Pre-Seed","Seed"]},"Amount": {"type":"integer"},"Date": {"type":"string"},"Pre-money": {"type":"integer"},"Post-money": {"type":"integer"}}},"description":"Information about Fundraising and funding rounds."}}}}]

This is my response:

  "Fundraising": [
      "Stage": "Series B",
      "Amount": 2500000,
      "Date": "1686055002.675",

it misses a value for Pre-money, Post-money and some closing brackets.

Is anyone else experiencing stuff like this?

1 Like

I am facing similar issues. Although defining JSON schema as parameters, the response is not valid JSON.

1 Like

Try one shot prompting (give one or more examples like

Here is some example input




and output should look like this




1 Like

thanks @jochenschultz! This helps a lot! I kinda expected that to be included in the training of the new model for Function Calling and wouldn’t be necessary in the prompt anymore. But including an example in the system message helps a lot already!

1 Like

Yelling at the model like this might work too:



I faced the same problem even with the function calling.

Just resend the invalid JSON to GPT and prompt
“Fix this invalid JSON data.”

It worked pretty well for me. :wink:

Oh I missed that you recieved invalid JSON with no values…
In my case, the problem was just missing quotation.
Your case is more troblesome…

Adding examples is one way.
You can also add the rules of JSON format in addition to the examples.
such as…
1,Data is in name/value pairs
2,Data is separated by commas
3,Curly braces hold objects
4,Square brackets hold arrays
This made better result for me!