{"record":{"id":"bd9c8e6be90e4857","repo":"deepset-ai/haystack","slug":"error-adapting-self-template-with-kwargs-e","errorCode":null,"errorMessage":"Error adapting {self.template} with {kwargs}: {e}","messagePattern":"Error adapting (.+?) with (.+?): (.+?)","errorType":"exception","errorClass":"OutputAdaptationException","httpStatus":null,"severity":"error","filePath":"haystack/components/converters/output_adapter.py","lineNumber":145,"sourceCode":"            self._env.filters[name] = filter_func\n        adapted_outputs = {}\n        try:\n            adapted_output_template = self._env.from_string(self.template)\n            output_result = adapted_output_template.render(**kwargs)\n            if isinstance(output_result, jinja2.runtime.Undefined):\n                raise OutputAdaptationException(f\"Undefined variable in the template {self.template}; kwargs: {kwargs}\")  # noqa: TRY301\n\n            # We suppress the exception in case the output is already a string, otherwise\n            # we try to evaluate it and would fail.\n            # This must be done cause the output could be different literal structures.\n            # This doesn't support any user types.\n            with contextlib.suppress(Exception):\n                if not self._unsafe:\n                    output_result = ast.literal_eval(output_result)\n\n            adapted_outputs[\"output\"] = output_result\n        except Exception as e:\n            raise OutputAdaptationException(f\"Error adapting {self.template} with {kwargs}: {e}\") from e\n        return adapted_outputs\n\n    def to_dict(self) -> dict[str, Any]:\n        \"\"\"\n        Serializes the component to a dictionary.\n\n        :returns:\n            Dictionary with serialized data.\n        \"\"\"\n        se_filters = {name: serialize_callable(filter_func) for name, filter_func in self.custom_filters.items()}\n        return default_to_dict(\n            self,\n            template=self.template,\n            output_type=serialize_type(self.output_type),\n            custom_filters=se_filters,\n            unsafe=self._unsafe,\n        )\n","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/converters/output_adapter.py#L127-L163","documentation":"OutputAdapter.run wraps template rendering in a try/except and re-raises any failure (Jinja runtime errors, ast.literal_eval failures on non-literal outputs, type errors) as OutputAdaptationException including the template, kwargs, and original exception message.","triggerScenarios":"Rendering raises any Exception: calling methods/filters on undefined or wrong-typed values, division errors, filters not registered, or the rendered string failing ast.literal_eval when _unsafe=False and output is not a literal.","commonSituations":"Templates doing arithmetic on strings; custom filters omitted from custom_filters; output being a plain sentence that literal_eval cannot parse.","solutions":["Read the chained exception message to find the underlying render/eval failure","Fix the template expression or supply correctly-typed inputs","Register any custom filter used by the template via custom_filters","Set unsafe=True if you intentionally need non-literal evaluation (trust the template source)"],"exampleFix":"// before\n{{ count / total }}  # total is a string -> render error\n// after\n{{ count / (total | int) }}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = adapter.run(**kwargs)\nexcept OutputAdaptationException as e:\n    log.error(\"OutputAdapter failed: %s\", e)\n    raise  # inspect chained cause for the root render/eval error","preventionTips":["Register every custom filter used by the template via custom_filters","Ensure rendered expressions are valid Python literals or run with unsafe=True intentionally","Test templates with representative inputs before production"],"tags":["python","haystack","jinja","render-failure","output-adapter"],"backgroundTag":"template-render-failed","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}