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

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

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.