Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Invalid Schema Error when Using examples Field in Pydantic Model for OpenAI Python Client

Aperta
#2,274 1 commento 3 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@LuminaX-alt ci sta già lavorando.

Dal 4/8/2025.

  • #39 di @LuminaX-alt — aperta
  • #3732 di @sylvesterkaczmarek — chiusa senza merge

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
python
Ambito
api

Direzione di ricerca

Inizia da client.beta.chat.completions.parse e ispeziona come viene inviato lo schema Pydantic di response_format. Riproduci il problema con il modello MathReasoning fornito e determina se il client o l'API rifiuta il campo examples. Il lavoro è completato quando è stata documentata una decisione sull'opportunità di apportare una modifica al client.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Python
Stelle
31.7k
Fork
6.8k
Merge medio
1g 4h
PR unite (30g)
126

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openai/openai-python

Tutte le issue di openai/openai-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.