langchain-ai/langchain · error · ValueError
Path '{path}' is absolute. Absolute paths are not allowed wh
Error message
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. What it means
`_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.
Source
Thrown at libs/core/langchain_core/prompts/loading.py:38
def _validate_path(path: Path) -> None:
"""Reject absolute paths and `..` traversal components.
Args:
path: The path to validate.
Raises:
ValueError: If the path is absolute or contains `..` components.
"""
if path.is_absolute():
msg = (
f"Path '{path}' is absolute. Absolute paths are not allowed "
f"when loading prompt configurations to prevent path traversal "
f"attacks. Use relative paths instead, or pass "
f"`allow_dangerous_paths=True` if you trust the input."
)
raise ValueError(msg)
if ".." in path.parts:
msg = (
f"Path '{path}' contains '..' components. Directory traversal "
f"sequences are not allowed when loading prompt configurations. "
f"Use direct relative paths instead, or pass "
f"`allow_dangerous_paths=True` if you trust the input."
)
raise ValueError(msg)
@deprecated(
since="1.2.21",
removal="2.0.0",
alternative="Use `dumpd`/`dumps` from `langchain_core.load` to serialize "
"prompts and `load`/`loads` to deserialize them.",
)
def load_prompt_from_config(
config: dict[str, Any], *, allow_dangerous_paths: bool = FalseView on GitHub (pinned to e32fa9a52e)
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.
Example fix
# before
load_prompt('/abs/path/prompt.json') # ValueError
# after (trusted input only)
load_prompt('/abs/path/prompt.json', allow_dangerous_paths=True)
# or use a relative path
load_prompt('prompts/prompt.json') Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
p = Path(user_path)
if p.is_absolute():
p = Path.cwd() / p # or reject, depending on trust
load_prompt(str(p)) Type guard
from pathlib import Path
def is_relative_safe(path: str | Path) -> bool:
p = Path(path)
return not p.is_absolute() and '..' not in p.parts Prevention
- 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.
When it happens
Trigger: 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`.
Common situations: 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.
Related errors
- Path '{path}' contains '..' components. Directory traversal
- Loading templates with '{template_format}' format is no long
- jinja2 is unsafe and is not supported for templates expresse
- Loading images from 'path' has been removed as of 0.3.15 for
- Loading {config_type} prompt not supported
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/43ec007da5619692.
Report an issue: GitHub.