{"record":{"id":"f97e26d2b70f559c","repo":"run-llama/llama_index","slug":"no-prompt-provided-in-positional-or-keyword-argume","errorCode":null,"errorMessage":"No prompt provided in positional or keyword arguments","messagePattern":"No prompt provided in positional or keyword arguments","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/llms/callbacks.py","lineNumber":308,"sourceCode":"\n\ndef llm_completion_callback() -> Callable:\n    def wrap(f: Callable) -> Callable:\n        @contextmanager\n        def wrapper_logic(_self: Any) -> Generator[CallbackManager, None, None]:\n            callback_manager = getattr(_self, \"callback_manager\", None)\n            if not isinstance(callback_manager, CallbackManager):\n                _self.callback_manager = CallbackManager()\n\n            yield _self.callback_manager\n\n        def extract_prompt(*args: Any, **kwargs: Any) -> str:\n            if len(args) > 0:\n                return str(args[0])\n            elif \"prompt\" in kwargs:\n                return kwargs[\"prompt\"]\n            else:\n                raise ValueError(\n                    \"No prompt provided in positional or keyword arguments\"\n                )\n\n        async def wrapped_async_llm_predict(\n            _self: Any, *args: Any, **kwargs: Any\n        ) -> Any:\n            prompt = extract_prompt(*args, **kwargs)\n            with (\n                wrapper_logic(_self) as callback_manager,\n                callback_manager.as_trace(\"completion\"),\n            ):\n                span_id = active_span_id.get()\n                model_dict = _self.to_payload()\n                dispatcher.event(\n                    LLMCompletionStartEvent(\n                        model_dict=model_dict,\n                        prompt=prompt,\n                        additional_kwargs=kwargs,","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/llms/callbacks.py#L290-L326","documentation":"Raised by the prompt-extraction helper inside the LLM callback-decorator wrapper (llms/callbacks.py) when neither a positional argument nor a 'prompt' keyword argument is present on the wrapped predict/complete call. The wrapper needs the prompt string to label the CB event trace, so a completion invoked without a prompt cannot be instrumented and fails here.","triggerScenarios":"Calling a decorated llm.complete() with no arguments, with only non-prompt kwargs (e.g. llm.complete(temperature=0)), or with the prompt under a different keyword (e.g. llm.complete(input='...', ) or messages=[...]) — chat-style calls routed through the completion wrapper.","commonSituations":"Generic dispatcher code that forwards **kwargs to complete() and sometimes passes nothing; refactoring chat() calls into complete() while keeping a messages kwarg; mocked LLMs in tests called with empty signatures that now hit the instrumented wrapper.","solutions":["Pass the prompt positionally: llm.complete('What is 2+2?') or as llm.complete(prompt='...').","For message lists, use llm.chat(messages=[...]) instead of complete().","Audit wrapper/dispatcher code that forwards kwargs to ensure 'prompt' is always present."],"exampleFix":"# before\nresp = llm.complete(messages=[ChatMessage('hi')])  # no 'prompt' arg -> ValueError\n\n# after\nresp = llm.chat(messages=[ChatMessage('hi')])\n# or for plain completion:\nresp = llm.complete(prompt='hi')","handlingStrategy":"validation","validationCode":"def call_complete(llm, *args, **kwargs):\n    if not args and 'prompt' not in kwargs:\n        raise ValueError('complete() requires a prompt')\n    return llm.complete(*args, **kwargs)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call complete() with a positional prompt","Use chat(messages=[...]) for message lists","Type-check dispatcher code that forwards kwargs into complete()"],"tags":["llm","callbacks","instrumentation","api-misuse"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}