Specify required and optional keys
Use the opposite Shift key for paired punctuation. · 171 words
A good structured-output prompt first names every field the answer must contain. For example, ask an assistant to read one museum visit note and return one JSON object for that note. Specify required keys id, visitor, visit_date, and ticket_count; specify optional keys membership_id and exhibit_rating. Give the source inline: id: M-104; visitor: Ana; visit_date: 2025-03-08; ticket_count: 2; membership_id: M-88; exhibit_rating: 4. This makes the task concrete and gives the model enough information to produce the requested shape.
Then state what to do when an optional value is missing: omit its key rather than writing null, an empty string, or a guess. Also require valid JSON and no markdown. For the example, a checkable output is {"id":"M-104","visitor":"Ana","visit_date":"2025-03-08","ticket_count":2,"membership_id":"M-88","exhibit_rating":4}. A checker can confirm that all four required keys appear once, both optional keys appear because the source supplies them, and the values match the note. The checker should enforce the same distinction that the instructions give the model. An absent optional key can be correct, whereas an absent required key always fails this contract.
Check your recall
How should a prompt handle a required key and an optional key when the source lacks the optional value?
Check your answer
Every required key must appear in every output object. An optional key should be included when the source provides a value, but omitted when it does not. The checker should verify the required keys, allowed optional keys, and agreement between the output values and the source.
Sources and credits
Original KeyTouch lesson. Background reading · JSON Schema · Understanding JSON Schema.