Grokking AI: 50 Questions Every Engineer Asks
0% completed
How Do I Get Valid JSON From a Model Every Time?
Short answer: Asking for JSON in the prompt works most of the time but not every time. For a guarantee, use the structured output feature of the API. You give the feature a description of the JSON that you expect (a schema). At each step, the feature allows only the small pieces of text (tokens) that keep the output valid for that schema. The feature guarantees the structure and not the values, so validate the values in code as well.
Look at the panel on the right
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%