Web search on Responses API breaks inline citations when passed a pydantic data model as text_format

Code to reproduce:

openai_client = OpenAI(api_key=OPENAI_API_KEY)

class Company(BaseModel):
    name: str = Field(..., description="Name of the company")
    company_summary: str = Field(..., description="Summary of the company")

def openai_web_search(
    prompt: str,
    model: str,
) :
    response = openai_client.responses.parse(
        model=model,
        tools=[
            {
                "type": "web_search_preview",
                "search_context_size": "high",
            }
        ],
        input=[{"role": "user", "content": prompt}],
        text_format=Company,
    )

    return response

if __name__ == "__main__":
    result = openai_web_search(
        prompt="Which company was the first one to create reusable rockets?",
        model="o3",
    )
    print(result)

This returns the parsed attribute as:
parsed=Company(name='SpaceX', company_summary='While NASA’s government-run Space Shuttle program (first flown in 1981) demonstrated partial reuse, the first company – i.e., privately-owned commercial entity – to design, fly, land and refly a rocket stage was SpaceX. On 22 December 2015 its Falcon 9 Flight 20 mission launched 11 ORBCOMM satellites to orbit and then brought the 15-story first stage back to Landing Zone 1 at Cape Canaveral, marking the first successful recovery of an orbital-class booster that was later reflown. \ue200cite\ue202turn1search12\ue201 (Blue Origin had landed the sub-orbital New Shepard booster a month earlier on 23 November 2015, but Falcon 9 was the first reusable orbital-class rocket.) Therefore, the first company to create a truly reusable rocket capable of reaching orbit was SpaceX.')

It contains this string above in bold, which I assume is the placeholder token where the inline citations was supposed to be added.

This is the content attribute which has an empty annotations list:
content=[ParsedResponseOutputText[Company](annotations=[], text='{"name":"SpaceX","company_summary":"While NASA’s government-run Space Shuttle program (first flown in 1981) demonstrated partial reuse, the first company – i.e., privately-owned commercial entity – to design, fly, land and refly a rocket stage was SpaceX. On 22 December 2015 its Falcon 9 Flight 20 mission launched 11 ORBCOMM satellites to orbit and then brought the 15-story first stage back to Landing Zone 1 at Cape Canaveral, marking the first successful recovery of an orbital-class booster that was later reflown. \ue200cite\ue202turn1search12\ue201 (Blue Origin had landed the sub-orbital New Shepard booster a month earlier on 23 November 2015, but Falcon 9 was the first reusable orbital-class rocket.) Therefore, the first company to create a truly reusable rocket capable of reaching orbit was SpaceX."}

If I remove text_format, the request works as intended.

1 Like

I am also struggling with this issue and have raised it with Open AI. Do you have a work around that removes these citation markers?

When client.responses.parse method (specifying text_format schema using Pydantic) is used with web_search as a tool, the below error occurs frequently
This error occurs within OpenAI when OpenAI parses the response before the response object is even generated. Even response id is not generated.
Invalid JSON: EOF while parsing a list at line 1 column 3467 [type=json_invalid, input_value='{“business_info”:[{"valu… \r \r \r \r \r ', input_type=str]
Also gpt 5 doesnt work web_search and client.responses.parse method but gpt 4.1 does.

this issue still exists as of today 28-Dec-25.
**
WebSearchTool with Structured Outputs causes JSON truncation (EOF error) - response grows unbounded**

Environment

  • Model: gpt-4.1-mini-2025-04-14

  • API: Responses API with WebSearchTool

  • Output: Structured Outputs (Pydantic schema)

  • Parameters tested:

  • max_output_tokens=32768 (model max)

  • search_context_size=“low” (minimum)

Problem Description

When using WebSearchTool with structured outputs, the API returns truncated JSON that fails Pydantic validation with:

Invalid JSON: EOF while parsing a list at line X column Y

The response is cut off mid-JSON, producing invalid output regardless of prompt instructions or parameter settings.

Reproduction Steps

  1. Create a Responses API request with:
  • WebSearchTool enabled

  • Structured output schema (Pydantic model)

  • A company/entity search query

  1. Observe truncated JSON in response

Test Results

Attempt Truncation Point Duration Prompt Strategy
1 column 6,791 ~20s Basic
2 column 34,601 ~3.8 min Added max_output_tokens=32768
3 column 48,433 ~4.8 min Added “keep response concise, max 3 items per field”

Key observation: Adding instructions to be concise made the response larger, not smaller. The model appears to ignore output length guidance when web search fills the context.

Workarounds Attempted (None Fully Effective)

  1. :white_check_mark: Set max_output_tokens=32768 - Response grew but still truncated

  2. :white_check_mark: Set search_context_size=“low” - No improvement

  3. :white_check_mark: Added prompt: “Ensure JSON is valid and complete” - No improvement

  4. :white_check_mark: Added prompt: “Maximum 3 items per field, prioritize quality” - Response grew larger

  5. :white_check_mark: Simplified schema to fewer fields - Still truncates

Expected Behavior

  • The API should return valid, parseable JSON that conforms to the schema

  • If context is exhausted, the model should gracefully close the JSON structure

  • search_context_size=“low” should limit internal context consumption

Actual Behavior

  • Web search appears to consume unbounded context internally

  • Model generates partial JSON until some limit is hit

  • Response is truncated mid-structure with no closing brackets

  • No error returned - API reports success with invalid JSON payload

Workaround Implemented

We catch the Pydantic validation error and extract partial data from the truncated response for logging/debugging, but this is not a production-viable solution.

Related Issues

Request

  1. Fix the internal context management for WebSearchTool

  2. If truncation is unavoidable, ensure JSON is properly closed before returning

  3. Return an appropriate error/warning when web search context exceeds limits