Structured output with JSON Schema

You can use JSON to enforce a specific output format.

For example, on Playground:

  1. Select the JSON response checkbox.
  2. In the JSON schema box, describe the kind of output you want, e.g. a list of Australian addresses
  3. Click on the Generate JSON schema button.
  4. Run your prompt, e.g. Generate a list of realistic Australian addresses.

Here's an image of what you would type into the Playground

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:

  1. Select the JSON response checkbox. This ensures that the output will always be JSON.
  2. Specify a JSON schema. This ensures that your output will always have this exact structure.