{"record":{"id":"591ca967b46606c7","repo":"microsoft/graphrag","slug":"template-template-name-not-found","errorCode":null,"errorMessage":"Template '{template_name}' not found.","messagePattern":"Template '(.+?)' not found\\.","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"packages/graphrag-llm/graphrag_llm/templating/jinja_template_engine.py","lineNumber":40,"sourceCode":"    def __init__(self, *, template_manager: \"TemplateManager\", **kwargs: Any) -> None:\n        \"\"\"Initialize the template engine.\n\n        Args\n        ----\n            template_manager: TemplateManager\n                The template manager to use for loading templates.\n        \"\"\"\n        self._templates = {}\n        self._template_manager = template_manager\n\n    def render(self, template_name: str, context: dict[str, Any]) -> str:\n        \"\"\"Render a template with the given context.\"\"\"\n        jinja_template = self._templates.get(template_name)\n        if jinja_template is None:\n            template_contents = self._template_manager.get(template_name)\n            if template_contents is None:\n                msg = f\"Template '{template_name}' not found.\"\n                raise KeyError(msg)\n            jinja_template = Template(template_contents, undefined=StrictUndefined)\n            self._templates[template_name] = jinja_template\n        try:\n            return jinja_template.render(**context)\n        except UndefinedError as e:\n            msg = f\"Missing key in context for template '{template_name}': {e.message}\"\n            raise KeyError(msg) from e\n        except Exception as e:\n            msg = f\"Error rendering template '{template_name}': {e!s}\"\n            raise RuntimeError(msg) from e\n\n    @property\n    def template_manager(self) -> \"TemplateManager\":\n        \"\"\"Template manager associated with this engine.\"\"\"\n        return self._template_manager\n","sourceCodeStart":22,"sourceCodeEnd":56,"githubUrl":"https://github.com/microsoft/graphrag/blob/f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704/packages/graphrag-llm/graphrag_llm/templating/jinja_template_engine.py#L22-L56","documentation":"JinjaTemplateEngine.render raises this KeyError when the named template cannot be found: it is not in the in-memory cache and the underlying TemplateManager.get() returned None for it. This is the template-resolution failure path before any Jinja compilation happens.","triggerScenarios":"Calling render(template_name, context) with a name that has no corresponding template file (wrong name, missing extension handling, or the templates directory simply lacks the file).","commonSituations":"Template file renamed or not deployed, name mismatch (e.g. 'prompt' vs 'prompt.txt' depending on template_extension), or using an in-memory template manager without registering the template.","solutions":["Check what templates exist: list files in the templates directory or keys registered on the template manager","Correct the template name to match, respecting the configured template_extension","Add/deploy the missing template file","If using a custom TemplateManager, ensure it registers templates under the expected names"],"exampleFix":"# before\nengine.render(\"summarze\", ctx)\n\n# after\nengine.render(\"summarize\", ctx)","handlingStrategy":"type-guard","validationCode":"if engine.template_manager.get(template_name) is None:\n    raise KeyError(f\"Missing template: {template_name}\")","typeGuard":"def template_exists(engine, name: str) -> bool:\n    return engine.template_manager.get(name) is not None","tryCatchPattern":"try:\n    out = engine.render(name, ctx)\nexcept KeyError as e:\n    if \"not found\" in str(e):\n        # surface missing-template error with dir listing for debugging\n        raise\n    raise","preventionTips":["Preflight check template_manager.get(name) before render","Standardize template naming and extension conventions","Ship a template manifest and assert it at startup"],"tags":["graphrag-llm","templating","jinja2","missing-template"],"backgroundTag":"template-not-found","analyzedSha":"f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704","analyzedAt":"2026-08-27T11:16:29.677Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}