Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#2,718 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@yashwantbezawada がすでに取り組んでいます。

2025年11月5日 から。

  • #2733 @yashwantbezawada による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
python
領域
api

調査の方向性

まず、提供されたスクリプトを再現し、responses.parse を StringModel、FloatModel、DecimalModel と比較します。特に、Decimal フィールド用に生成された Pydantic スキーマを確認してください。ライブラリがそのスキーマをどのように処理するかを追跡し、回帰テストを追加します。DecimalModel が報告された 500 エラーなしで gpt-5 に対して成功すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Python
スター
31.8k
フォーク
7.3k
平均マージ
1日 1時間
マージ済み PR(30日)
137

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openai/openai-python のほかの issue

openai/openai-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。