Moderation Endpoint Schema Mismatch for illicit and illicit_violent fields

Aberta
#1,786 3 comentários 6 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@nightcityblade já está trabalhando nisso.

Desde 30/9/2026.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
45/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
python
Domínio
api

Direção de pesquisa

Comece com a resposta de Moderation e as definições de Categories e CategoryScores; em seguida, reproduza a solicitação de moderação mostrada na issue. Confirme se illicit e illicit_violent são retornados como null pela API; o trabalho estará concluído quando o schema Python corresponder ao contrato observado da API e a resposta puder ser validada de forma consistente.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
Python
Estrelas
32.2k
Forks
5.8k
Merge médio
12h 31min
PRs com merge (30d)
101

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de openai/openai-python

Todas as issues de openai/openai-python

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.