Open
Description
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
In some occasions while using the Completion API with Structured Outputs, the SDK fails and returns a ValidationError
:
ValidationError: 1 validation error for RawResponse
Invalid JSON: EOF while parsing a value at line 1 column 600 [type=json_invalid, input_value=' ... ', input_type=str]
For further information visit https://errors.pydantic.dev/2.9/v/json_invalid
This does not happen every time, but we use it in a production service and this unpredictable behavior is hard to prevent.
To Reproduce
- Create a Pydantic model
- Instantiate an OpenAI client
- Use the method
OpenAI.beta.chat.completions.parse(...)
with the following arguments - Repeat a few times for seeing the error
from pydantic import BaseModel
from openai import OpenAI
class RawResponse(BaseModel):
answer: str
client = OpenAI(api_key=...)
completion = client.beta.chat.completions.parse(
model='gpt-4o-2024-08-06',
messages=messages,
max_tokens=750,
n=1,
stop=None,
temperature=0.1,
response_format=RawResponse
)
After a few times, this fails with:
ValidationError: 1 validation error for RawResponse
Invalid JSON: EOF while parsing a value at line 1 column 600 [type=json_invalid, input_value=' ... ', input_type=str]
For further information visit https://errors.pydantic.dev/2.9/v/json_invalid
Code snippets
No response
OS
debian:bullseye-slim
Python version
CPython 3.10.8
Library version
openai 1.48.0