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?
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?
For me, it’s been fairly consistent today. Haven’t had any problems or exceptions thrown
(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
Appreciate your work, JSON mode solves so many problems parsing the JSON responses, especially the unescaped symbols. Good work
Amazing! Thank you @owencmoore