# Student safety (/docs/use-cases/education/student-safety)



`createStudentSafetyScrubber` redacts student-identifying fragments before they
reach the model. It composes [`KeyedRegexScrubber`](/docs/scrubbers), so it
drops into any `ComplianceRuntime` scrubber chain.

[`educationAgent`](/docs/use-cases/education) wires it automatically. Use this
page to extend it, tune it, or wire it into a runtime outside `@pleach/recipes`,
such as a teacher-facing transcription pipeline.

## What it redacts today [#what-it-redacts-today]

Four pattern categories ship as defaults. Matching favors false positives over false negatives.

| Pattern name             | Regex (illustrative)                                                                       | Example match                         |
| ------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------- |
| `student-id-number`      | `\b(?:student\s*id\|id#\|id\s*number)\s*:?\s*\d{4,10}\b`                                   | `Student ID 9876543`, `ID# 1234567`   |
| `grade-band`             | `\b(?:K\|[1-9]\|1[0-2])(?:st\|nd\|rd\|th)?[\s-]+grad(?:e\|er)\b`                           | `5th grade`, `11th-grader`, `grade 9` |
| `school-issued-email`    | `\b[a-z0-9._%+-]+@[a-z0-9.-]*\.(?:k12\|edu\|sch)\.[a-z.]{2,}\b`                            | `jane.doe12@district.k12.ca.us`       |
| `labeled-parent-contact` | `\b(?:parent\|guardian)[\s\w]{0,20}(?:phone\|contact\|number)\s*:?\s*\+?[\d\s().\-]{7,}\b` | `Parent phone: (555) 123-4567`        |

Default replacement is `[STUDENT]`. Override it per scrubber or per `extra` entry.

To narrow the defaults, such as turning off `grade-band` for research, compose
your own `KeyedRegexScrubber` rather than subtracting from the default set.

## Minimal usage [#minimal-usage]

```ts
import { createStudentSafetyScrubber } from "@pleach/compliance/education";

const scrubber = createStudentSafetyScrubber();

const result = scrubber.scrub(
  "Hi — Student ID 9876543 needs help with 5th grade fractions",
  {
    eventType: "user.message",
    fieldPath: ["content"],
    tenantId: "district-1234",
  },
);

// result.redacted   : "Hi — [STUDENT] needs help with [STUDENT] fractions"
// result.matchCount : 2
// result.matchedScrubberIds : ["student-safety:student-id-number",
//                              "student-safety:grade-band"]
```

The result shape matches every other [`Scrubber`](/docs/scrubbers):
`{ redacted, matchCount, matchedScrubberIds }`. Audit ledgers can read
`matchedScrubberIds` to attribute which pattern fired.

## Extending with district-specific patterns [#extending-with-district-specific-patterns]

Pass district-specific identifiers, such as SIS IDs, locker numbers, bus routes, or IEP filename prefixes, through `extra`:

```ts
import { createStudentSafetyScrubber } from "@pleach/compliance/education";

const scrubber = createStudentSafetyScrubber({
  id: "district-1234-student-safety",
  replacement: "[STUDENT]",
  extra: [
    // District-issued 8-digit student ID with leading `D`.
    { name: "district-id", pattern: /\bD\d{8}\b/g, replacement: "[DID]" },
    // Bus route on a transportation transcript.
    { name: "bus-route", pattern: /\bRoute\s+\d{1,3}[A-Z]?\b/gi },
    // IEP filename pattern. Replacement defaults to the scrubber's.
    { name: "iep-doc", pattern: /\bIEP-\d{6}\.pdf\b/g },
  ],
});
```

`extra` runs after the defaults. A per-entry `replacement` overrides the scrubber-level default.

## Composing with `KeyedRegexScrubber` directly [#composing-with-keyedregexscrubber-directly]

For full control over pattern order, construct `KeyedRegexScrubber` directly:

```ts
import { KeyedRegexScrubber } from "@pleach/compliance/scrubbers";

const districtScrubber = new KeyedRegexScrubber({
  id: "district-1234-overrides",
  entries: [
    { name: "internal-ticket", pattern: /TKT-\d{6}/g, replacement: "[TKT]" },
    { name: "lunch-account", pattern: /LUNCH\d{8}/g, replacement: "[LUNCH]" },
  ],
});

// Chain in your ComplianceRuntime:
// scrubbers: [createStudentSafetyScrubber(), districtScrubber, ...]
```

You own the false-positive rate on your patterns. Idempotency is also yours: chained pathological patterns such as `{ pattern: /\d+/, replacement: "0" }` are a config error.

## Wiring into a custom `ComplianceRuntime` [#wiring-into-a-custom-complianceruntime]

Outside `educationAgent`, compose the scrubber into a `ComplianceRuntime` directly:

```ts
import {
  createComplianceRuntime,
  SsnUsScrubber,
} from "@pleach/compliance";
import { createStudentSafetyScrubber } from "@pleach/compliance/education";

const runtime = createComplianceRuntime({
  scrubbers: [
    createStudentSafetyScrubber(),
    new SsnUsScrubber(), // belt-and-suspenders for parent SSNs on emergency forms
  ],
});

// In your per-event boundary:
const { redacted, matchCount } = runtime.scrub(transcript, {
  eventType: "transcript.captured",
  fieldPath: ["content"],
  tenantId: districtId,
});
```

## Adding content moderation [#adding-content-moderation]

The shipped scrubber redacts **identifiers** only. Per-category content safety,
such as self-harm, violence, or age-inappropriate language, is a step you add.
`educationAgent` records the `contentSafety` array for your telemetry but
doesn't enforce it. Two options:

1. **External moderation API.** Put an Anthropic or OpenAI moderation endpoint, or a vendor like Hive or Perspective, in front of `ask()`. Reject or escalate on the verdict.
2. **Custom `Scrubber`.** Implement the [`Scrubber`](/docs/scrubbers) contract with your own classifier inside `scrub()`.

## Where to import [#where-to-import]

* `createStudentSafetyScrubber` and `createCostCapPolicy` come from
  `@pleach/compliance/education`.
* The underlying composable scrubber shape is in
  `@pleach/compliance/scrubbers`.

## See also [#see-also]

* [Education](/docs/use-cases/education) — the landing page.
* [FERPA / COPPA scope](/docs/use-cases/education/ferpa-coppa) —
  what you provide alongside this scrubber.
* [Scrubbers](/docs/scrubbers) — the redaction contract,
  per-event-type allowlist, and authoring guide.
* [`@pleach/compliance`](/docs/compliance) — the underlying
  scrubber library and `ComplianceRuntime`.
