Advanced course for engineers

Structured output course: valid, typed data from models

Free text works in a demo. In production, a missing field, a wrong type or a plausible but invalid value breaks your code. This course replaces guessing with contracts and checks, from the schema to the stored row.

Open the courseTry the validator

The loop

One loop from the schema to the stored row

The intro video describes one loop with five stations. A failed check sends the reply back to the model.

Still from the intro video for the course Structured Output Validation & Reliable AI Interfaces
Intro video, 1 min 12 s. Transcript below.
Read the transcript

If your application parses model output and sometimes breaks on it, this course is for you. You will learn to get typed, valid, business-correct data out of a model and store it safely. Free text works in a demo. In production, a missing field, a wrong type, or a plausible but invalid value breaks your code. The course replaces guessing with contracts and checks. The course follows one loop. The model generates under a schema. Your code validates types and structure. Then business rules check that the data is correct. On failure, you retry or repair. Only valid, versioned data reaches storage. You finish by building a validated assessment service that brings every piece together. If you want model output your code can trust, start with the first chapter: why free text breaks software.

  1. 1

    The model generates under a schema

    The schema is the contract the reply has to meet.

  2. 2

    Your code validates types and structure

    Keys and types are checked before anything else.

  3. 3

    Business rules check the data is correct

    A reply can have the right shape and still be wrong.

  4. 4

    On failure, you retry or repair

    Send the reply back with the reason, or fix what is safe to fix.

  5. 5

    Only valid, versioned data reaches storage

    Data that reaches storage is valid and versioned.

A failed check sends the reply back

The course intro video with its transcript, then the five stations of the loop in a row, with a dashed way back from the checks to the model.

Chapters 1 and 2

Write the contract as a JSON Schema

Chapter 1 shows six ways free text breaks a parser and designs the contract. Chapter 2 covers JSON Schema essentials, five lessons. The card shows the lessons its rows use.

invoice schema(invented example)

  • customerstringLesson 1. required, not empty, and no other keys are allowed
  • itemsarray of objectsLesson 4. required, at least one item, each item uses the same sub schema
  • items[].namestringLesson 1. required, not empty
  • items[].centsintegerLesson 3. zero or more
  • total_centsintegerLesson 3. zero or more
  1. Types, required keys and extra keys

    Each key has a type, can be required, and extra keys can be refused.

  2. Enums and patterns

    A value can be limited to a list or to a pattern.

  3. Numeric and length limits

    Numbers and text can have a smallest and a largest value.

  4. Arrays and reuse

    A list has an item type, and a part of a schema can be reused.

  5. Choices and nullable fields

    A field can allow one of several shapes, or null.

An invented invoice schema as a card of typed rows, the same schema the six replies below are checked against. Each row carries the number of a lesson it uses.

Prompt engineering course →

Chapter 1

Three checks, run in order, and the first failure stops the run

The first chapter has a lesson on three layers of validity. This example runs three checks on an invented invoice reply.

Three checks on a reply

Invented replies for an invented invoice.

Pick a reply

The reply as the model sent it

{"customer":"Nora Test","items":[{"name":"Setup","cents":4200},{"name":"Support","cents":1550}],"total_cents":5750}
  1. 1. Parse the textPassed
  2. 2. Keys and typesPassed
  3. 3. Business rulePassed

All three checks passed. This reply may go on to storage.

Clean reply. All three checks passed. This reply may go on to storage.

  • 1Parse

    The text must be valid JSON.

  • 2Types and structure

    Keys and types must match the schema.

  • 3Business rules

    The values must add up and make sense.

Six invented replies for the invoice schema. Pick one to see which of the three checks stops it and why.
  • The rule in this example: first the text must parse as JSON. Then the keys and types must match the schema, with no extra keys and whole numbers for cents. Then the item cents must add up to total_cents. The first check that fails stops the run, and the checks after it do not run.
  • Money is counted in whole cents, so the sum is exact. A reply that passes all three checks has the right shape and the right arithmetic. It can still be wrong about the world, which chapter 4 returns to.

Chapter 4

