Moderation Endpoint Schema Mismatch for illicit and illicit_violent fields
维护者通常 1 天内回复
@nightcityblade 已经在做这个了。
开始于 2026年9月30日。
评估
调研方向
先从 Moderation 响应以及 Categories 和 CategoryScores 定义开始,然后复现 issue 中显示的 moderation 请求。确认 API 是否将 illicit 和 illicit_violent 返回为 null;当 Python schema 与观察到的 API contract 相匹配,并且 response 可以一致地完成验证时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
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.categoriesfield (of typeCategories), all fields are annotated asbool. However, when the moderation endpoint is called, the fieldsillicitandillicit_violentreturnNonevalues instead ofTrueorFalse. - The same issue occurs with the
category_scoresfield (of typeCategoryScores), where all fields are expected to befloat. Yet,illicitandillicit_violentare also returned asNone.
Expected Behavior:
- If the
Nonevalues forillicitandillicit_violentare 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
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openai/openai-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
openai/openai-python#4339 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
openai/openai-python#4338 · 1 条评论 ·
维护者通常 1 天内回复
-
`DeprecationWarning` thrown when calling websockets (17.1 and later)可能已有人在做 @akhil9tiet 于 1 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 65/100
openai/openai-python#4337 · 1 条评论 ·
维护者通常 1 天内回复
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parameters可能已有人在做 @Rewaskc02-lang 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
openai/openai-python#4311 · 4 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
openai/openai-python#4310 · 1 条评论 ·
维护者通常 1 天内回复
查看 openai/openai-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 69/100
-
frontend testing
难度 2/5 1-3 小时 新手友好度 84/100
vendrabuck/HERD#1588 ·
维护者通常 1 天内回复
-
Lessons: record the second case of L14 (security updates cover only pip)可能已有人在做 @vishwanathj 今天认领。 未关闭area/docs no-test-needed type/docs
难度 2/5 1-3 小时 新手友好度 76/100
vishwanathj/ocp_lab.ai#39 · 1 条评论 ·
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 88/100
laaielichter/Gulliver#228 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复