Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Lesson 13 · 50 minutes

Run a triage copilot with human review and measure its errors

After this lesson you can
  • Build a copilot loop that proposes a verdict with evidence and waits for a person
  • Write a review record for every alert, and make a rule for which alerts a person must read
  • Measure the errors of the copilot with and without review against the true labels
Lab files of this lesson (54)

The lab folder as it stands after this lesson. Unzip it in ~/krlab.

More

The zip holds every file that the course has printed up to here. To start this lesson with the files of the earlier lessons only, take the zip of the lesson before. Type the code yourself first: you learn more.

Scenario

The SOC wants a copilot for the night shift. It reads each alert, proposes "close" or "escalate" with the evidence, and a person confirms. Your lead has two worries: "Nobody can read 1,000 alerts a week, so which ones does a person see? And when the person is tired, does the review still help?" You build the loop, write down every decision, and measure the errors on the fixed week.

Recall

Lesson 9: what are the three outcomes of the gate for a suggested action?

Allow (it may run), approval (it waits for a named person) and refuse (it is not on the allowlist, or its arguments are bad). The copilot of this lesson uses the same idea for verdicts: a model proposes, and a person or a fixed rule decides.

Lesson 2: why is the cut-off 0.5 not a safe choice for auto-closing?

It is a default of the library. At 0.5 the model closes 955 alerts and misses 17 real incidents. The threshold must come from a rule about risk.

The idea

A copilot is a helper that works with a person, in a loop: it reads an alert, makes a proposal (a verdict and the evidence behind it), and waits. The person accepts the proposal or reverses it. The decision goes into a review record, so that anyone can later ask who decided, with which evidence, and what the model said.

The copilot proposes, a person decides
Alert feedCopilotReviewLaterAlertsCopilotReviewerReview recordError report12345Alert feedCopilotReviewLaterAlertsCopilotReviewerReview recordError report12345
  1. Alerts → Copilot: a score, a verdict and evidence
  2. Copilot → Reviewer: score 0.02 or more: accept or reverse
  3. Copilot → Review record: below 0.02: closed by rule
  4. Reviewer → Review record: one line for each alert
  5. Review record → Error report: errors against the labels

Two numbers set the work. ESCALATE_FROM is the score at or above which the copilot proposes "escalate". It is 0.20, a choice and not a law: in the table of lesson 2 it is the largest threshold before the misses of the copilot alone rise above 15, and the row "copilot alone" in step 3 is the 0.2 row of lesson 2, not the 0.5 row. REVIEW_FROM is the score at or above which a person must decide. It is 0.02, the threshold that lesson 2 chose on week 4. Below REVIEW_FROM the alert closes by itself, and that is the same silent risk that lesson 2 counted. The review rule is a trade: a lower REVIEW_FROM means more reading and fewer silent misses.

Two errors are measured against the labels, as in lesson 2. A missed incident is a real incident whose final verdict is "close". A false alarm is a harmless alert whose final verdict is "escalate". The final verdict is the one after the person has had their say.

Worked example

1. Save the copilot

Save copilot.py. propose makes the proposal: a dictionary with the id, the score, the verdict and a list of evidence made of plain facts from the alert fields. {**p, "reviewed": True} copies the dictionary p and adds or changes keys. review shows the proposal to a person through the function ask, which returns y (accept) or n (reverse). input(prompt) waits until the user types a line. simulated_reviewer stands in for a person on the whole week: it knows the true label and is wrong on every twentieth alert, as a tired person is. nonlocal count lets the inner function change the variable count of the function around it. sys.argv holds the words typed after the program name.

copilot.py

"""copilot.py: read an alert, propose a verdict with evidence, and wait for a human.

    python3 copilot.py ask 3       you review the first 3 proposals that need a person
    python3 copilot.py week        a simulated reviewer works through the fixed week; errors are measured
"""
import json
import sys

from gen import alerts
from triage import scores, train

ESCALATE_FROM = 0.20     # a score at or above this: the copilot proposes "escalate"
REVIEW_FROM = 0.02       # a score at or above this: a person must decide. Below it, the alert closes by itself.


def propose(alert, score):
    """A proposal is a verdict and the evidence behind it. It is only a suggestion."""
    evidence = [f"score {score}"]
    for text, test in (("off-hours", alert["hour"] < 6 or alert["hour"] >= 20), ("admin account", alert["admin"]),
                       ("external source", alert["ext_src"]), ("critical asset", alert["asset"] == 3),
                       ("new source for this user", alert["new_source"])):
        if test:
            evidence.append(text)
    return {"id": alert["id"], "score": score, "verdict": "escalate" if score >= ESCALATE_FROM else "close",
            "evidence": evidence}


