{"record":{"id":"af0b4d23db481841","repo":"run-llama/llama_index","slug":"astream-complete-is-not-supported-by-default","errorCode":null,"errorMessage":"astream_complete is not supported by default.","messagePattern":"astream_complete is not supported by default\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/llms/structured_llm.py","lineNumber":175,"sourceCode":"                    ),\n                    raw=partial_output,\n                )\n\n        return gen()\n\n    @llm_completion_callback()\n    async def acomplete(\n        self, prompt: str, formatted: bool = False, **kwargs: Any\n    ) -> CompletionResponse:\n        complete_fn = achat_to_completion_decorator(self.achat)\n        return await complete_fn(prompt, **kwargs)\n\n    @llm_completion_callback()\n    async def astream_complete(\n        self, prompt: str, formatted: bool = False, **kwargs: Any\n    ) -> CompletionResponseGen:\n        \"\"\"Async stream completion endpoint for LLM.\"\"\"\n        raise NotImplementedError(\"astream_complete is not supported by default.\")\n","sourceCodeStart":157,"sourceCodeEnd":176,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/llms/structured_llm.py#L157-L176","documentation":"StructuredLLM deliberately does not implement astream_complete: structured prediction validates the complete JSON payload before returning, so an async token stream cannot be produced. Calling it raises NotImplementedError.","triggerScenarios":"Awaiting/iterating structured_llm.astream_complete(prompt), or running an async streaming query engine whose LLM is a StructuredLLM wrapper.","commonSituations":"Async chat frontends that always consume async streams; setting Settings.llm = llm.as_structured_llm(...) globally and forgetting that some code paths stream.","solutions":["Use await structured_llm.acomplete(prompt) for the single validated response.","Stream from the original unwrapped LLM when streaming matters more than schema validation.","Wrap acomplete's result in an async generator yielding one response if a stream-shaped API is required."],"exampleFix":"# before\nresp = await structured_llm.astream_complete(prompt)  # raises\n# after\nresp = await structured_llm.acomplete(prompt)\nasync def one_shot():\n    yield resp\nstream = one_shot()","handlingStrategy":"type-guard","validationCode":"from llama_index.core.llms.structured_llm import StructuredLLM\n\ndef supports_astream_complete(llm) -> bool:\n    return not isinstance(llm, StructuredLLM)","typeGuard":"from llama_index.core.llms.structured_llm import StructuredLLM\n\ndef is_structured_llm(llm) -> bool:\n    return isinstance(llm, StructuredLLM)","tryCatchPattern":"try:\n    stream = await structured_llm.astream_complete(prompt)\nexcept NotImplementedError:\n    resp = await structured_llm.acomplete(prompt)\n    async def _one():\n        yield resp\n    stream = _one()","preventionTips":["Do not set a StructuredLLM as Settings.llm if any async streaming path exists.","Route streaming consumers to the unwrapped LLM.","Wrap acomplete in a single-item async generator at the boundary."],"tags":["llama-index","async","structured-output","streaming","not-implemented"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}