# AI Text Content Moderation

## Objective

Classify user text against the app's policy and act on it proportionately.

A classification step on user-submitted text that maps policy categories to graduated actions and a review queue.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Identify every surface where one user's text reaches another — posts, comments, messages, profile fields, review text, support replies — and apply the check there. Text that never leaves its author does not need moderating.
2. Define a graduated set of actions rather than a binary verdict, and map each policy category and confidence band to one of them: allow, warn the author, limit reach, quarantine for review, or block outright.
3. Send the user's text as data, clearly delimited from the policy instructions, and treat anything inside it as untrusted input. Text that says it is a new system instruction must be classified, not obeyed.
4. Route the uncertain band to the same human review queue used by AI Image Content Moderation, sharing its action vocabulary, reviewer permissions, and appeal path. This brief owns the text classifier and its categories; that one owns the image classifier.
5. Record the decision, the categories, the action, and the reviewer, and keep only the excerpt needed to justify it. Do not archive the full text of every message that was allowed.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Quoted, reported, educational, and fictional uses of prohibited language differ from genuine abuse. Where the policy depends on that distinction, pass enough surrounding context for the classifier to see it, and route the ambiguous cases to a human rather than resolving them by keyword.
- Allow, warn, limit, quarantine, and block must be distinct actions with distinct consequences and distinct user-facing copy. Collapsing them into a single block produces either an unusable product or an unmoderated one.
- Every uncertain classification needs a human path with a stated turnaround, and quarantined content must be visible to its author as pending rather than silently vanishing.
- User text will contain attempts to redirect the moderation prompt. Keep instructions and content separated, ignore instruction-shaped content in the input, and treat structured output that does not match the expected shape as a failed classification, not as an allow.
- The audit trail must justify the decision without becoming a store of the sensitive content it was judging. Retain the categories, the action, and a minimal excerpt, under the app's stated retention period.
- Multilingual text, transliteration, and deliberate character substitution must be handled, and text the classifier cannot read must go to review rather than through.
- When the provider is unavailable, times out, or rate-limits, choose a documented posture per surface — a public post can hold, a private message may pass — and re-check held content when service returns.
- Edits after publication must be re-checked, or a benign post becomes a policy violation with one edit and no further scrutiny.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Every surface where text reaches another user is classified before that text is visible.
- [ ] Actions are graduated across allow, warn, limit, quarantine, and block, each mapped to a category and confidence band.
- [ ] Uncertain classifications reach a human review queue shared with image moderation, with a stated turnaround.
- [ ] User text is passed as delimited data and instruction-shaped content in it has no effect on the classification.
- [ ] Malformed or truncated structured output is treated as a failed classification, never as an allow.
- [ ] Decisions are auditable from categories, action, and a minimal excerpt, under a stated retention period.
- [ ] Edited content is re-checked and a provider outage applies a documented per-surface posture with automatic re-check.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
