{"record":{"id":"33cd8a845f42fb02","repo":"langchain-ai/langchain","slug":"path-path-contains-components-directory","errorCode":null,"errorMessage":"Path '{path}' contains '..' components. Directory traversal sequences are not allowed when loading prompt configurations. Use direct relative paths instead, or pass `allow_dangerous_paths=True` if you trust the input.","messagePattern":"Path '(.+?)' contains '\\.\\.' components\\. Directory traversal sequences are not allowed when loading prompt configurations\\. Use direct 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":46,"sourceCode":"    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\n) -> BasePromptTemplate[str]:\n    \"\"\"Load prompt from config dict.\n\n    Args:\n        config: Dict containing the prompt configuration.\n        allow_dangerous_paths: If `False` (default), file paths in the\n            config (such as `template_path`, `examples`, and\n            `example_prompt_path`) are validated to reject absolute paths","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/loading.py#L28-L64","documentation":"`_validate_path` rejects any path containing a `..` component when loading prompt configs (default `allow_dangerous_paths=False`). `..` segments can escape the intended directory, enabling directory-traversal attacks when loading untrusted prompt files.","triggerScenarios":"`load_prompt('prompts/../../etc/config.json')` or a config whose `template_path: ../../shared/t.txt` includes `..`, without `allow_dangerous_paths=True`.","commonSituations":"Configs written on a machine with a different directory layout (template lives one level up); prompt packages that reference shared templates across folders; testing with ad-hoc `../` paths.","solutions":["Resolve the real location and reference it via a safe relative path with no `..` components (e.g. run from a common parent directory).","If the input is trusted, pass `allow_dangerous_paths=True` to the loader.","Restructure so templates live at or below the config directory."],"exampleFix":"# before\nload_prompt('prompts/../shared/prompt.json')  # ValueError\n\n# after\nload_prompt('shared/prompt.json')  # invoke from the parent dir\n# or, for trusted input\nload_prompt('prompts/../shared/prompt.json', allow_dangerous_paths=True)","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\np = Path(user_path)\nassert '..' not in p.parts, f'reject traversal path: {p}'\nload_prompt(str(p))","typeGuard":"def has_no_traversal(path: str | Path) -> bool:\n    return '..' not in Path(path).parts","tryCatchPattern":null,"preventionTips":["Normalize and resolve user-supplied prompt paths, then verify the result stays under your prompts root.","Treat any '..' in stored config paths as a defect to fix in the config, not to bypass."],"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"}