Loading video player…

Tools, Guardrails and Evals for AI Features (Overview)

Welcome to Tools, Guardrails and Evals for AI Features! A language model only generates text. It can’t look up how many seats are left on a ferry or move a booking, and it has no way to check what it says against your data.

In this course, you describe your own functions to the model as tools. The model asks to call them, and your code decides what actually runs. Then you measure the feature with evals, so you can check whether a change made it better before you switch.

What You’ll Build

The course follows Linden Ferries, a small island ferry company whose phone line is busy every summer with the same questions about when the boats leave, whether there’s room for a car, and whether a booking can move. The company wants a booking assistant in its passenger chat that answers from its seven sailings and a dozen bookings, and changes a passenger’s booking when they ask.

A wrong change can cost a family its crossing, and one booking’s note tells the assistant to cancel every booking. So the model only asks for changes. Your code checks each one, shows the passenger exactly what will change, and runs it only after a yes.

Here’s a first taste from one real run, with the usage lines left out and the long lines wrapped for display. Amara asked to move her booking LF-2417 to Sunday morning and add her brother. Your wording will differ:

Language: Program Output
$ node --env-file=.env assistant.js \
    "Please move LF-2417 to LF103 on Sunday morning and add my brother, so there are three of us."
call: lookUpBooking { reference: 'LF-2417' }
call: changeBooking {
  reference: 'LF-2417',
  sailingId: 'LF103',
  passengers: 3,
  vehicle: null,
  cancel: false
}
Change booking LF-2417:
  sailing: LF102, 2026-12-05 14:30 → LF103, 2026-12-06 08:00
  passengers: 2 → 3
Make this change? (yes/no) yes
answer: All set! Booking LF-2417 is now on Sunday morning’s LF103 sailing
for three passengers. The note that you’re traveling with a dog is still
on the booking.

The model asked to look the booking up, then asked for the change. Your code showed Amara exactly what would change and waited. Only after her yes did the change run.

What You’ll Learn

By the end of this course, you’ll be able to let a model call your own functions and keep those calls safe by checking arguments, confirming changes, and limiting each feature to its own tools. Those guards limit what an instruction hidden in your data can make the assistant do. You’ll also be able to measure a feature with an eval set before and after a change.

Step by step, you’ll:

  • Let a model call your functions by describing them as tools, running the loop that answers every call the model asks for, and adding askWithTools() to your model/ module
  • Keep tool calls safe by checking each call’s arguments in your code, confirming changes with the passenger, choosing which tools and limits each feature gets, and finding where untrusted text gets into a request
  • Measure the feature with evals by writing cases and checks, running each case more than once, grading open answers with a rubric, and comparing two versions before you switch
  • Put it all together in a project where you build the booking assistant from a brief, with no walkthrough, and use its evals to check that a change made it better

Before You Start

This is the last of five courses on building AI features in JavaScript. It builds on a small model/ module that sends your requests to OpenAI or Anthropic. Its ask(), askForJson(), and streamAnswer() functions come from the four courses before this one, and this course adds askWithTools().

If you’re starting here, you don’t need to have built the module. The course’s code download has the starting project with model/ ready, along with the ferry company’s sailings, bookings, and passengers.

You should already know async functions with await, how to handle a failed request with retries, JSON, and Node.js scripts with npm packages.

You should also know how to call a model and read its token usage, check its JSON output with a schema, and send a conversation as a history of messages. The path’s first four courses teach these: Calling a Language Model From JavaScript, Structured Output From Language Models, Streaming AI Answers to a Web Page, and Answering Questions From Your Own Documents.

You’ll need:

  • A current Node LTS, a terminal, and any editor. The course’s runs used Node v26.14.0.
  • A key for one model provider, OpenAI or Anthropic, for the lessons and the project that call a real model. Copy the starting project’s .env.example to .env, set MODEL_PROVIDER to openai or anthropic, and put your key there. The commands run with node --env-file=.env. Keep .env out of your repository. If the folder’s .gitignore doesn’t list it, then add it.

In the course’s runs, which went to OpenAI, one run of an eval case cost 0.2 to 0.4 cents, and comparing two versions of the assistant on the project’s eval set cost about a dollar. With Anthropic, your token counts and costs will differ, so check your own usage. A monthly spending limit with your provider, such as five dollars, leaves room to rerun the examples.

How the Course Works

  • Text lessons carry most of the course, and you build the assistant’s pieces in the ferry company’s project as you type along. Most of the code is the same for either provider, because model/ handles the difference. Where provider code does differ, in the first lessons, you open the version for your provider.
  • Four video lessons show the tool-calling loop, a change waiting for the passenger’s yes, where untrusted text gets in, and each eval case run more than once.
  • Four coding exercises run in your browser on a stand-in model, so they need no key. Their tests check what your code does with the stand-in’s responses.
  • A project gives you the assistant’s brief and its eval cases, which you pass in the last exercise and then run against your real provider with your key. Next, a mentor review has you explain your assistant and make a change you haven’t seen. Then you plan and build a feature of your own with the mentor. A quiz checks what you’ve learned, and a short summary video closes the course.
  • Downloads include the starting project and the finished code.

The next lesson, Describe a Tool and Read the Request, sets up the ferry company’s project and gives the model its first tool.

Download

Course Slides (.pdf)

549.4 KB
Download

Sample Code (.zip)

215.4 KB

00:00 Welcome to Tools, Guardrails and Evals for AI Features. On its own, a model only writes text. Here, it asks to call your functions, and your code decides what runs.

00:12 Then evals show whether a change helped.

00:17 Here’s one real run of the assistant you’ll build. Amara wants to move her booking and add her brother. The model asks to look it up, then for the change. Your code shows her exactly what will change, and waits.

00:33 Only after her yes does it run.

00:38 Linden Ferries’ phone line is busy every summer, with the same questions about times, cars and changes. Its assistant answers passengers in a chat, from its sailings and bookings.

00:50 A wrong change can cost a family its crossing. And one booking’s note says to cancel everything.

00:59 You’ll describe functions as tools and answer the model’s calls in a loop. You’ll guard those calls by checking arguments, confirming changes and limiting tools, so an instruction in a booking’s note can do less.

01:12 You’ll write evals and compare two versions. Then you’ll build the assistant from a brief, with no walkthrough.

01:20 This is the last of five courses on AI features. It builds on a module that sends requests to OpenAI or Anthropic. If you’re starting here, the code download has it.

01:32 The text below says where to learn what’s on this list. You’ll need a current Node, and one provider’s key for the real runs.

01:43 Most lessons are text. Four are videos. Four coding exercises run in your browser, with no key. The last is the ferry project. Then you plan and build a feature of your own with the mentor.

01:57 Next, in Describe a Tool and Read the Request, you’ll give the model its first tool.

Become a Member to join the conversation.