def needs_review(p):
    return p["score"] >= REVIEW_FROM


def other(verdict):
    return "close" if verdict == "escalate" else "escalate"


def review(p, ask):
    """Show the proposal to a person. ask(p) returns "y" to accept it or "n" to reverse it."""
    accept = ask(p) == "y"
    return {**p, "reviewed": True, "human": "accept" if accept else "override",
            "final": p["verdict"] if accept else other(p["verdict"])}


def auto(p):
    return {**p, "reviewed": False, "human": None, "final": p["verdict"]}


def ask_person(p):
    return input(f"{p['id']}  proposal: {p['verdict']}  evidence: {', '.join(p['evidence'])}\n  accept? [y/n] ").strip().lower()


def simulated_reviewer(labels, sees_all=True):
    """A reviewer who knows the true answer, but is wrong on one alert in twenty.
    With sees_all=False the reviewer accepts every proposal to close: a quiet incident looks harmless to a person."""
    count = 0

    def ask(p):
        nonlocal count
        count += 1
        right = "escalate" if labels[p["id"]] else "close"
        agree = (p["verdict"] == right) != (count % 20 == 0)
        return "y" if agree or (not sees_all and p["verdict"] == "close") else "n"
    return ask


def errors(records, labels):
    missed = sum(r["final"] == "close" and labels[r["id"]] for r in records)
    false_alarms = sum(r["final"] == "escalate" and not labels[r["id"]] for r in records)
    return missed, false_alarms


if __name__ == "__main__":
    week = alerts(5)
    props = [propose(a, s) for a, s in zip(week, scores(train(), week))]
    labels = {a["id"]: a["label"] for a in week}
    if sys.argv[1:2] == ["ask"]:
        todo = [p for p in props if needs_review(p)][:int(sys.argv[2])]
        for p in todo:
            print(json.dumps(review(p, ask_person)))
        sys.exit()
    ask = simulated_reviewer(labels)
    records = [review(p, ask) if needs_review(p) else auto(p) for p in props]
    with open("review.jsonl", "w") as f:
        f.writelines(json.dumps(r) + "\n" for r in records)
    alone = [auto(p) for p in props]
    print(f"{'':22}{'missed':>8}{'false alarms':>14}{'read by a person':>18}")
    for name, rows in (("copilot alone", alone), ("copilot + review", records)):
        m, f = errors(rows, labels)
        print(f"{name:22}{m:>8}{f:>14}{sum(r['reviewed'] for r in rows):>18}")
    print("real incidents in the week:", sum(labels.values()))
    print("overridden by a person:", sum(r["human"] == "override" for r in records))
    print("assumes: a reviewer who recognises every real incident that they read, and errs on 1 alert in 20")

2. Review three proposals yourself

ask 3 shows the first three alerts that need review and waits for you to type y or n after each. On this page the three answers are given by a pipe, so type your own on your machine. Your answers can differ, and the output has no check.

printf 'y\nn\ny\n' | python3 copilot.py ask 3
W5-0001  proposal: close  evidence: score 0.0229, new source for this user
  accept? [y/n] {"id": "W5-0001", "score": 0.0229, "verdict": "close", "evidence": ["score 0.0229", "new source for this user"], "reviewed": true, "human": "accept", "final": "close"}
W5-0006  proposal: close  evidence: score 0.0653, off-hours, new source for this user
  accept? [y/n] {"id": "W5-0006", "score": 0.0653, "verdict": "close", "evidence": ["score 0.0653", "off-hours", "new source for this user"], "reviewed": true, "human": "override", "final": "escalate"}
W5-0016  proposal: escalate  evidence: score 0.9687, off-hours
  accept? [y/n] {"id": "W5-0016", "score": 0.9687, "verdict": "escalate", "evidence": ["score 0.9687", "off-hours"], "reviewed": true, "human": "accept", "final": "escalate"}
A proposal and what the person did
W5-0006alert idscore 0.0653the model's scoreclosethe proposaloff-hours, new sourcethe evidenceoverridethe person reverses itescalatethe final verdictW5-0006alert idscore 0.0653the model's scoreclosethe proposaloff-hours, new sourcethe evidenceoverridethe person reverses itescalatethe final verdict

