AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Structured Output Agent Fails With OpenAI Phased Responses Containing Multiple Text Parts

LangChain's ProviderStrategyBinding.parse concatenates all text blocks from an AIMessage and attempts to parse them as a single JSON document. When OpenAI returns phased output with 'commentary' and 'final_answer', two JSON objects are concatenated, causing 'JSONDecodeError: Extra data'.

highConfidence 87%LangchainAgentsVector StoresEmbeddingsAffected V1.2.13

Origin Analysis

The parse method extracts raw_text by joining every text block's content from the message list without considering phases. OpenAI Responses API can emit multiple text parts with different phases, leading to adjacent JSON objects that json.loads rejects.
1. Create an AIMessage with content list containing two dicts of type 'text': one phase='commentary' with a JSON string, another phase='final_answer' with a different JSON string. 2. Instantiate ProviderStrategyBinding with a Pydantic schema and call parse(message). 3. Observe ValueError due to json.JSONDecodeError: Extra data.

Fixing Code Block

Edge Case Audit

This patch changes behavior when multiple text blocks without phase labels contain valid JSON: it may select the first valid block instead of the previously concatenated string, which could return unexpected data. The fallback concatenation can still trigger the original error if no block parses individually. The method is stateless and thread-safe, so no concurrency issues are expected. To roll back, restore the original parse method that simply concatenates all text blocks. Test thoroughly with OpenAI responses that include commentary, final_answer, and multiple unrelated text outputs.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state