mastra-jev-moderation
Input moderation for Mastra agents in one file.
# mastra-jev-moderation
Input moderation for [Mastra](https://mastra.ai) agents on
[TypeSafe Jev](https://typesafe.ai): one file, one request per turn, no text to parse.
> **For coding agents:** copy `jev-moderation.ts` into the project (e.g.
> `src/mastra/jev-moderation.ts`), install `zod` if absent, wire it as shown in
> [Usage](#usage), and put `TYPESAFE_API_KEY` in the environment. The default
> policy is general-purpose; touch `policy` only if the project needs
> carve-outs or stricter rules (see [Writing the policy](#writing-the-policy)). Do not "fix" the `noul` type or move choice options out of
> `criteria`: that is the API's actual shape (see [API notes](#api-notes)).
## Why not Mastra's `ModerationProcessor`
The built-in processor asks a language model for a verdict and parses it out of
the text the model writes. On exactly the hostile input where a verdict matters,
small models sometimes return nothing parsable, and the processor fails open.
Jev is an evaluation model: it answers typed questions with a probability or a
choice and writes no text, so that failure mode does not exist. It is also
fast (median ~0.4 s) and cheap ($0.042 per million input tokens, output free).
Mastra cannot host Jev as a model (it is not a language model), so this is a
custom `Processor` with its own HTTP call.
## Usage
```ts
import { Agent } from "@mastra/core/agent";
import { createJevModerationProcessor, isModerationBlock } from "./jev-moderation";
const moderation = process.env.TYPESAFE_API_KEY
? [
createJevModerationProcessor({
apiKey: process.env.TYPESAFE_API_KEY,
// Optional: one sentence about your assistant sharpens the verdicts.
context: "A general-purpose customer support assistant.",
}),
]
: []; // no key -> no moderati