Moderation
The POST /v1/moderations endpoint is an OpenAI-compatible content moderation
mock. Register fixture patterns on the LLMock instance and the request
input is matched against them — first match wins, no match returns a default
unflagged result.
Endpoint
| Method | Path | Request Body | Response |
|---|---|---|---|
POST |
/v1/moderations |
{ "input": "..." } |
{ "id": "...", "model": "...", "results": [...] } |
How It Works
-
The
inputfield is matched against registered patterns — string patterns are case-insensitive substring matches, RegExp patterns are tested as-is - First matching fixture wins, so register specific patterns before catch-alls
-
Unmatched inputs return a default result with
flagged: falseand every category (and category score) set tofalse/0 -
Under strict mode (
--strict, orX-AIMock-Strict: trueon the request), an unmatched input returns503 no_fixture_matchinstead of the unflagged default -
An array
inputis joined with spaces for matching, and multimodaltextparts contribute their text
Unit Test: Flagged Content
moderation-fixture.test.ts ts
const mock = new LLMock();
mock.onModerate("violent", {
flagged: true,
categories: { violence: true, hate: false },
category_scores: { violence: 0.95, hate: 0.01 },
});
await mock.start();
const res = await fetch(`${mock.url}/v1/moderations`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ input: "a violent threat" }),
});
const body = await res.json();
expect(body.results[0].flagged).toBe(true);
expect(body.model).toBe("omni-moderation-latest");
Response Format
Matches the OpenAI /v1/moderations response format:
Response shape json
{
"id": "modr-...",
"model": "omni-moderation-latest",
"results": [
{
"flagged": true,
"categories": { "violence": true, "hate": false },
"category_scores": { "violence": 0.95, "hate": 0.01 }
}
]
}
Validation
- Malformed JSON bodies are rejected with
400 -
An
inputthat is neither a string, an array of strings, nor multimodal parts is rejected with400 - A missing
inputmatches against the empty string (usually a miss)
Journal Integration
Moderation requests are recorded in the LLMock journal with
service: "moderation":
Journal entries typescript
const entries = mock.getRequests();
const moderationRequests = entries.filter((e) => e.service === "moderation");
See also the Services overview, plus the sibling pages Web Search and Rerank.