Each result is a line of JSON: the proposal and what the person did. This is the review record. The second alert was a proposal to close with a score of 0.0653, and the answer n reversed it to "escalate". Read the evidence that the copilot gave: "off-hours" and "new source for this user" are facts, and the score is a number. The copilot gives no story, so the person has nothing to believe, only to check.

3. Run the whole week

python3 copilot.py week
                        missed  false alarms  read by a person
copilot alone               15            11                 0
copilot + review            10             9               254
real incidents in the week: 59
overridden by a person: 31
assumes: a reviewer who recognises every real incident that they read, and errs on 1 alert in 20

The copilot alone (no review) misses 15 of 59 incidents and raises 11 false alarms. With review, 254 alerts (those with a score of 0.02 or more) go to a person. Then 10 incidents are missed and 9 false alarms remain. A person overrode the copilot 31 times. The last line says what these numbers assume: see the last question of "Check yourself".

Errors of the fixed week, copilot alone and with review
Missed, copilot alone15Missed, with review10False alarms, alone11False alarms, with review9Missed, copilot alone15Missed, with review10False alarms, alone11False alarms, with review9

4. Read where the misses come from

Seven of the 10 missed incidents are in the pile below 0.02 that nobody reads, because they look harmless in every field (lesson 2). The other three are reviewer errors: the simulated person is wrong on one alert in twenty, and a wrong reversal of a correct "escalate" turns a catch into a miss. Review helps a lot, and it does not give perfect results. The records show it: review.jsonl holds one line for each of the 1,000 alerts.

python3 -c "
import json
from collections import Counter
rows = [json.loads(l) for l in open('review.jsonl')]
print(len(rows), 'records')
print(Counter((r['reviewed'], r['human']) for r in rows))
"
1000 records
Counter({(False, None): 746, (True, 'accept'): 223, (True, 'override'): 31})

The 746 alerts with reviewed false and human none were closed by the copilot alone. They are the part that needs a policy and a sample audit.

5. Change the rule and watch the trade

Set REVIEW_FROM to 0.05 in copilot.py and run week again: a person reads 115 alerts instead of 254, and the misses rise from 10 to 15. Set it to 0.01 and a person reads 454, and the misses fall to 6. The numbers are not a law. They are the price list that your lead needs to choose the rule. Put the value back to 0.02 afterwards.

Your turn

Use copilot.py and the fixed week. You write the changes, and you put the original values back afterwards.

  1. Set REVIEW_FROM to 0.05. How many alerts does a person read, and how many incidents are missed?
  2. With REVIEW_FROM at 0.02 again, make the simulated reviewer wrong on every tenth alert (count % 10). How many incidents are missed, and how many false alarms are there?

Last, write one sentence on how you would keep a real reviewer from getting tired on the night shift.

Check yourself

Why does the copilot give evidence and not an explanation in words?

Facts such as "off-hours" can be checked in a second. A written story sounds right even when it is wrong. A person who checks facts finds an error, and a person who reads a story tends to agree with it.

Review lowered the misses from 15 to 10, not to 0. Why?

Seven real incidents have a score below 0.02, and nobody reads them. The reviewer also makes mistakes, here one in twenty. Review is a control with a measured effect. It does not remove the risk.

Why keep a record line for the alerts that were closed with no review?

An alert that was closed by a rule is a decision. When an incident is found later, the record shows its score, the rule of the day and the evidence. Without the line, the question "why was it closed?" has no answer.

The simulated reviewer knows the true label. What does that do to the result?

It makes the measure better than real life: a real person does not know the label, and can be wrong more often than one in twenty. Use the result as a best case. Measure a real reviewer on a sample with labels that were made later.

Field notes

  • People trust a confident proposal. This is automation bias, and it is stronger at night. Show the evidence before the verdict, and measure how often reviewers accept a wrong proposal, using a few test alerts that you plant.
  • Log what the reviewer saw, how long they took and their decision. A reviewer who accepts every proposal in two seconds is not reviewing.
  • Sample the alerts that closed with no review. Read 20 each week and write the count of real incidents among them. This is your live estimate of the silent miss rate.
  • NIST SP 800-61 Revision 3 (2025) places detection, response and recovery in one improvement cycle. A review record is the data that this cycle needs. Take the current text from NIST.
  • Do not let the copilot act. In this lesson it closes alerts in a list. In a real tool, closing, blocking or isolating goes through the gate of lesson 9.