JSON mode vs Function Calling

Trying to understand the trade offs between when to use JSON mode instead of Function Calling?
The documentation says JSON mode will always produce valid JSON. And at the same time it says Function Calling is “more likely” to return the right function parameters than in the previous models.

Previously I was using function calling to get JSON from the GPT models (using the function_call parameter) and occasionally it would give me invalid JSON. If I require valid JSON should I swap out my current function calling approach for the JSON mode in order to get 100% valid JSON then?

3 Likes

Using the JSON mode, which is an inbuilt feature specifically for the purpose of creating a JSON, makes more sense in your situation.

Don’t forget to add the line 'Return the output as JSON" to the system prompt when using the mode, so that the ystem does not throw up an error

Does it consistently return the same JSON structure?

1 Like

For me, it’s been fairly consistent today. Haven’t had any problems or exceptions thrown

1 Like

(I work on JSON mode at OpenAI)

JSON mode is always enabled for the generation of function arguments, so those are guaranteed to parse.

JSON mode is opt in for regular messages.

Note that JSON mode sadly doesn’t guarantee that the output will match your schema (though the model tries to do this and is continually getting better at it), only that it is JSON that will parse.

So TL;DR is that you can use either functions or messages, and in both cases know you will get parseable JSON back :+1:

17 Likes

Appreciate your work, JSON mode solves so many problems parsing the JSON responses, especially the unescaped symbols. Good work :heart:

1 Like

Amazing! Thank you @owencmoore

Hello,
I still have such issues (not valid JSON or completely other format) on around 10 to 20% of my function calls.

Example function :

Should return a json with field “command” inside.
I have in return the format below, which is incorrect and not parseable.

Any help on this ?

As this topic has a noted solution closing this topic.

Please open a new topic for new questions.