Encountering a 500 error when calling responses.parse on a schema containing decimal.Decimal fields.
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
まず、提供されたスクリプトを再現し、responses.parse を StringModel、FloatModel、DecimalModel と比較します。特に、Decimal フィールド用に生成された Pydantic スキーマを確認してください。ライブラリがそのスキーマをどのように処理するかを追跡し、回帰テストを追加します。DecimalModel が報告された 500 エラーなしで gpt-5 に対して成功すれば完了です。
索引モデルが 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
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
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openai/openai-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
openai/openai-python#4022 · コメント 19 件 ·
メンテナーはふだん 1 日以内に返信
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providers対応中かも @mohmedmm が 10 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
openai/openai-python#4017 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Querystring drops explicit empty-string scalar values対応中かも @sylvesterkaczmarek が 33 日前に担当しました。 オープンsdk-breaking-change v4
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
openai/openai-python#3837 ·
メンテナーはふだん 1 日以内に返信
-
Define + export `ServiceTiers` string literal対応中かも @SparshGarg999 が 59 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
openai/openai-python#3556 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Empty OPENAI_BASE_URL prevents fallback to default API endpoint対応中かも @Sehastrajit-S が 25 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
openai/openai-python#2927 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
openai/openai-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
huggingface/peft#3955 ·
メンテナーはふだん 1 日以内に返信
-
author-page correction
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
acl-org/acl-anthology#10313 ·
メンテナーはふだん 1 日以内に返信
-
anime duplicate exception request-theme
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
LizardByte/ThemerrDB#8926 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
huggingface/transformers#49556 ·
メンテナーはふだん 1 日以内に返信
-
area/security bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
mozilla-ai/otari#2245 ·
メンテナーはふだん 1 日以内に返信