Loading video player…

Route Each Flag to an Action

A moderation flag names a kind of harm, as a category with a score. Your flagsFor() from the last lesson raises one for each category whose score reaches its threshold.

A flag doesn’t say what the assistant should do. Course 3’s emergency check still runs first, so an emergency gets the rescue number alone and never reaches moderation. After it, if every flag gets the same refusal, a person in crisis is turned away, and nobody at the warden’s desk hears about a threat.

Key Points

  • Each category gets its own action, in a table in your code that names each category exactly as your thresholds name it. A self-harm/intent flag gets crisis resources instead of a refusal. The reply is a crisis line from config and a short supportive message, and the model isn’t called. A violence flag goes to a person at the warden’s desk, and harassment gets a short blocking message. How the handoff to the warden’s desk works comes later in the course.
  • None of the last lesson’s labeled warden threats reaches the desk. The English threat says “hurt”, so the emergency check sends it the rescue number alone. The German, Italian and French versions are flagged only for harassment and blocked. Save them with your known misses in evals/adversarial/.
  • The first matching row wins. A row matches a flag with its category, and the rows are checked from top to bottom, so their order is the priority when a question raises two flags. None of these actions sends the question to the model. A flag with no row is blocked too, and a question with no flags goes to the model as usual.
  • Routing a batch gives you a count per action. Eight July questions, with flags from your thresholds recorded on December 2, 2026, came out as four answered, and one each for the rescue number, crisis resources, a person and a block. A threat that raised both harassment and violence went to a person, because the violence row sits higher. Eight questions is a toy batch, but the same code routes a whole season.
  • Moderation checks harm, not instructions. Two of the four answered questions were attacks. One told the assistant to ignore its instructions, and the other gave it a new role with no rules. Neither holds harmful content, so both passed untouched. Catching them takes checks in your own code, which the next section, Guarding Answers in Code, starts building.

Final Code

Like the rescue number, the crisis line comes from config.

Language: JavaScript Filename: guards/actions.js
export const ACTIONS = [
  { category: "self-harm/intent", action: "crisis" },
  { category: "violence", action: "person" },
  { category: "harassment", action: "block" },
];

export function chooseAction(flags) {
  for (const row of ACTIONS) {
    if (flags.some((f) => f.category === row.category)) {
      return row.action;
    }
  }
  return flags.length > 0 ? "block" : "answer";
}

A script runs the emergency check and then chooseAction() on each recorded question, and counts the actions. The script, scripts/route-batch.js, and the batch, data/july-batch.json, are in the code download. Run it with node scripts/route-batch.js, and its last line is the count:

Language: Text
{ answer: 4, rescue: 1, crisis: 1, person: 1, block: 1 }

Next, in Exercise: Set Moderation Thresholds, you’ll write the policy yourself, choosing a threshold and an action for each category and deciding what happens when the moderation call fails.

00:00 In the last lesson, your flags function turned moderation scores into flags. Each flag has a category and a score. Course 3’s emergency check still runs first, so an emergency gets the rescue number alone.

00:15 However, a flag only names a kind of harm. It doesn’t say what the assistant should do next. Right now, every flag gets the same refusal.

00:26 Here are three flagged questions from July. One hiker writes that they want to end it all, another threatens the warden at hut 6, and a third insults the wardens.

00:38 All three get the same refusal. The person in crisis is turned away, and nobody at the warden’s desk hears about the threat.

00:48 So each category gets its own action. A table in a new file in the guards folder lists them. Each row names a category exactly as your thresholds name it, and the action it leads to.

01:01 A self-harm flag gets crisis resources instead of the refusal. The reply is a crisis line from config and a short supportive message, and the model isn’t called.

01:12 A violence flag goes to a person at the warden’s desk. How that handoff works comes later in the course. For now, it’s a label. Harassment is blocked with a short message.

01:26 Now look at the last lesson’s labeled questions. The English threat to a warden says “hurt”, so the emergency check sends it the rescue number alone. The German, Italian and French versions are flagged only for harassment and blocked.

01:40 So the desk hears none of them. Save them with your known misses in your adversarial evals.

01:48 A function below the table picks the action. A row matches when a flag has its category. The rows are checked from top to bottom, and the first match wins.

01:58 So when a question raises two flags, the order of the rows is the priority. None of these actions sends the question to the model. If you add a category to your thresholds and forget its row, its flag is blocked too.

02:12 With no flags at all, the question goes to the model as usual.

02:19 Now route a batch of eight July questions through it. Their flags come from your thresholds and are recorded, so your run matches this one. Eight questions is a toy batch, but the same code routes a whole season.

02:33 The ford and the last lesson’s splinting question raise no flags, so they go to the model. The partner whose knee is bleeding never reaches the table. The emergency check sends the rescue number alone.

02:48 The hiker in crisis gets crisis resources. The threat raises two flags, and violence sits higher in the table, so it goes to a person. The insult is blocked.

03:01 The last two have no flags, so they go to the model too. A script runs the same checks on each recorded question and counts the actions. Four were answered, and one each got the rescue number, crisis resources, a person and a block.

03:18 Look at the answer lane again. Two of its four questions are attacks. One tells the assistant to ignore its instructions. The other gives it a new role with no rules.

03:30 Watch out: moderation looks for harmful content, and these two hold none. So both pass untouched. Catching them takes checks in your own code, and the next section, Guarding Answers in Code, starts building them.

03:46 A flag tells you the kind of harm. Your table decides what the assistant does about it. Here, eight questions led to five different outcomes, and both attacks went through.

03:59 Next, in Exercise: Set Moderation Thresholds, you’ll write the policy yourself, choosing a threshold and an action for each category and deciding what happens when the moderation call fails.

Become a Member to join the conversation.