Um momento
0x30Lesson 4 of 6

Request structured, usable outputs

Specify schemas and constraints, then validate generated results in code.

12 min 5-question quiz
By the end of this lesson you can
  • Design an output contract and explain why generated data needs validation.

When another program will consume a response, define a simple output contract: required fields, allowed values, and what to do when a value is unknown. A model can be asked to return JSON or another format, but a prompt alone does not guarantee valid structure. Parse and validate the output before using it, and handle missing fields or invalid values safely.

A small example

Illustrative Python
1record = {"title": "Meeting", "date": "2026-10-02"}
2required = {"title", "date"}
3valid = required.issubset(record)
4print("valid record" if valid else "missing fields")
Output
valid record

For supported model APIs, schema-constrained output features can enforce more structure than plain text instructions. Even then, check semantic requirements such as whether a date is plausible or supported by the source. Keep user-facing presentation separate from machine-readable fields where possible.

Key takeaways

  • Design an output contract and explain why generated data needs validation.

  • Test prompts on realistic inputs and validate important outputs in software.

Lesson quiz

5 questions · pass with 4 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…

Gostou da aula? 😆👍
Apoie nosso trabalho com uma doação: