Skip to content
pleach
Use casesEducation

Student safety

The shipped student-safety scrubber from @pleach/compliance/education — what it redacts today, the composable KeyedRegexScrubber shape for district-specific extensions, and how to add per-category content moderation.

createStudentSafetyScrubber redacts student-identifying fragments before they reach the model. It composes KeyedRegexScrubber, so it drops into any ComplianceRuntime scrubber chain.

educationAgent 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

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

Pattern nameRegex (illustrative)Example match
student-id-number\b(?:student\s*id|id#|id\s*number)\s*:?\s*\d{4,10}\bStudent ID 9876543, ID# 1234567
grade-band\b(?:K|[1-9]|1[0-2])(?:st|nd|rd|th)?[\s-]+grad(?:e|er)\b5th grade, 11th-grader, grade 9
school-issued-email\b[a-z0-9._%+-]+@[a-z0-9.-]*\.(?:k12|edu|sch)\.[a-z.]{2,}\bjane.doe12@district.k12.ca.us
labeled-parent-contact\b(?:parent|guardian)[\s\w]{0,20}(?:phone|contact|number)\s*:?\s*\+?[\d\s().\-]{7,}\bParent 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

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: { redacted, matchCount, matchedScrubberIds }. Audit ledgers can read matchedScrubberIds to attribute which pattern fired.

Extending with district-specific patterns

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

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

For full control over pattern order, construct KeyedRegexScrubber directly:

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

Outside educationAgent, compose the scrubber into a ComplianceRuntime directly:

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

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 contract with your own classifier inside scrub().

Where to import

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

See also