{"record":{"id":"5d65b53f4346ebb9","repo":"run-llama/llama_index","slug":"this-class-is-deprecated-use-any-llm-class-direct","errorCode":null,"errorMessage":"This class is deprecated. Use any LLM class directly.","messagePattern":"This class is deprecated\\. Use any LLM class directly\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/service_context_elements/llm_predictor.py","lineNumber":83,"sourceCode":"    async def astream(\n        self, prompt: BasePromptTemplate, **prompt_args: Any\n    ) -> TokenAsyncGen:\n        \"\"\"Async predict the answer to a query.\"\"\"\n\n\nclass LLMPredictor(BaseLLMPredictor):\n    \"\"\"\n    LLM predictor class.\n\n    NOTE: Deprecated. Use any LLM class directly.\n    \"\"\"\n\n    def __init__(\n        self,\n        **kwargs: Any,\n    ) -> None:\n        \"\"\"Initialize params.\"\"\"\n        raise ValueError(\"This class is deprecated. Use any LLM class directly.\")\n","sourceCodeStart":65,"sourceCodeEnd":84,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/service_context_elements/llm_predictor.py#L65-L84","documentation":"LLMPredictor.__init__ is a hard-removal stub: constructing this deprecated wrapper always raises. Since llama-index v0.10 an LLM instance (e.g. OpenAI, Anthropic) is used directly and configured via Settings.llm or an llm= argument; the predictor layer no longer exists.","triggerScenarios":"Instantiating LLMPredictor(...) or LLMPredictor(), often as service_context=ServiceContext.from_defaults(llm_predictor=LLMPredictor(...)) in pre-0.10 code, or via a dependency that wraps LLM calls through the old predictor abstraction.","commonSituations":"Upgrading from llama_index < 0.10, reusing old tutorial/notebook code that predates the predictor removal, or internal wrappers that standardized on LLMPredictor for prompt handling and token accounting.","solutions":["Replace LLMPredictor(...) with a direct LLM instance such as OpenAI(model='gpt-4o-mini') and set Settings.llm = llm.","Where llm_predictor was passed into an index/query call, pass llm=<instance> instead.","For token/cost accounting that LLMPredictor used to provide, use the callbacks mechanism (TokenCountingHandler) instead.","Upgrade any third-party package that still instantiates LLMPredictor."],"exampleFix":"# before\nfrom llama_index.core.service_context_elements.llm_predictor import LLMPredictor\nllm_predictor = LLMPredictor(llm=OpenAI(temperature=0))\n\n# after\nfrom llama_index.core import Settings\nfrom llama_index.llms.openai import OpenAI\nSettings.llm = OpenAI(temperature=0)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    LLMPredictor()\nexcept ValueError as e:\n    if 'deprecated' in str(e):\n        Settings.llm = OpenAI()  # use an LLM class directly\n    else:\n        raise","preventionTips":["Use concrete LLM classes (OpenAI, Anthropic, etc.) and Settings.llm; never import service_context_elements.llm_predictor.","Use TokenCountingHandler callbacks for token accounting previously done by LLMPredictor.","Add a lint rule forbidding LLMPredictor imports."],"tags":["deprecation","llm","llm-predictor","migration","llama-index"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}