Moderation Endpoint Schema Mismatch for illicit and illicit_violent fields

未关闭
#1,786 3 条评论 6 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@nightcityblade 已经在做这个了。

开始于 2026年9月30日。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
api

调研方向

先从 Moderation 响应以及 Categories 和 CategoryScores 定义开始,然后复现 issue 中显示的 moderation 请求。确认 API 是否将 illicit 和 illicit_violent 返回为 null;当 Python schema 与观察到的 API contract 相匹配,并且 response 可以一致地完成验证时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug openapi
Confirm this is an issue with the Python library and not an underlying OpenAI API
  • This is an issue with the Python library
Describe the bug

Description:
The results returned by the moderation endpoint do not align with the expected schema.

Details:

  • In the Moderation.categories field (of type Categories), all fields are annotated as bool. However, when the moderation endpoint is called, the fields illicit and illicit_violent return None values instead of True or False.
  • The same issue occurs with the category_scores field (of type CategoryScores), where all fields are expected to be float. Yet, illicit and illicit_violent are also returned as None.

Expected Behavior:

  • If the None values for illicit and illicit_violent are expected behavior, these fields should be annotated as optional in the schema.
  • If this is not expected behavior, the API should be corrected to ensure that these fields return appropriate boolean or float values.

Additional Notes:
It is surprising that Pydantic does not throw an error for these mismatches and allows None values to be returned. I could not manually create a Categories object with any None value in it.

To Reproduce

Run the moderation endpoint and check response.results[0] categories and category_scores -> illicit field.

Result I'm getting:

response.results: [
    Moderation(
        categories=Categories(
            harassment=False,
            harassment_threatening=False,
            hate=False,
            hate_threatening=False,
            illicit=None,
            illicit_violent=None,
            self_harm=False,
            self_harm_instructions=False,
            self_harm_intent=False,
            sexual=False,
            sexual_minors=False,
            violence=False,
            violence_graphic=False,
            self-harm=False,
            sexual/minors=False,
            hate/threatening=False,
            violence/graphic=False,
            self-harm/intent=False,
            self-harm/instructions=False,
            harassment/threatening=False,
        ),
        category_applied_input_types=None,
        category_scores=CategoryScores(
            harassment=0.000255020015174523,
            harassment_threatening=1.3588138244813308e-05,
            hate=2.8068381652701646e-05,
            hate_threatening=1.0663524108167621e-06,
            illicit=None,
            illicit_violent=None,
            self_harm=9.841909195529297e-05,
            self_harm_instructions=7.693658517382573e-06,
            self_harm_intent=7.031533459667116e-05,
            sexual=0.013590452261269093,
            sexual_minors=0.0031673426274210215,
            violence=0.00022930897830519825,
            violence_graphic=4.927426198264584e-05,
            self-harm=9.841909195529297e-05,
            sexual/minors=0.0031673426274210215,
            hate/threatening=1.0663524108167621e-06,
            violence/graphic=4.927426198264584e-05,
            self-harm/intent=7.031533459667116e-05,
            self-harm/instructions=7.693658517382573e-06,
            harassment/threatening=1.3588138244813308e-05,
        ),
        flagged=False,
    ),
]
Code snippets
import openai

client = openai.OpenAI()
response = client.moderations.create(input="text")
print(response.results[0])
OS

macOS

Python version

Python 3.12.4

Library version

openai 1.51.2

主要语言
Python
星标
32.2k
派生
5.8k
平均合并
12 小时 31 分钟
30 天内合并 PR
101

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openai/openai-python 的其他 Issue

查看 openai/openai-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。