OpenAI API responses.parse with web_search_preview tool returns corrupted JSON with control characters
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia dal punto di ingresso client.responses.parse ed esegui la riproduzione AsyncOpenAI fornita con lo strumento web_search_preview e un input non ASCII. Confronta il testo restituito con il JSON previsto, verificando la presenza di caratteri di controllo, escape incompleti e troncamento; completato significa JSON valido e completo, con il testo non ASCII codificato correttamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 31.8k
- Fork
- 7.3k
- Merge medio
- 1g 3h
- PR unite (30g)
- 131
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di openai/openai-python
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
openai/openai-python#4022 · 18 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providersForse già presa @mohmedmm l’ha presa 8 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
openai/openai-python#4017 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Querystring drops explicit empty-string scalar valuesForse già presa @sylvesterkaczmarek l’ha presa 30 giorni fa. Apertasdk-breaking-change v4
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
openai/openai-python#3837 ·
I maintainer di solito rispondono entro 1 giorno
-
Define + export `ServiceTiers` string literalForse già presa @SparshGarg999 l’ha presa 57 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
openai/openai-python#3556 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Empty OPENAI_BASE_URL prevents fallback to default API endpointForse già presa @Sehastrajit-S l’ha presa 23 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
openai/openai-python#2927 · 6 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di openai/openai-python
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
awslabs/visual-asset-management-system#414 ·
I maintainer di solito rispondono entro 1 giorno
-
bug v1 v2
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
modelcontextprotocol/python-sdk#3670 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
aicell-lab/bioengine#232 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
modelscope/evalscope#1836 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100