How to prompt with JSON mode
JSON mode is typically used to format unstructured data. In the content workflow pipeline, data is gathered with online models, analyzed with reasoning models, and then JSON mode is used to extract that analysis.
Core reasons to use JSON mode
- Extract information from unformatted data
- Generate consistent response formats
- Categorize with a structured output
- Create a list that can be iterated over
How to use JSON mode
Prompts for JSON mode usually target simple technical and non-analytical tasks. Key requirements:
- Specify “output in this JSON format”
- Use the system role for instructions (apart from context) and the user role for content
- Consolidate prompt instructions in the system message
Example: Meta description with categorization
A test using the meta description example can include article categorization:
- Define categories (article, product, announcement, customer story)
- Include “output in this JSON format” with keys on the left and placeholders on the right
- Provide the article content in the user role
- Set the workflow step’s format to JSON
Other reasons to use JSON mode:
1. Extract multiple data points
JSON mode can return more than one piece of data in a single response, such as:
- Title
- Author
- Other desired fields
2. Reference structured data in future steps
Adding a text step allows each element of the JSON output to be referenced individually:
- Category
- Title
- Author
This structured data can also be passed to other systems like a CMS.