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

[Bug]: Refine With Streaming=True And Output_cls Returns "Empty Response"

When Refine or CompactAndRefine is built with both streaming=True and an output_cls, the structured output is discarded and synthesize/asynthesize return a plain Response with text 'Empty Response'.

highConfidence 92%Llama_indexIndexingVectorStoreIndexDocument ProcessingAffected V0.14.25

Origin Analysis

In llama_index/core/response_synthesizers/refine.py, DefaultRefineProgram.stream_call and astream_call only yield when the streamed object has an attribute named 'answer'. When output_cls is set, stream_structured_predict yields user-defined Pydantic objects that lack 'answer', so the generator yields nothing. _update_response then receives no structured response and returns None, which the caller converts to 'Empty Response'.
1. Define a Pydantic model Foo with fields name and age. 2. Create a FakeLLM subclass that implements stream_structured_predict / astream_structured_predict to yield Foo(name='bob', age=3) objects. 3. Instantiate Refine or CompactAndRefine with llm=FakeLLM(), output_cls=Foo, streaming=True. 4. Call synthesize or asynthesize with a query and a list of NodeWithScore. 5. Observe that the response is a plain Response with text 'Empty Response' instead of a PydanticResponse containing Foo.

Fixing Code Block

Edge Case Audit

This hotfix assumes that the structured output can be fully serialized to JSON; output_cls models with non-serializable fields (e.g., datetime, custom types) will raise serialization errors. Streaming may yield multiple partial JSON strings, causing repeated parsing attempts and potentially invalid intermediate JSON. Async and sync generators must be consumed exactly once; if the caller abandons iteration early, the stream may be left open, leaking resources. The method signatures and internal prompt formatting are based on llama-index-core 0.14.25; upgrading to a future version that changes DefaultRefineProgram internals may require re-applying the fix. To roll back, restore the original stream_call/astream_call implementations or use streaming=False with output_cls until an official fix is released.

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