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 天內回覆