Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Structured Output From Language Models (Summary)

In this video, you replayed one real run of the clinic’s intake over the twelve booking notes, and looked back at the steps of the course behind each part of it.

What You Can Do Now

You can now write a prompt that turns messy text into data, get the answer as JSON that matches a schema, check it with Zod, and retry or fall back when it’s wrong, through askForJson() in the model module, for OpenAI or Anthropic.

One Morning’s Intake

Here’s one real run of node --env-file=.env run-intake.js on December 1, 2026, with one provider’s capable model. Your records, wording, and cost will differ:

Language: Program Output
12 notes, capable: 3.062 cents
to book: 9
front desk: 3
  #6 the clinic doesn't treat corn snake
  #7 date 2026-11-30 is before today
  #8 not a booking
saved intake-2026-12-01.json

Nine notes passed every check. Three went to the front desk’s list: Noodle, a corn snake the clinic doesn’t treat, Rolo, booked for a date that’s already passed, and a one-word note, “help”. The run cost about three cents. No answer needed a retry in the finished intake’s runs.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 You’ve reached the end of Structured Output From Language Models. You can now write a prompt that turns messy text into data, get JSON that fits a schema, check it with Zod, and retry or hand off when it’s wrong.

00:14 It all goes through askForJson(), with either provider.

00:20 Here’s one real run of your intake, replayed. Yours will differ.

00:25 Nine notes passed every check. Three went to the front desk. Noodle’s a corn snake the clinic doesn’t treat, Rolo wants a past date, and a one-word note says help.

00:38 The run cost about three cents. No answer needed a retry in the finished intake’s runs.

00:46 Each part came from a step. The prompt keeps the instructions apart from the note, and your code supplies today’s date. In one provider’s runs, a faster model cost about half, and missed a date now and then.

01:00 JSON asked for in the prompt broke a run, so askForJson() sends a schema instead. Zod checks every answer’s shape. Your checks catch a date that’s passed, or a pet the clinic doesn’t treat.

01:14 Only an answer that’s invalid or isn’t JSON gets one retry, with the error. Anything else you can’t book goes to the front desk’s list. Things to remember.

01:27 Keep instructions apart from data. Test a prompt on every note, more than once. Pick a model by trying your real inputs. Send a schema, and still check each answer.

01:39 A valid record can still be wrong. Retry an invalid answer once with the error, then ask a person.

01:48 This course is the second of five on building AI features in JavaScript. The next one streams answers to a web page, and your model folder comes along. Thanks for following along.

Become a Member to join the conversation.