{"record":{"id":"d16f762569d21e65","repo":"run-llama/llama_index","slug":"program-factory-not-supported-without-structured-a","errorCode":null,"errorMessage":"Program factory not supported without structured answer filtering.","messagePattern":"Program factory not supported without structured answer filtering\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/response_synthesizers/refine.py","lineNumber":248,"sourceCode":"            chat_prompt_helper=chat_prompt_helper,\n            streaming=streaming,\n            multimodal=multimodal,\n        )\n        self._text_qa_template = text_qa_template or DEFAULT_TEXT_QA_PROMPT_SEL\n        self._refine_template = refine_template or DEFAULT_REFINE_PROMPT_SEL\n        self._chat_content_qa_template = (\n            chat_content_qa_template or CHAT_CONTENT_QA_PROMPT\n        )\n        self._chat_content_refine_template = (\n            chat_content_refine_template or CHAT_CONTENT_REFINE_PROMPT\n        )\n        self._verbose = verbose\n        self._structured_answer_filtering = structured_answer_filtering\n        self._output_cls = output_cls\n        self._response_padding_size = response_padding_size\n\n        if not self._structured_answer_filtering and program_factory is not None:\n            raise ValueError(\n                \"Program factory not supported without structured answer filtering.\"\n            )\n        self._program_factory = program_factory or self._default_program_factory\n\n    def _get_prompts(self) -> PromptDictType:\n        \"\"\"Get prompts.\"\"\"\n        return {\n            \"text_qa_template\": self._text_qa_template,\n            \"refine_template\": self._refine_template,\n            \"chat_content_qa_template\": self._chat_content_qa_template,\n            \"chat_content_refine_template\": self._chat_content_refine_template,\n        }\n\n    def _update_prompts(self, prompts: PromptDictType) -> None:\n        \"\"\"Update prompts.\"\"\"\n        if \"text_qa_template\" in prompts:\n            self._text_qa_template = prompts[\"text_qa_template\"]\n        if \"refine_template\" in prompts:","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/response_synthesizers/refine.py#L230-L266","documentation":"Refine's structured answer filtering uses a program (a structured LLM extractor) to decide whether a refined answer actually improved. Passing program_factory only makes sense in that flow, so Refine.__init__ raises ValueError when program_factory is not None but structured_answer_filtering=False. Note program_factory defaults to _default_program_factory when omitted.","triggerScenarios":"Constructing Refine(program_factory=my_factory, structured_answer_filtering=False); copying config from a refine setup that had structured filtering on, then disabling the flag but keeping the factory; toggling structured_answer_filtering off to save tokens while leaving a program factory in place.","commonSituations":"Config-driven synthesizer setup where the two options are set independently; refactors that flip the flag without cleaning the factory argument.","solutions":["Set structured_answer_filtering=True if you want to use the program factory.","Or drop the program_factory argument entirely when running with structured_answer_filtering=False."],"exampleFix":"# before\nsynth = Refine(\n    program_factory=my_factory,\n    structured_answer_filtering=False,\n)\n\n# after\nsynth = Refine(\n    program_factory=my_factory,\n    structured_answer_filtering=True,\n)","handlingStrategy":"validation","validationCode":"if program_factory is not None:\n    assert structured_answer_filtering, \"program_factory requires structured_answer_filtering=True\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat program_factory and structured_answer_filtering as one coupled config pair.","Remove the factory argument whenever you disable structured filtering."],"tags":["response-synthesizer","refine","configuration","initialization"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}