Hey all,
I’m currently struggeling with above combination.
I do have the following Pydatic Base Model, where founder is optional:
class Capital(BaseModel):
capital: str
country: str
population: float
longitude: float
latitude: float
founder: Optional[str]
class Result(BaseModel):
capitals: list[Capital]
When I send this via the responses.parse endpoint the generated request seems valid:
"founder": {
"title": "Founder",
"anyOf": [
{"type": "string"},
{"type": "null"}
]
}
and founder is a mandatory field.
Here is my request:
response = client.responses.parse(
model="gpt-4.1-mini",
input=[
{"role": "system", "content": "Provide the relevant information based on the user's question. For each capital, if the founder is unknown or if the founder is not a single person, set the 'founder' field to '-'."},
{
"role": "user",
"content": "Hello, which are the 5 biggest capitals in Europe?!"
}
],
text_format=Result
)
As long as all returned rows do contain a founder everything works like charm, but once at least one founder is null / not returned by the LLM the response parsing (within the OpenAI SDK fails).
File "C:\Users\<homefolder>\source\sample\.venv\Lib\site-packages\openai\lib\_parsing\_responses.py", line 62, in parse_response
for output in response.output:
TypeError: 'NoneType' object is not iterable
Am I doing something wrong? Is this a limitation or can I overcome it somehow.
I came across some OpenAI documentation using Pydantic and Optional as well. But I also read you should not trust all the OpenAI documentaiton.
Thanks in advance