Requesting JSON Chat Completions from OpenAI for Programmatic Use

InstructorColby Fayock

Share this video with your friends

Send Tweet

Getting a long string as a response makes a lot of sense if you're building an app or tool that appears conversational or if you just want to display a little bit of information as a response, but if you want to do something programmatic with the information, such as using different datapoints from the information in different parts of the UI, you'll have a hard time parsing out that information from a single request.

To get around this, we can simply ask GPT to return our data formatted as JSON! Further, we can ask it in a particular shape. You'll learn how to format a chat completion prompt to request JSON data and gain confidence in that data by defining the shape in the request.