run-llama/llama_index · error · ValueError

Must provide either prompt or prompt_template_str.

Error message

Must provide either prompt or prompt_template_str.

What it means

Error "Must provide either prompt or prompt_template_str." thrown in run-llama/llama_index.

Source

Thrown at llama-index-core/llama_index/core/program/function_program.py:116

        prompt: Optional[BasePromptTemplate] = None,
        llm: Optional[LLM] = None,
        verbose: bool = False,
        allow_parallel_tool_calls: bool = False,
        tool_choice: Optional[Union[str, Dict[str, Any]]] = None,
        tool_required: bool = True,
        **kwargs: Any,
    ) -> "FunctionCallingProgram":
        llm = llm or Settings.llm  # type: ignore
        assert llm is not None

        if not llm.metadata.is_function_calling_model:
            raise ValueError(
                f"Model name {llm.metadata.model_name} does not support "
                "function calling API. "
            )

        if prompt is None and prompt_template_str is None:
            raise ValueError("Must provide either prompt or prompt_template_str.")
        if prompt is not None and prompt_template_str is not None:
            raise ValueError("Must provide either prompt or prompt_template_str.")
        if prompt_template_str is not None:
            prompt = PromptTemplate(prompt_template_str)

        return cls(
            output_cls=output_cls,
            llm=llm,  # type: ignore
            prompt=cast(PromptTemplate, prompt),
            tool_choice=tool_choice,
            allow_parallel_tool_calls=allow_parallel_tool_calls,
            tool_required=tool_required,
            verbose=verbose,
        )

    @property
    def output_cls(self) -> Type[Model]:
        return self._output_cls

View on GitHub (pinned to afd0fef371)

Solutions

  1. Provide either a prompt object or prompt_template_str when constructing the program.
  2. Create a PromptTemplate from your template string and pass it as prompt.

When it happens

Trigger: Thrown at llama-index-core/llama_index/core/program/function_program.py:116 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/f4565f9d2ec9adf9. Report an issue: GitHub.