AI & Automation free courses

Master the TrickFoundationFree

Prompt Engineering: Structured Outputs

Turn an ambiguous request into a structured prompt, validate the response and handle missing information.

3 reading lessons · about 30 min ·written by MTT

The idea

Describe the task, permitted source information and required output fields separately. A structured response makes downstream checks easier, but valid JSON does not imply correct facts. Decide which fields are required, which may be unknown and what an acceptable value looks like before asking a model to generate the response.

Worked example

A fictional support message says a parcel arrived damaged but gives no order number. Request fields for issue, orderId and needsFollowUp. The issue can be damaged parcel, orderId should be null and needsFollowUp should be true. A realistic-looking invented order number would fail the contract even if the JSON parses.

Try it

Write a prompt for classifying three fictional support messages. Define three output fields and their allowed values. Include one message with missing information and specify how unknown values must be represented. Check each output against the source, not just its shape.

Lesson 1 of 3 · About 10 min

Define the response contract

Check your understanding

Course quiz

Finish the course to unlock the quiz

Complete all 3 lessons and 5 questions open up here. You have 3 to go.

What you will learn

  • Specify a task and output schema
  • Use examples without leaking private data
  • Validate generated fields before using them

Before you start

Prerequisites
None. Exercises can be completed on paper or with an approved AI tool.
Cost
Free introductory reading lessons, exercises and quiz. Optional third-party tools, hosting or AI subscriptions may cost money.

Original introductory lessons and assessment by Master the Trick. Estimated times include the suggested exercises.