run-llama/llama_index · error · ValueError
Prompt should have output parser.
Error message
Prompt should have output parser.
What it means
LLMQuestionGenerator parses the LLM's sub-question output with prompt.output_parser. The constructor requires the prompt template to carry an output parser (a SubQuestionOutputParser) so parsed text can become SubQuestion objects; without one it raises ValueError('Prompt should have output parser.')
Source
Thrown at llama-index-core/llama_index/core/question_gen/llm_generators.py:30
)
from llama_index.core.question_gen.types import BaseQuestionGenerator, SubQuestion
from llama_index.core.schema import QueryBundle
from llama_index.core.settings import Settings
from llama_index.core.tools.types import ToolMetadata
from llama_index.core.types import BaseOutputParser
class LLMQuestionGenerator(BaseQuestionGenerator):
def __init__(
self,
llm: LLM,
prompt: BasePromptTemplate,
) -> None:
self._llm = llm
self._prompt = prompt
if self._prompt.output_parser is None:
raise ValueError("Prompt should have output parser.")
@classmethod
def from_defaults(
cls,
llm: Optional[LLM] = None,
prompt_template_str: Optional[str] = None,
output_parser: Optional[BaseOutputParser] = None,
) -> "LLMQuestionGenerator":
# optionally initialize defaults
llm = llm or Settings.llm
prompt_template_str = prompt_template_str or DEFAULT_SUB_QUESTION_PROMPT_TMPL
output_parser = output_parser or SubQuestionOutputParser()
# construct prompt
prompt = PromptTemplate(
template=prompt_template_str,
output_parser=output_parser,
prompt_type=PromptType.SUB_QUESTION,View on GitHub (pinned to afd0fef371)
Solutions
- Attach the parser when building a custom prompt: PromptTemplate(template, output_parser=SubQuestionOutputParser())
- Or prefer from_defaults(prompt_template_str=...) which wires SubQuestionOutputParser automatically
- Keep the {output_cls} / JSON structure tokens in a custom template so the parser still works
Example fix
// before from llama_index.core import PromptTemplate prompt = PromptTemplate(custom_sub_question_template) # no parser gen = LLMQuestionGenerator(llm=llm, prompt=prompt) // after from llama_index.core.question_gen.output_parser import SubQuestionOutputParser prompt = PromptTemplate(custom_sub_question_template, output_parser=SubQuestionOutputParser()) gen = LLMQuestionGenerator(llm=llm, prompt=prompt)
Defensive patterns
Strategy: validation
Validate before calling
from llama_index.core.question_gen.output_parser import SubQuestionOutputParser
def make_question_prompt(template_str: str):
prompt = PromptTemplate(template_str)
if prompt.output_parser is None:
prompt = PromptTemplate(template_str, output_parser=SubQuestionOutputParser())
return prompt Type guard
def prompt_has_output_parser(prompt) -> bool:
"""LLMQuestionGenerator requires a parsed output."""
return prompt.output_parser is not None Prevention
- Prefer LLMQuestionGenerator.from_defaults(prompt_template_str=...) which attaches the parser
- When using a custom PromptTemplate object, always pass output_parser=SubQuestionOutputParser()
- Keep the JSON/{output_cls} structure in custom templates so the parser has something to parse
When it happens
Trigger: Instantiating LLMQuestionGenerator(llm=..., prompt=PromptTemplate(...)) with a plain PromptTemplate that has no output_parser, or from_defaults(prompt_template_str=custom_str, output_parser=None) is fine (it defaults) but a custom prompt object lacking a parser is not.
Common situations: Swapping in a custom sub-question prompt by constructing BasePromptTemplate/PromptTemplate directly without attaching SubQuestionOutputParser.
Related errors
- All agents must have a name in a multi-agent workflow
- All agents must have a description in a multi-agent workflow
- Initial state is not supported per-agent in AgentWorkflow
- Exactly one root agent must be provided
- Root agent {root_agent} not found in provided agents
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/c1a00fd1e049af91.
Report an issue: GitHub.