Structured output with JSON Schema
You can use JSON to enforce a specific output format.
For example, on Playground:
- Select the JSON response checkbox.
- In the JSON schema box, describe the kind of output you want, e.g.
a list of Australian addresses
- Click on the Generate JSON schema button.
- Run your prompt, e.g.
Generate a list of realistic Australian addresses
.
This generates a JSON response like this:
{
"addresses": [
{
"streetNumber": "123",
"streetName": "Main St",
"suburb": "Sydney",
"state": "NSW",
"postcode": "2000"
},
// ...
{
"streetNumber": "202",
"streetName": "Collins St",
"suburb": "Melbourne",
"state": "VIC",
"postcode": "3000"
}
]
}
This involves 2 steps:
- Select the JSON response checkbox. This ensures that the output will always be JSON.
- Specify a JSON schema. This ensures that your output will always have this exact structure.