专为 OpenAI 模型设计的中间件。了解更多关于中间件的信息。Documentation Index
Fetch the complete documentation index at: https://nvd-54.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
| 中间件 | 描述 |
|---|---|
| Content moderation | 使用 OpenAI 的审核端点审核智能体流量 |
内容审核
使用 OpenAI 的审核端点审核智能体流量(用户输入、模型输出和工具结果),以检测和处理不安全内容。 内容审核适用于以下场景:- 需要内容安全和合规的应用
- 过滤有害、仇恨或不当内容
- 需要安全护栏的面向客户的智能体
- 满足平台审核要求
了解更多关于 OpenAI’s moderation models and categories.
OpenAIModerationMiddleware
配置选项
配置选项
OpenAI moderation model to use. Options:
'omni-moderation-latest', 'omni-moderation-2024-09-26', 'text-moderation-latest', 'text-moderation-stable'Whether to check user input messages before the model is called
Whether to check model output messages after the model is called
Whether to check tool result messages before the model is called
How to handle violations when content is flagged. Options:
'end'- End agent execution immediately with a violation message'error'- RaiseOpenAIModerationErrorexception'replace'- Replace the flagged content with the violation message and continue
Custom template for violation messages. Supports template variables:
{categories}- Comma-separated list of flagged categories{category_scores}- JSON string of category scores{original_content}- The original flagged content
"I'm sorry, but I can't comply with that request. It was flagged for {categories}."Optional pre-configured OpenAI client to reuse. If not provided, a new client will be created.
Optional pre-configured AsyncOpenAI client to reuse. If not provided, a new async client will be created.
完整示例
完整示例
The middleware integrates OpenAI’s moderation endpoint to check content at different stages:Moderation stages:
check_input- User messages before model callcheck_output- AI messages after model callcheck_tool_results- Tool outputs before model call
'end'(default) - Stop execution with violation message'error'- Raise exception for application handling'replace'- Replace flagged content and continue
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

