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

Measure What a Guardrail Blocks

In this lesson, you measured the held request from Place Guardrails Around the Stream and the Cache like a feature: what it lets through, what it wrongly blocks, how long hikers wait for the first words, and what its judge costs.

Key Points

  • Recorded runs, December 2, 2026. Every number below comes from them, on OpenAI, through the request as Place Guardrails Around the Stream and the Cache leaves it: input moderation before the call, the answer held, gate() with the checks span, and the eight-second deadline from Set a Time Budget.
  • Two kinds of cases. Thirty hiker questions in four languages got real answers in four runs, and all 120 answers were read and labeled right, so they must pass. Twelve wrong answers must be stopped: the seven from Check Answers in Code, the injected “open and safe” answer, and four more that state what no report says. They ran three times, for 36 cases. Every case went through the held request, eight-second deadline and all, in a replay with short answers and no beds lookups, which is lighter than the full app. Each run wrote one record per case to a results file: its case, its failed checks, any error, whether the deadline cut it, and its two times.
  • The script reads that file. A case was blocked when its list of failed checks isn’t empty.
  • A false negative is a wrong answer the gate lets through. Here, positive means the guardrail fired. None of the twelve got through, in any run. Twelve handwritten answers is a small set, though. Zero means none of these got through. A wrong answer you didn’t write still could.
  • A false positive is a right answer the gate blocks. With the judge’s three-second limit, it blocked 88 of 120. Fifteen were right answers saying there’s no report, blocked for words like “open” or “storm”. Seventy-two waited on a judge that took longer than three seconds, and one hit the deadline. All 88 hikers got the latest reports instead.
  • One run can’t give you the rate. The judge’s timeouts ranged from 10 to 22 per run of thirty.
  • Holding the stream moves the first words. Streamed, half the answers in this replay would start within a second and 95 percent within 1.4. That includes input moderation before the call, about a tenth of a second on OpenAI’s free endpoint. On Anthropic, moderation is a billed call to the fast model, for the question and again for the answer, so time and price both there. Held, the hiker sees nothing until the whole answer and its checks are done: p50 4.7 seconds, p95 6.1.
  • A longer judge limit trades one number for another. At six seconds, still none of the twelve got through. The word checks stop half the 36, and the judge’s own fail verdict stopped the other 18. At three seconds, the timer had stopped three of those. Wrongly blocked fell to 19 of 120. Seventeen were for words, a few more than before, since every run gets fresh answers. Two were cut by the deadline. But the held p95 grew to 7.0 seconds.
  • The judge costs too: about 50 cents per thousand questions, half what the answers cost, at either limit, since a timed-out call is still billed. Moderation is free on OpenAI. On Anthropic, it’s a fast-model call per question and per answer.
  • The decision, and where it holds. On this replay, six seconds wins. It blocks 19 right answers instead of 88, and the p95 stays under eight seconds. But the full app is slower: its whole answers reach 6.4 to 6.9 seconds at the p95 in Make Answers Feel Fast. And in one of the three-second runs, most judge calls took over six seconds to finish. On the full app, more answers may hit the deadline, and each one is another wrong block. So rerun these cases there, on your provider, before you ship. Then watch the first words’ p95, the blocks per check, and the judge timeouts in your traces.
  • The rule: measure a guardrail like a feature. Count what it lets through and what it wrongly blocks, time the wait it adds, and price its calls, on cases that must pass and cases that must stop, more than once.

Final Code

Save this as scripts/guard-evals.js. It reads a results file, given as its argument, with one record per case run. A record’s cut is true when the eight-second deadline cut the answer. percentile() is the same as in scripts/latency.js:

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 In Place Guardrails Around the Stream and the Cache, you held every answer until its checks passed. Before the wardens put that on their website, they’ll ask how often it’s wrong and how long hikers wait.

00:12 Start with cases. Thirty hiker questions in four languages got real answers in four runs. All hundred and twenty answers were read and labeled right, so they must pass.

00:25 Then twelve wrong answers that must be stopped: the seven from Check Answers in Code, the injected answer, and four more that state what no report says. They ran three times.

00:38 Every case went through the held request, eight-second deadline and all. It’s a replay, not the full app: short answers and no beds lookups. Each run wrote one record per case.

00:52 A short script reads that file. A case was blocked when its list of failed checks isn’t empty. Run it on the three-second results. A wrong answer the gate lets through is a false negative.

01:05 Here, positive means the guardrail fired. None of the twelve got through, in any run. Twelve handwritten answers is a small set, though. Zero means none of these got through.

01:16 A wrong answer you didn’t write still could.

01:21 A right answer it blocks is a false positive. It blocked eighty-eight of a hundred and twenty.

01:28 Fifteen were right answers saying there’s no report, blocked for words like “open” or “storm”. Seventy-two waited on a judge that took longer than three seconds, and one hit the deadline.

01:40 All eighty-eight hikers got the latest reports instead.

01:45 Timeouts ranged from ten to twenty-two per run of thirty, so one run alone can’t give you the rate.

01:54 Now the wait. Each record also says when the first words were ready. Streamed, half the answers in this replay would start within a second, and ninety-five percent within 1.4.

02:07 That includes input moderation before the call, as Place Guardrails Around the Stream and the Cache has it. On OpenAI’s free endpoint, that’s about a tenth of a second.

02:17 On Anthropic, moderation is a billed model call, for the question and again for the answer, so time both there.

02:25 Held, the hiker sees nothing until the whole answer and its checks are done. The median moves to 4.7 seconds and the p95 to 6.1.

02:38 Most false positives came from the judge’s time limit. So raise it to six seconds and run everything again. Still none of the twelve got through. The word checks stop half the thirty-six, and now the judge’s own verdict stopped the other eighteen.

02:54 At three seconds, the timer had stopped three of those. Wrongly blocked falls to nineteen. Seventeen were for words, a few more than before, since every run gets fresh answers.

03:07 Two were cut by the deadline. But the held p95 grows to 7.0 seconds.

03:15 The judge costs about fifty cents per thousand questions, half what the answers cost, at either limit. A timed-out call is still billed.

03:25 So on this replay, six seconds wins. It blocks nineteen right answers instead of eighty-eight, and the p95 stays under eight seconds. But the full app is slower.

03:38 And in one of the three-second runs, most judge calls took over six seconds to finish. On the full app, more answers may hit the deadline, and each one is another wrong block.

03:49 So rerun these cases there, on your provider, before you ship.

03:56 So measure a guardrail like a feature. Count what it lets through and what it wrongly blocks, time the wait it adds, and price its calls, on cases that must pass and cases that must stop, more than once.

04:11 Next, in Exercise: Guard the Conditions Answer, you’ll guard the assistant’s conditions answers yourself and report what your guardrail blocks.

Become a Member to join the conversation.