Lesson 1.3

Structured output and JSON schemas

Parsing prose with a regular expression works until the day it does not.

31mIntermediate14.4k students

Overview

Text is not an interface

Parsing prose with a regular expression works until the day it does not. Asking for output against a schema makes the shape part of the contract, and gives you a real object to hand to the rest of your code.

Validate anyway. A schema constrains structure, not meaning: a required field can still come back as an empty string, and a date can still be nonsense.

Schema design affects accuracy. Flat schemas with descriptive field names and small enums are filled correctly far more often than deeply nested ones with abbreviated keys.

In this lesson you will:

  • Constrain the model to a schema
  • Validate the response before using it
  • Design a schema that is easy to fill correctly

Resources

Previous Lesson
Next Lesson
Structured output and JSON schemas — Building LLM Applications — Vertex