{"record":{"id":"43ec007da5619692","repo":"langchain-ai/langchain","slug":"path-path-is-absolute-absolute-paths-are-not","errorCode":null,"errorMessage":"Path '{path}' is absolute. Absolute paths are not allowed when loading prompt configurations to prevent path traversal attacks. Use relative paths instead, or pass `allow_dangerous_paths=True` if you trust the input.","messagePattern":"Path '(.+?)' is absolute\\. Absolute paths are not allowed when loading prompt configurations to prevent path traversal attacks\\. Use relative paths instead, or pass `allow_dangerous_paths=True` if you trust the input\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/loading.py","lineNumber":38,"sourceCode":"\n\ndef _validate_path(path: Path) -> None:\n    \"\"\"Reject absolute paths and `..` traversal components.\n\n    Args:\n        path: The path to validate.\n\n    Raises:\n        ValueError: If the path is absolute or contains `..` components.\n    \"\"\"\n    if path.is_absolute():\n        msg = (\n            f\"Path '{path}' is absolute. Absolute paths are not allowed \"\n            f\"when loading prompt configurations to prevent path traversal \"\n            f\"attacks. Use relative paths instead, or pass \"\n            f\"`allow_dangerous_paths=True` if you trust the input.\"\n        )\n        raise ValueError(msg)\n    if \"..\" in path.parts:\n        msg = (\n            f\"Path '{path}' contains '..' components. Directory traversal \"\n            f\"sequences are not allowed when loading prompt configurations. \"\n            f\"Use direct relative paths instead, or pass \"\n            f\"`allow_dangerous_paths=True` if you trust the input.\"\n        )\n        raise ValueError(msg)\n\n\n@deprecated(\n    since=\"1.2.21\",\n    removal=\"2.0.0\",\n    alternative=\"Use `dumpd`/`dumps` from `langchain_core.load` to serialize \"\n    \"prompts and `load`/`loads` to deserialize them.\",\n)\ndef load_prompt_from_config(\n    config: dict[str, Any], *, allow_dangerous_paths: bool = False","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/loading.py#L20-L56","documentation":"`_validate_path` in `langchain_core.prompts.loading` rejects absolute paths when loading prompt configuration files (default behavior, `allow_dangerous_paths=False`). This is a path-traversal defense: absolute paths let a malicious prompt config point the loader at arbitrary files on the host.","triggerScenarios":"Calling `load_prompt('/home/user/prompts/config.json')` or a config with `template_path: /etc/passwd`-style absolute references without passing `allow_dangerous_paths=True`.","commonSituations":"Scripts that store prompt YAMLs at absolute locations (common in notebooks/containers); loading third-party or hub-downloaded prompt configs that reference templates by absolute path; CI pipelines with fixed workspace paths.","solutions":["Pass a path relative to your current working directory: `load_prompt('prompts/config.json')`.","If you fully trust the config source, opt in explicitly: `load_prompt(p, allow_dangerous_paths=True)`.","Change the config file so `template_path`/`example_prompt_path`/`examples` entries are relative to the config file's directory."],"exampleFix":"# before\nload_prompt('/abs/path/prompt.json')  # ValueError\n\n# after (trusted input only)\nload_prompt('/abs/path/prompt.json', allow_dangerous_paths=True)\n# or use a relative path\nload_prompt('prompts/prompt.json')","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\np = Path(user_path)\nif p.is_absolute():\n    p = Path.cwd() / p  # or reject, depending on trust\nload_prompt(str(p))","typeGuard":"from pathlib import Path\n\ndef is_relative_safe(path: str | Path) -> bool:\n    p = Path(path)\n    return not p.is_absolute() and '..' not in p.parts","tryCatchPattern":null,"preventionTips":["Store prompt bundles with configs referencing sibling files by relative path only.","Only pass allow_dangerous_paths=True for config sources you control end to end."],"tags":["prompts","security","path-traversal","loading"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}