Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

beta.chat.completions.parse returns unhandled ValidationError

Đang mở
#1,763 22 bình luận 13 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Jack-the-slp đang làm issue này rồi.

Từ ngày 30/8/2026.

  • #2908 của @giulio-leone — đã đóng, không merge
  • #2917 của @giulio-leone — đã đóng, không merge
  • #3763 của @Jack-the-slp — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
api, backend-api-design

Hướng nghiên cứu

Bắt đầu từ OpenAI.beta.chat.completions.parse(...) và tái hiện lỗi Structured Outputs xảy ra không liên tục bằng model Pydantic được cung cấp. Theo dõi nơi response trở thành RawResponse và kiểm tra ranh giới xử lý lỗi; được xem là hoàn tất khi trường hợp tái hiện được bao phủ bởi một regression check và không còn làm phát sinh ValidationError chưa được xử lý.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

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
  1. Create a Pydantic model
  2. Instantiate an OpenAI client
  3. Use the method OpenAI.beta.chat.completions.parse(...) with the following arguments
  4. 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

Ngôn ngữ chính
Python
Star
31.8k
Fork
7.3k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
131

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của openai/openai-python

Tất cả issue của openai/openai-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.