{"record":{"id":"5fdf7ad80fba8a94","repo":"microsoft/graphrag","slug":"templates-directory-base-dir-does-not-exist-or","errorCode":null,"errorMessage":"Templates directory '{base_dir}' does not exist or is not a directory.","messagePattern":"Templates directory '(.+?)' does not exist or is not a directory\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/graphrag-llm/graphrag_llm/templating/file_template_manager.py","lineNumber":51,"sourceCode":"                The file extension for template files.\n            encoding: str (default=\"utf-8\")\n                The encoding used to read template files.\n\n        Raises\n        ------\n            ValueError\n                If the base directory does not exist or is not a directory.\n                If the template_extension is an empty string.\n        \"\"\"\n        self._templates = {}\n        self._encoding = encoding\n\n        self._templates_extension = template_extension\n\n        self._templates_dir = Path(base_dir).resolve()\n        if not self._templates_dir.exists() or not self._templates_dir.is_dir():\n            msg = f\"Templates directory '{base_dir}' does not exist or is not a directory.\"\n            raise ValueError(msg)\n\n    def get(self, template_name: str) -> str | None:\n        \"\"\"Retrieve a template by its name.\"\"\"\n        template_file = (\n            self._templates_dir / f\"{template_name}{self._templates_extension}\"\n        )\n        if template_file.exists() and template_file.is_file():\n            return template_file.read_text(encoding=self._encoding)\n        return None\n\n    def register(self, template_name: str, template: str) -> None:\n        \"\"\"Register a new template.\"\"\"\n        self._templates[template_name] = template\n        template_path = (\n            self._templates_dir / f\"{template_name}{self._templates_extension}\"\n        )\n        template_path.write_text(template, encoding=self._encoding)\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/microsoft/graphrag/blob/f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704/packages/graphrag-llm/graphrag_llm/templating/file_template_manager.py#L33-L69","documentation":"FileTemplateManager.__init__ raises this ValueError when base_dir does not exist on disk or is not a directory. The path is resolved with Path.resolve() and checked with exists()/is_dir() before the manager is usable, failing fast so template lookups never silently return nothing.","triggerScenarios":"Constructing FileTemplateManager(base_dir=...) where base_dir points to a missing folder, a file instead of a directory, or a relative path that resolves against an unexpected working directory.","commonSituations":"Deployments where templates directory is not packaged/copied, wrong relative path assumptions (cwd changes between dev and prod), or passing a template file path instead of its directory.","solutions":["Verify the path exists and is a directory (os.path.isdir) before constructing the manager","Use absolute paths or resolve paths relative to your package/module (__file__) instead of cwd","Create the templates directory or fix packaging so it ships with your app","If the path may be relative to cwd, resolve it explicitly before passing"],"exampleFix":"# before\nmgr = FileTemplateManager(base_dir=\"templates\")\n\n# after\nfrom pathlib import Path\nbase = Path(__file__).parent / \"templates\"\nmgr = FileTemplateManager(base_dir=str(base))","handlingStrategy":"validation","validationCode":"import os\n\nif not os.path.isdir(base_dir):\n    raise ValueError(f\"Templates dir missing: {base_dir}\")\nmgr = FileTemplateManager(base_dir=base_dir)","typeGuard":"import os\n\ndef is_valid_templates_dir(p: str) -> bool:\n    return os.path.isdir(p)","tryCatchPattern":"try:\n    mgr = FileTemplateManager(base_dir=base_dir)\nexcept ValueError as e:\n    if \"does not exist or is not a directory\" in str(e):\n        # create dir or point to a packaged path\n        raise\n    raise","preventionTips":["Resolve template paths relative to your module, not cwd","Verify the templates dir exists in deployment packaging (wheel/docker image)","Add a startup check for required asset directories"],"tags":["graphrag-llm","templating","filesystem","path-validation"],"backgroundTag":"directory-not-found","analyzedSha":"f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704","analyzedAt":"2026-08-27T11:16:29.677Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}