Skip to main content
A moderation model requires separate deployment support. Use the Moderations API to check text; conversational refusals and gateway keyword rules are separate mechanisms. Set an explicit moderation model ID instead of relying on the gateway’s historical default.

Run batch text moderation

Install dependencies in the documentation directory using the Python guide, then replace the address, token, and moderation model. The script submits two fixed texts and prints allow or review in input order without printing source text or scores.
examples/moderations.py uses the SDK’s generic HTTP method to read raw dictionaries so missing fields or string booleans cannot become valid decisions.

Apply the result

  • results follows input order; there is no document index to replace that position. The example checks the count and validates every result before printing decisions.
  • flagged is the overall signal, categories contains category signals, and category_scores contains confidence scores. The sample application routes any positive signal to review; allow is not proof of safety.
  • Categories can evolve with the model, so the example does not freeze an enum. Evaluate thresholds for your language, use case, and model instead of copying thresholds across models. See the OpenAI moderation guide for field semantics.
  • HTTP errors, empty results, and invalid scores mean no usable decision. They do not mean approval. The script exits unsuccessfully; the application must choose review, delayed publication, or a retry message.

Check inputs and outputs

Check user input before deciding whether to invoke generation, and check generated content before publication. If a workflow requires reviewing the complete output, buffer it on the server before publishing. Do not assume streamed content already shown to a user can be recalled. Image moderation requires separate confirmation of the model, channel, and content block format. This guide and example cover only text and text batches. Moderation does not replace permissions, tool execution authorization, or RAG document access controls.

Gateway adaptation caveat

The current OpenAI adapter can rebuild a response as a generic text response when the channel enables ForceFormat, losing moderation-specific results. For HTTP 200 without results, ask the administrator to inspect channel response formatting and the original upstream structure. A registered route does not guarantee every channel preserves moderation fields. Errors and retries · Production integration 阅读中文