Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Encountering a 500 error when calling responses.parse on a schema containing decimal.Decimal fields.

Abierto
#2,718 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@yashwantbezawada ya está trabajando en esto.

Desde el 5/11/2025.

  • #2733 de @yashwantbezawada — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
python
Área
api

Línea de trabajo

Empieza reproduciendo el script proporcionado y compara responses.parse con StringModel, FloatModel y DecimalModel, especialmente el esquema de Pydantic generado para los campos Decimal. Sigue cómo la biblioteca gestiona ese esquema y añade una prueba de regresión; la tarea estará terminada cuando DecimalModel funcione con gpt-5 sin el error 500 indicado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

api bug
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

The responses.parse() method fails when the Pydantic model contains decimal.Decimal type fields.

To Reproduce

Run this test script below


import logging
from decimal import Decimal
from typing import Optional
from pydantic import BaseModel, Field
from openai import OpenAI

# Set up logger
logging.basicConfig(level=logging.INFO, format='%(message)s')
logger = logging.getLogger(__name__)

# Define test models
class DecimalModel(BaseModel):
    """Model with Decimal fields."""
    premium: Optional[Decimal] = Field(default=None, description="Premium amount")
    amount: Optional[Decimal] = Field(default=None, description="Total amount")

class FloatModel(BaseModel):
    """Model with float fields."""
    premium: Optional[float] = Field(default=None, description="Premium amount")
    amount: Optional[float] = Field(default=None, description="Total amount")

class StringModel(BaseModel):
    """Model with string fields."""
    premium: Optional[str] = Field(default=None, description="Premium amount")
    amount: Optional[str] = Field(default=None, description="Total amount")

# Initialize client and test data
client = OpenAI()
test_content = "The premium is $5,000.00 and the total amount is $5,500.50"

request_model = "gpt-5"
# request_model = "gpt-5-mini" # Uncomment to test with a mini
# Test String Model
try:
    response = client.responses.parse(
        model=request_model,
        input=[
            {"role": "system", "content": "Extract the financial amounts."},
            {"role": "user", "content": test_content}
        ],
        text_format=StringModel,
    )
    logger.info(f"StringModel: WORKS. Data: {response.output_parsed.model_dump_json()}")
except Exception as e:
    logger.error(f"StringModel: FAILED - {type(e).__name__}")
    logger.exception(e)

# Test Float Model
try:
    response = client.responses.parse(
        model=request_model,
        input=[
            {"role": "system", "content": "Extract the financial amounts."},
            {"role": "user", "content": test_content}
        ],
        text_format=FloatModel,
    )
    logger.info(f"FloatModel: WORKS. Data: {response.output_parsed.model_dump_json()}")
except Exception as e:
    logger.error(f"FloatModel: FAILED - {type(e).__name__}")
    logger.exception(e)

# Test Decimal Model
try:
    response = client.responses.parse(
        model=request_model,
        input=[
            {"role": "system", "content": "Extract the financial amounts."},
            {"role": "user", "content": test_content}
        ],
        text_format=DecimalModel,
    )
    logger.info(f"DecimalModel: WORKS. Data: {response.output_parsed.model_dump_json()}")
except Exception as e:
    logger.error(f"DecimalModel: FAILED - {type(e).__name__}")
    logger.exception(e)

Output with gpt-5

> python test_decimal_extraction.py
HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
StringModel: WORKS. Data: {"premium":"$5,000.00","amount":"$5,500.50"}
HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
FloatModel: WORKS. Data: {"premium":5000.0,"amount":5500.5}
HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 500 Internal Server Error"
Retrying request to /responses in 0.459931 seconds
HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 500 Internal Server Error"
Retrying request to /responses in 0.893894 seconds
HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 500 Internal Server Error"
DecimalModel: FAILED - InternalServerError
Error code: 500 - {'error': {'message': 'An error occurred while processing your request. You can retry your request, or contact us through our help center at help.openai.com if the error persists. Please include the request ID req_2e82ffe03e6d45f38ad7ff9b98a62ec4 in your message.', 'type': 'server_error', 'param': None, 'code': 'server_error'}}

Works as expected with gpt-5-mini

> python test_decimal_extraction.py
HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
StringModel: WORKS. Data: {"premium":"$5,000.00","amount":"$5,500.50"}
HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
FloatModel: WORKS. Data: {"premium":5000.0,"amount":5500.5}
HTTP Request: POST https://api.openai.com/v1/responses "HTTP/1.1 200 OK"
DecimalModel: WORKS. Data: {"premium":"5000.00","amount":"5500.50"}
Code snippets

OS

Debian GNU/Linux

Python version

3.12.10

Library version

openai v1.109.1

Lenguaje dominante
Python
Estrellas
31.8k
Forks
7.3k
Merge medio
1 d 3 h
PR fusionados (30 d)
131

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de openai/openai-python

Todos los issues de openai/openai-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.