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

Catch Valid but Wrong Records

In this video, you printed the fields the front desk books from and found two records that matched the schema but couldn’t be booked. Then you wrote checkRecord() to check each record against today’s date and the clinic’s data, its species and its opening hours, and flagged the two in the intake script.

Key Points

  • Every note came back as a record. With the species, preferred date, and preferred time printed after the kind, all twelve notes came back from askForJson() as records, and no note was held back. Every one of them matched the schema.
  • Rolo’s date has already passed. Today, in the video’s run, is December 1, 2026. Rolo’s owner asked for “yesterday afternoon”, and the model wrote that date down: 2026-11-30. It’s a real date in the right format, and it has already passed.
  • The clinic doesn’t treat Noodle. Noodle is a corn snake, and data/clinic.json lists the species the clinic treats: dogs, cats, rabbits, guinea pigs, and ferrets. The note asks for an appointment, so its kind is "booking". And the prompt keeps any species the clinic doesn’t treat as the owner wrote it, so here it’s "corn snake".
  • Output varies. Your run’s wording will differ. In nine runs of the set behind this video, all with one provider, these two records came back this way every time.
  • A schema checks the shape, not the truth. Here’s Rolo’s whole record from the run, next to what the schema allows for each field. Every field matches:
Field Value The schema allows
kind "booking" "booking" or "not_a_booking"
species "guinea pig" a string or null
petName "Rolo" a string or null
problem "Frequent sneezing" a string or null
urgency "soon" "routine", "soon", "urgent", or null
preferredDate "2026-11-30" a string or null
preferredTime "afternoon" a string or null
  • Two kinds of rule. This schema says what each value must look like, not whether a date has passed or the clinic treats a species. Your prompt gives the model today’s date and the clinic’s species to write the record, not to check it, and the model did what the prompt asked. It worked Rolo’s date out from the note and wrote Noodle’s species as the owner wrote it.
  • The model’s job and your code’s job. The schema leaves the species open on purpose. Writing down what the note says is the model’s job. Deciding whether the clinic can book it is your code’s.
  • Compare dates as text. A date written as year, month, then day, with two digits for the month and the day, sorts the same way as text, so the less than operator compares two of them as dates. The comparison only works on a real date written that way, and nothing checks that yet.
  • Look the species up. The second check looks for the record’s species in the clinic’s list with .includes(), one of the array methods the Functions You Can Pass Around course works with. Corn snake isn’t there, so it adds a problem. Both checks skip a null, because the note didn’t give that value.
  • Compare times with the opening hours. The clinic can’t book outside its opening hours either. So the third check takes a clock time, with a colon after a two-digit hour, like 10:00, and compares it with the opening hours, as text again. That’s why it looks for ":" at index 2. It skips any other time, like morning. No note in this set asks for a time outside the hours, so it flags nothing here.
  • Flag each failing record. The intake script calls checkRecord() after printing each record and prints any problems under it as flagged. It doesn’t send the record anywhere yet. In the run below, Noodle is flagged for the species and Rolo for the date, and the other ten records pass all three checks.
  • A later day flags more. The notes’ dates don’t change, but today comes from your clock. Run the script on a later day, and more dates are flagged as before today. That’s the check working.

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 Your intake script now gets a record for each note from askForJson(), or a reason to hold the note back. The front desk books from three of its fields: the species, the preferred date, and the preferred time.

00:14 Take those three from the record, and print them after the kind. Run the set, and all twelve notes come back as records, none held back. Every one of them matched the schema.

00:28 But read them against what the clinic knows. Today, in this run, is the first of December. Note seven is Rolo, a guinea pig, booked for the thirtieth of November.

00:38 That was yesterday. Rolo’s owner asked for yesterday afternoon, and the model wrote that date down. It’s a real date in the right format, and it has already passed.

00:52 Now note six, Noodle, a corn snake. The clinic’s file lists the species it treats: dogs, cats, rabbits, guinea pigs, and ferrets. No snakes. The note asks for an appointment, so its kind is booking.

01:08 And the prompt keeps any species the clinic doesn’t treat as the owner wrote it, so here it’s corn snake. Booked as they are, Rolo would get a slot in the past, and Noodle a clinic that doesn’t treat snakes.

01:22 Your run’s wording will differ, but in nine runs of the set with one provider, these two came back this way every time.

01:31 Rolo’s record, next to what the schema allows, shows why they passed. The species and the date can each be a string or null. Both are strings, so every field matches.

01:43 This schema says what each value must look like, not whether a date has passed or the clinic treats a species. Your prompt gives the model today’s date and the clinic’s species to write the record, not to check it.

01:56 The model did what the prompt asked.

01:59 The schema leaves the species open on purpose. Writing down what the note says is the model’s job. Deciding whether the clinic can book it is your code’s. Add a file, check-record.js, with one function.

02:15 It takes a record, today’s date, and the clinic’s data, and returns a list of problems, empty when it finds none.

02:23 The first check compares the preferred date with today. A date written as year, month, then day, with two digits for the month and the day, sorts the same way as text.

02:34 So the less than operator compares two of them as dates. The comparison only works on a real date written that way, and nothing checks that yet.

02:46 The second check looks for the record’s species in the clinic’s list. Corn snake isn’t there, so it adds a problem. Both checks skip a null, because the note didn’t give that value.

02:59 The clinic can’t book outside its opening hours either. So the third check takes a clock time, with a colon after a two-digit hour, like ten o’clock, and compares it with the hours, as text again.

03:12 It skips any other time, like morning. No note in this set asks for a time outside the hours, so it flags nothing.

03:21 In read-notes.js, import the function and call it after each record is printed. Any problems it returns are printed under the record as flagged, and not sent anywhere yet.

03:34 Run the set again. Noodle is flagged for the species, and Rolo for the date. The other ten pass all three checks. On a later day, more dates are flagged. Today comes from your clock, and the notes don’t change.

03:48 That’s the check working.

03:52 A record that matches the schema has the right shape. Whether its values are true is for your code to check. The date check needs a real date written the right way, and the schema only says it’s a string.

04:06 Next, in the lesson Check Every Record With Zod, you’ll write the record’s shape rules once, for the request and for the check.

Become a Member to join the conversation.