{"record":{"id":"763111ef717250ee","repo":"deepset-ai/haystack","slug":"the-prompt-must-not-have-any-variables-only-instr","errorCode":null,"errorMessage":"The prompt must not have any variables, only instructions on how to extract the content of the the image-based document. Found {','.join(variables)} in the prompt.","messagePattern":"The prompt must not have any variables, only instructions on how to extract the content of the the image-based document\\. Found (.+?) in the prompt\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"haystack/components/extractors/image/llm_document_content_extractor.py","lineNumber":251,"sourceCode":"        Deserializes the component from a dictionary.\n\n        :param data:\n            Dictionary with serialized data.\n        :returns:\n            An instance of the component.\n        \"\"\"\n        init_params = data.get(\"init_parameters\", {})\n        deserialize_chatgenerator_inplace(init_params, key=\"chat_generator\")\n\n        return default_from_dict(cls, data)\n\n    @staticmethod\n    def _validate_prompt_no_variables(prompt: str) -> None:\n        ast = SandboxedEnvironment().parse(prompt)\n        template_variables = meta.find_undeclared_variables(ast)\n        variables = list(template_variables)\n        if variables:\n            raise ValueError(\n                f\"The prompt must not have any variables, only instructions on how to extract the content of the \"\n                f\"the image-based document. Found {','.join(variables)} in the prompt.\"\n            )\n\n    @staticmethod\n    def _process_response(response_text: str) -> tuple[str | None, dict[str, Any], str | None]:\n        \"\"\"\n        Parse LLM response. Returns (content, meta_updates, error).\n\n        - Plain string (non-JSON): use entire response as document content;\n        - Valid JSON object: use key ``document_content`` for Document.content and all other keys for Document.metadata;\n        - Valid JSON but not an object (e.g. array or primitive), report an error;\n        \"\"\"\n        try:\n            parsed = _parse_dict_from_json(response_text, raise_on_failure=True)\n        except json.JSONDecodeError:\n            return response_text, {}, None\n        except ValueError:","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/extractors/image/llm_document_content_extractor.py#L233-L269","documentation":"LLMDocumentContentExtractor renders its prompt template with the image document content only; the user-supplied prompt must therefore contain no Jinja variables. Any undeclared variable found by parsing the template triggers ValueError.","triggerScenarios":"Passing a prompt like \"Extract the text from {{ document }}\" to LLMDocumentContentExtractor(prompt=...); any prompt containing {{ ... }} placeholders fails _validate_prompt_no_variables at construction.","commonSituations":"Copying a prompt from LLMMetadataExtractor (which requires a 'document' variable) into the image extractor; templated prompts reused across components.","solutions":["Rewrite the prompt as plain instructions with no {{ }} variables, e.g. \"Extract all text content from the image\"","Remove any variable placeholders copied from other extractor components","If you need variable substitution, use a different component (e.g. PromptBuilder) instead"],"exampleFix":"// before\nextractor = LLMDocumentContentExtractor(prompt=\"Extract the content of {{ document }}\")\n// after\nextractor = LLMDocumentContentExtractor(prompt=\"Extract all textual content from the provided image\")","handlingStrategy":"validation","validationCode":"from jinja2 import meta, Environment\nvars_ = meta.find_undeclared_variables(Environment().parse(prompt))\nif vars_:\n    raise ValueError(f\"Prompt must not contain variables: {vars_}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write image-extractor prompts as plain instructions with no {{ }} placeholders","Do not copy prompts from LLMMetadataExtractor into the image extractor","Assert no '{{' appears in the prompt in tests or config validation"],"tags":["python","validation","jinja-template"],"backgroundTag":"invalid-template-variables","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}