{"record":{"id":"ea9eb79d1610b51d","repo":"run-llama/llama_index","slug":"expected-response-object-got-type-answer-obj-i","errorCode":null,"errorMessage":"Expected Response object, got {type(answer_obj)} instead.","messagePattern":"Expected Response object, got (.+?) instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/query_engine/flare/base.py","lineNumber":223,"sourceCode":"            lookahead_resp = lookahead_resp.strip()\n            if self._verbose:\n                print_text(f\"Lookahead response: {lookahead_resp}\\n\", color=\"pink\")\n\n            is_done, fmt_lookahead = self._done_output_parser.parse(lookahead_resp)\n            if is_done:\n                cur_response = cur_response.strip() + \" \" + fmt_lookahead.strip()\n                break\n\n            # parse lookahead response into query tasks\n            query_tasks = self._query_task_output_parser.parse(lookahead_resp)\n\n            # get answers for each query task\n            query_tasks = query_tasks[: self._max_lookahead_query_tasks]\n            query_answers = []\n            for _, query_task in enumerate(query_tasks):\n                answer_obj = self._query_engine.query(query_task.query_str)\n                if not isinstance(answer_obj, Response):\n                    raise ValueError(\n                        f\"Expected Response object, got {type(answer_obj)} instead.\"\n                    )\n                query_answer = str(answer_obj)\n                query_answers.append(query_answer)\n                source_nodes.extend(answer_obj.source_nodes)\n\n            # fill in the lookahead response template with the query answers\n            # from the query engine\n            updated_lookahead_resp = self._lookahead_answer_inserter.insert(\n                lookahead_resp, query_tasks, query_answers, prev_response=cur_response\n            )\n\n            # get \"relevant\" lookahead response by truncating the updated\n            # lookahead response until the start position of the first tag\n            # also remove the prefix from the lookahead response, so that\n            # we can concatenate it with the existing response\n            relevant_lookahead_resp_wo_prefix = self._get_relevant_lookahead_response(\n                updated_lookahead_resp","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/query_engine/flare/base.py#L205-L241","documentation":"FLAREQueryEngine decomposes generation into lookahead steps and calls self._query_engine.query(...) for each sub-question, then does `str(answer_obj)` and reads .source_nodes — both only exist on a (non-streaming) Response. If the wrapped query engine returns anything else (StreamingResponse, AgentOutput, a plain string engine, etc.), it raises ValueError with the offending type name.","triggerScenarios":"Constructing FLAREQueryEngine(query_engine=...) with an inner engine configured for streaming (e.g. RetrieverQueryEngine with a streaming response_synthesizer), or with a custom/agent engine whose query() returns a non-Response object. The error surfaces on the first lookahead step, inside FLAREQueryEngine._query.","commonSituations":"Reusing an engine built for chat/streaming UX as FLARE's inner engine; passing a CustomQueryEngine (returns str) as query_engine; building the inner engine with RetrieverQueryEngine.from_args(..., streaming=True) or a response_mode that yields streaming responses.","solutions":["Give FLARE a plain RetrieverQueryEngine built without streaming: RetrieverQueryEngine.from_args(retriever=..., response_mode='compact') (streaming off by default).","If you passed a custom engine, wrap it so query() returns Response(source_nodes=[...], response=...), or use llama_index.core.response.Response directly.","Ensure any custom response synthesizer you inject into the inner engine is non-streaming (streaming=False).","Check for the type before wiring: a one-off `type(inner.query('ping'))` in a scratch script confirms it is `llama_index.core.response.Response`."],"exampleFix":"# before\ninner = RetrieverQueryEngine.from_args(\n    retriever=retriever,\n    response_synthesizer=get_response_synthesizer(streaming=True),  # returns StreamingResponse\n)\nflare = FLAREQueryEngine(query_engine=inner)  # -> ValueError at first lookahead\n\n# after\ninner = RetrieverQueryEngine.from_args(\n    retriever=retriever,\n    response_mode=\"compact\",  # non-streaming -> returns Response\n)\nflare = FLAREQueryEngine(query_engine=inner, retriever=retriever)","handlingStrategy":"validation","validationCode":"from llama_index.core.response import Response\n\ndef assert_engine_returns_response(engine, probe: str = \"ping\") -> None:\n    out = engine.query(probe)\n    if not isinstance(out, Response):\n        raise TypeError(\n            f\"FLARE requires a non-streaming Response; inner engine returned {type(out).__name__}. \"\n            \"Rebuild with RetrieverQueryEngine.from_args(...) and streaming off.\"\n        )\n\nassert_engine_returns_response(inner_engine)  # before FLAREQueryEngine(...)","typeGuard":"from llama_index.core.response import Response, StreamingResponse\n\ndef returns_plain_response(engine) -> bool:\n    out = engine.query(\"probe\")\n    return isinstance(out, Response) and not isinstance(out, StreamingResponse)","tryCatchPattern":null,"preventionTips":["Build FLARE's inner engine with RetrieverQueryEngine.from_args() and no streaming synthesizer.","Probe the inner engine once with type(inner.query('ping')) before wiring FLARE.","Never reuse a chat/streaming UX engine as FLARE's query_engine."],"tags":["llama-index","flare","query-engine","streaming","active-retrieval"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}