run-llama/llama_index · error · ValueError
No prompt provided in positional or keyword arguments
Error message
No prompt provided in positional or keyword arguments
What it means
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.
Source
Thrown at llama-index-core/llama_index/core/llms/callbacks.py:308
def llm_completion_callback() -> Callable:
def wrap(f: Callable) -> Callable:
@contextmanager
def wrapper_logic(_self: Any) -> Generator[CallbackManager, None, None]:
callback_manager = getattr(_self, "callback_manager", None)
if not isinstance(callback_manager, CallbackManager):
_self.callback_manager = CallbackManager()
yield _self.callback_manager
def extract_prompt(*args: Any, **kwargs: Any) -> str:
if len(args) > 0:
return str(args[0])
elif "prompt" in kwargs:
return kwargs["prompt"]
else:
raise ValueError(
"No prompt provided in positional or keyword arguments"
)
async def wrapped_async_llm_predict(
_self: Any, *args: Any, **kwargs: Any
) -> Any:
prompt = extract_prompt(*args, **kwargs)
with (
wrapper_logic(_self) as callback_manager,
callback_manager.as_trace("completion"),
):
span_id = active_span_id.get()
model_dict = _self.to_payload()
dispatcher.event(
LLMCompletionStartEvent(
model_dict=model_dict,
prompt=prompt,
additional_kwargs=kwargs,View on GitHub (pinned to afd0fef371)
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.
Example fix
# before
resp = llm.complete(messages=[ChatMessage('hi')]) # no 'prompt' arg -> ValueError
# after
resp = llm.chat(messages=[ChatMessage('hi')])
# or for plain completion:
resp = llm.complete(prompt='hi') Defensive patterns
Strategy: validation
Validate before calling
def call_complete(llm, *args, **kwargs):
if not args and 'prompt' not in kwargs:
raise ValueError('complete() requires a prompt')
return llm.complete(*args, **kwargs) Prevention
- Always call complete() with a positional prompt
- Use chat(messages=[...]) for message lists
- Type-check dispatcher code that forwards kwargs into complete()
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- query and response must be provided
- Got empty streaming response
- Expected ActionReasoningStep, got {reasoning_step}
- This query engine does not support retrieve, use query direc
- This query engine does not support synthesize, use query dir
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/f97e26d2b70f559c.
Report an issue: GitHub.