Options for configuring the OpenAI Moderation middleware.
interface OpenAIModerationMiddlewareOptionsWhether to check user input messages.
Whether to check model output messages.
Whether to check tool result messages.
How to handle violations.
"error": Throw an error when content is flagged"end": End the agent execution and return a violation message"replace": Replace the flagged content with a violation messageOpenAI model to use for moderation. Can be either a model name or a BaseChatModel instance.
const model = new ChatOpenAI({ model: "gpt-4o-mini" });
const middleware = openAIModerationMiddleware({ model });
const agent = createAgent({
model,
middleware: [middleware],
});const middleware = openAIModerationMiddleware({ model: "gpt-4o-mini" });
const agent = createAgent({
model: "gpt-5",
middleware: [middleware],
});Moderation model to use.
Custom template for violation messages.
Available placeholders: {categories}, {category_scores}, {original_content}