Constrained generation fixes the shape, and the values still need checking

Chapter 4 looks at four ways to ask for structure and how to choose between them. One lesson has the title "Structure is not truth, and field order matters".

Reply(invented example)

"start": "2026-03-10T10:00",
"end": "2026-03-10T09:00"
  1. Parse: passedValid JSON.
  2. Types: passedBoth values are date times.
  3. Rule between fields: failedThe end is before the start.
  • How constrained decoding works

    The output is limited while it is generated, to keep the reply inside the schema.

  • Structure is not truth

    A reply can match the schema and still be wrong. The lesson also covers why field order matters.

  • Tool calling as structured output

    A tool call is another way to get named, typed fields back.

  • Choosing a method

    Pick the way to ask for structure that fits the job.

An invented appointment reply. It parses and its types are right, but a rule between two fields fails.

Model Context Protocol, tools and servers →

Chapters 5 and 6

Retry with the reason, repair only what is safe, and know when to stop

Chapter 5 covers business rules, integer cents and reason codes. Chapter 6 builds the retry loop around them.

(invented example)

  1. Attempt 1FailedSUM_MISMATCH

    The item cents do not add up to the total.

  2. Attempt 2PassedOK

    The corrected reply passes all the checks.

  3. LimitStopMAX_ATTEMPTS

    If the checks keep failing, the loop has to end somewhere.

The reason code goes back to the model with the reply

  • A retry loop

    Ask again when a check fails.

  • Telling the model what went wrong

    A reason code gives the model something to fix.

  • Safe and unsafe repairs

    Some fixes are mechanical. Others change what the data means.

  • When to stop

    A loop needs an end.

  • Measuring the loop

    Count how often a reply needs a retry.

An invented run. The first attempt fails with a reason code, the reason goes back to the model, the second attempt passes, and a stop marker shows where a loop must end.

Chapters 7 and 8

Version the schema, store safely, and review the capstone

Stored data outlives the code that wrote it. Chapter 7 covers compatible and breaking changes, migrating money and auditability. The capstone is a validated assessment service.

(invented example)

  1. Version 1

    • customer
    • total_cents
    Stored rows
  2. Compatible changeA new optional field. Old rows still fit.
  3. Version 2

    • customer
    • total_cents
    • note
    Stored rows
  4. Breaking changeA key is renamed. Old rows no longer fit.Migrate stored rows
  5. Version 3

    • client
    • total_cents
    • note
    Stored rows

Capstone: a validated assessment service

  1. 1The contract

    Write the schema the service promises to meet.

  2. 2The consistency rule

    State which values must agree with each other.

  3. 3Retry policy

    Decide how many tries a reply gets and what happens next.

  4. 4Storage and migration

    Store versioned rows, and move old rows when the schema breaks.

  5. 5Acceptance review

    Check the whole service against the contract.

Open the course: Structured Output Validation & Reliable AI Interfaces

An invented record in three versions. A compatible change leaves old rows readable. A breaking change needs a migration of the stored rows.

Hallucination detection course: check claims, not shape →

Questions about the course

  • What is structured output in this course?

    Typed, valid, business correct data that a model returns and your code can trust, as the course description puts it.

  • Who is the structured output course for?

    Software engineers and technical product people who build AI features are the audience the catalogue names.

  • What level is it?

    It is an advanced course, as the catalogue lists it.

  • What will I learn?

    Six outcomes: why free text breaks software, JSON Schema essentials, typed models and validation, constrained and structured generation, semantic and business rule validation, and retry and repair strategies.

  • What do I build at the end?

    The capstone is a validated assessment service: the contract, the consistency rule, a retry policy, storage with a migration, and an acceptance review.

  • How big is the course?

    The outline has 40 lessons in eight chapters, and the capstone closes it.

  • Is there a certificate?

    The course comes with a certificate, or a confirmation of participation, depending on how you went through it. It is not a state-recognized qualification, and the PDF is on your learning page.

  • Can the AI coach tell me if I will be certified?

    No. Your levels come from graded work under fixed rules. The coach has no say in them and cannot predict the outcome.