Imported from bedkillerspacex-boop/codex-skill-library (
typescript-content-safety/SKILL.md). Install upstream withnpx skills add bedkillerspacex-boop/codex-skill-library --skill typescript-content-safety. Copyright stays with the author.
TypeScript Content Safety
Scope And Authorization
- In scope: Building moderation for user-generated or model-generated content in products you operate, under product policy and legal guidance.
- Out of scope: Mass-scraping third-party sites to "moderate" them; doxxing; discriminatory enforcement outside written policy.
- Prefer least-privilege access to raw content queues; audit reviewer actions.
- Redact sensitive user content from engineering tickets when possible.
- Pair with
code-quality-standards; route prompt injection tollm-prompt-injection.
When To Use
- Shipping UGC comments, uploads, or AI chat with risk categories.
- Combining blocklists, classifiers, and human review in Node services.
- Defining fail-closed vs fail-open for generation and publish paths.
- Measuring precision/recall and false positive impact on creators.
- Implementing age-gated or region-specific policy packs.
Do Not Use As Primary
| Need | Skill instead |
|---|---|
| Prompt/tool injection testing | llm-prompt-injection |
| Broader AI/ML system security | ai-ml-security |
| DLP (secrets/PII exfil patterns) | typescript-dlp-rules |
| Consent for processing | typescript-consent |
| Implementation quality baseline | code-quality-standards |
Domain Focus
| Area | Guidance |
|---|---|
| Topic | Policy categories, detection stages, enforcement actions |
| Tooling | Perspective/OpenAI moderation APIs, custom classifiers, queues |
| Verify | Known-bad fixtures blocked; known-good not overblocked; audit trail |
| Pitfalls | Single regex "solution"; fail-open on generator abuse; no human appeal |
Actions
| Action | When |
|---|---|
| Allow | Below thresholds |
| Shadow | Label for metrics; still visible (experiment) |
| Quarantine | Hold for human review |
| Block | Prevent publish/send |
| Ban escalate | Repeated severe violations (policy) |
Workflow
1. Confirm policy and success criteria
- Record categories, severity, regions, SLA for human review, authorization.
- Success: severe categories blocked pre-publish; FP rate within budget.
- Legal/policy sign-off on category definitions.
2. Inventory content surfaces
- Text posts, chat, filenames, images, audio
- Model outputs (pre-user delivery)
- Admin-generated content
3. Pipeline design
export type SafetyCategory =
| "hate"
| "sexual"
| "self_harm"
| "violence"
| "scam";
export type SafetyResult = {
action: "allow" | "shadow" | "quarantine" | "block";
categories: Partial<Record<SafetyCategory, number>>;
model: string;
policyVersion: string;
};
export async function moderateText(
text: string,
classify: (t: string) => Promise<Partial<Record<SafetyCategory, number>>>,
thresholds: Record<SafetyCategory, number>,
): Promise<SafetyResult> {
// Stage 0: size/empty
if (!text.trim()) {
return { action: "allow", categories: {}, model: "noop", policyVersion: "v1" };
}
// Stage 1: optional blocklist (high precision phrases) - keep small
const scores = await classify(text);
let action: SafetyResult["action"] = "allow";
for (const [cat, score] of Object.entries(scores) as [SafetyCategory, number][]) {
if (score >= thresholds[cat]) action = "block";
else if (score >= thresholds[cat] * 0.8 && action === "allow") action = "quarantine";
}
return { action, categories: scores, model: "classifier", policyVersion: "v1" };
}
4. Enforce at write path
- User publish: block/quarantine before durable write.
- LLM output: filter before stream finalize; document fail behavior if API down.
- Async: re-score on model upgrade; do not silently unban without review.
5. Human review and appeals
- Reviewer UI with limited context; dual control for account bans.
- Appeal path with SLA; audit who overrode model.
- Training set hygiene: no leaking private UGC into public fine-tunes without rights.
6. Verify
pnpm vitest run tests/content-safety
# Fixture packs: true_positive.jsonl / true_negative.jsonl
| Check | Pass |
|---|---|
| TP severe | 100% blocked on fixture pack |
| TN clean | FP under threshold |
| Fail mode | Documented for classifier outage |
| Audit | Decision + scores retained per retention policy |
7. Observe and hand off
- Metrics: block rate, FP appeals, latency, outage fallback count.
- Weekly policy sampling.
- Route jailbreak/prompt attacks to LLM skills.
Good / Bad
| Topic | Good | Bad |
|---|---|---|
| Policy | Written categories + owners | Ad-hoc moderator mood |
| Stages | Layered precision tools | One giant regex |
| Outage | Fail closed on high-risk gen | Silent allow all |
| Review | Audited overrides | Hard-delete without log |
| Eval | Versioned fixture packs | "Looks fine in chat" |
| Scope | Own product UGC | Off-platform harassment campaigns |
Output Checklist
- Policy categories and thresholds documented
- Surfaces inventoried
- Pipeline + enforcement points implemented
- Human review/appeal path defined
- Fixture evaluation recorded
- Outage behavior documented
- Metrics live
-
code-quality-standardsapplied - Residual risk and review date noted
Rules
- Follow written product policy and law; eng does not invent speech codes alone.
- Protect reviewer mental health and data access least privilege.
- Never use moderation systems for unauthorized surveillance.
- Prefer measurable precision/recall over vibes.
- LLM security exploits route to dedicated skills.