OpenAI API responses.parse with web_search_preview tool returns corrupted JSON with control characters
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đá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
- 35/100
Hướng nghiên cứu
Bắt đầu tại điểm vào client.responses.parse và chạy bản tái hiện AsyncOpenAI được cung cấp với công cụ web_search_preview và đầu vào không phải ASCII. So sánh văn bản được trả về với JSON mong đợi, kiểm tra các ký tự điều khiển, escape chưa hoàn chỉnh và việc bị cắt ngắn; hoàn tất có nghĩa là JSON hợp lệ, đầy đủ với văn bản không phải ASCII được mã hóa chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
Summary
When using the responses.parse API with the web_search_preview tool, the
response frequently contains control characters and gets truncated, causing
JSON parsing failures. This occurs specifically when generating search queries
that may include non-ASCII content.
Environment
- OpenAI Python SDK Version: 1.95.0
- Python Version: 3.12+
- API Model: gpt-4.1
- Endpoint: client.responses.parse
Impact
- JSON parsing fails with ValidationError
- The web_search_preview tool becomes unusable for queries involving
non-English content - Responses are truncated around 3.5-4.5KB, suggesting a buffer overflow issue
Workaround
We currently retry without the web_search_preview tool when these errors occur,
which succeeds but loses the web search functionality.
Suggested Fix
- Ensure web search results are properly sanitized to remove control
characters - Fix the response buffer size to prevent truncation
- Properly encode non-ASCII characters as UTF-8 instead of malformed escape
sequences
To Reproduce
Steps to Reproduce
from openai import AsyncOpenAI
from pydantic import BaseModel, Field
from typing import List, Optional
class Subqueries(BaseModel):
subqueries: List[str] = Field(description="List of search queries")
hl: Optional[str] = Field(default=None, description="Language code")
gl: Optional[str] = Field(default=None, description="Country code")
async_client = AsyncOpenAI()
response = await async_client.responses.parse(
model="gpt-4.1",
input=[
{
"role": "system",
"content": "Generate search queries for finding content creators"
},
{
"role": "user",
"content": "Find Russian language content creators"
}
],
text_format=Subqueries,
tools=[
{
"type": "web_search_preview",
"user_location": {"type": "approximate"},
"search_context_size": "medium"
}
],
temperature=1
)
Expected Behavior
The API should return valid JSON with properly encoded text, including
non-ASCII characters as valid UTF-8.
Actual Behavior
- Control Character Corruption: Responses contain invalid control characters:
{"subqueries": ["\u0004\u0043\u0043... - Where \u0004 is ASCII control character 4, not valid text.
- Truncation Mid-Escape: Responses get truncated in the middle of escape
sequences:
Invalid JSON: EOF while parsing a string at line 1 column 4587
input_value='{"subqueries": ["\u0017...0043a\u00043e\u00043 ' - Note the incomplete escape sequence at the end.
- Malformed Unicode: Instead of proper UTF-8 encoding for Cyrillic:
- Expected: "Фильмы" (proper UTF-8)
- Actual: "\x04\x024\x038..." (control char + ASCII digits)
Code snippets
OS
macOS
Python version
3.12
Library version
1.95.0
- Ngôn ngữ chính
- Python
- Star
- 31.7k
- Fork
- 6.8k
- Merge trung bình
- 1 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 128
Chuẩn bị môi trường
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.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openai/openai-python
-
sdk-breaking-change v4
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
openai/openai-python#3837 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
openai/openai-python#3556 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
openai/openai-python#2927 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug openapi
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openai/openai-python#2502 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
openai/openai-python#2486 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openai/openai-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
conda-forge/conda-build-feedstock#289 · 1 bình luận · 1 reaction ·
-
`pulptest` no longer works in 4.0.0: `ImportError: Start directory is not importable: 'pulp/tests'`Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
remove reddit feedsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
TomCasavant/ohio-sites#224 ·