Invalid Schema Error when Using examples Field in Pydantic Model for OpenAI Python Client
メンテナーはふだん 1 日以内に返信
@LuminaX-alt がすでに取り組んでいます。
2025年8月4日 から。
評価
調査の方向性
client.beta.chat.completions.parse から開始し、Pydantic の response_format スキーマがどのように送信されるかを調査します。提供された MathReasoning モデルで問題を再現し、client と API のどちらが examples フィールドを拒否しているのかを特定します。client の変更が必要かどうかについて文書化された判断があれば完了です。
索引モデルが 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
When you add the examples field in the Field definition of a Pydantic model (as shown in the code below) while using the OpenAI Python client, it raises a BadRequestError with error code 400. The error message indicates that the examples field is not permitted in the schema for the response_format parameter.
This is the error message:
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'MathReasoning': In context=('properties', 'final_answer'), 'examples' is not permitted.", 'type': 'invalid_request_error', 'param': 'response_format', 'code': None}}
Question:
Is this behavior due to a limitation in the OpenAI Python client or API, or is it something that could potentially be patched in the future?
To Reproduce
from openai import Client
from pydantic import BaseModel, Field
from dotenv import load_dotenv
load_dotenv()
client = Client()
class Step(BaseModel):
explanation: str
output: str
class MathReasoning(BaseModel):
steps: list[Step]
final_answer: str = Field(
title="Final Answer",
description="The final answer to the math problem",
examples=["x = -3", "x = 2"]
)
completion = client.beta.chat.completions.parse(
model="gpt-4o-2024-08-06",
messages=[
{"role": "system", "content": "You are a helpful math tutor. Guide the user through the solution step by step."},
{"role": "user", "content": "how can I solve 8x + 7 = -23"}
],
response_format=MathReasoning,
)
math_reasoning = completion.choices[0].message
# If the model refuses to respond, you will get a refusal message
if (math_reasoning.refusal):
print(math_reasoning.refusal)
else:
print(math_reasoning.parsed)
Code snippets
OS
Windows
Python version
Python v3.11.9
Library version
openai v1.68.2
- 主要言語
- Python
- スター
- 31.8k
- フォーク
- 7.3k
- 平均マージ
- 1日 3時間
- マージ済み PR(30日)
- 131
環境構築
このプロジェクトの開発コンテナを、あなたの 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 が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
openai/openai-python#4017 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Querystring drops explicit empty-string scalar values対応中かも @sylvesterkaczmarek が 31 日前に担当しました。 オープンsdk-breaking-change v4
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
openai/openai-python#3837 ·
メンテナーはふだん 1 日以内に返信
-
Define + export `ServiceTiers` string literal対応中かも @SparshGarg999 が 57 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
openai/openai-python#3556 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Empty OPENAI_BASE_URL prevents fallback to default API endpoint対応中かも @Sehastrajit-S が 23 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
openai/openai-python#2927 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
openai/openai-python の issue をすべて見る
似ている issue
-
enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
python-version
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
bug javascript P2-medium python release:v3.1
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
adrirubio/claude-deck#546 ·
メンテナーはふだん 1 日以内に返信
-
area: desktop area: website priority: P2 type: feature
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
appandflow/stim#3411 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信