BerriAI/litellm · error · ValueError
Prompt directory does not exist
Error message
Prompt directory does not exist: {self.prompt_directory} What it means
PromptManager._load_prompts, called automatically from __init__ whenever prompt_directory is set, raises ValueError if the directory is falsy or does not exist on disk. The message interpolates the stored path (which prints 'None' if the value was empty). This makes construction itself fail before any prompts are read.
Solutions
- Verify the directory exists (and correct the path) before constructing PromptManager
- Use an absolute path anchored to code location: Path(__file__).parent / 'prompts'
- Create the directory if it may legitimately be empty: Path(dir).mkdir(parents=True, exist_ok=True)
- If you only need one file, use prompt_file + prompt_id so no directory is required
Example fix
# before
manager = PromptManager(prompt_directory='prompts')
# after
from pathlib import Path
PROMPT_DIR = Path(__file__).parent / 'prompts'
assert PROMPT_DIR.is_dir(), f'missing prompt directory: {PROMPT_DIR}'
manager = PromptManager(prompt_directory=str(PROMPT_DIR)) Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
prompt_dir = Path(prompt_directory) if prompt_directory else None
if prompt_directory and not prompt_dir.is_dir():
raise FileNotFoundError(f'prompt directory missing: {prompt_dir}')
manager = PromptManager(prompt_directory=str(prompt_dir) if prompt_dir else None) Try / catch
try:
manager = PromptManager(prompt_directory=str(PROMPT_DIR))
except ValueError as e:
if 'Prompt directory does not exist' in str(e):
logger.error('prompts folder missing at %s — check deployment layout', PROMPT_DIR)
raise Prevention
- Anchor prompt directories to __file__, never to cwd
- Include the prompts directory in the Docker image / package and assert presence at startup
- Add a CI check that the configured prompt directory exists in the built artifact
When it happens
Trigger: PromptManager(prompt_directory='prompts') when the folder does not exist or the process cwd differs (relative paths resolve against cwd at construction time); a path sourced from an env var or config that is wrong; a directory that was deleted between deployments.
Common situations: Running the proxy/service from a different working directory (systemd unit, Docker WORKDIR) so a relative path no longer resolves; CI checkout missing the prompts folder; typo in the configured path; packaging the app without the prompts directory.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Error rendering template
- Invalid type for field
- Invalid YAML frontmatter
- prompt_id is required when prompt_file is provided
- Prompt ' ' not found. Available prompts
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/02a2710ece4c2416.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/dotprompt/prompt_manager.py:96
# Load prompts from directory if provided
if self.prompt_directory:
self._load_prompts()
if self.prompt_file:
if not prompt_id:
raise ValueError("prompt_id is required when prompt_file is provided")
template: Final = self._load_prompt_file(self.prompt_file, prompt_id)
self.prompts[prompt_id] = template
# Load prompts from JSON data if provided
if prompt_data:
self._load_prompts_from_json(prompt_data, prompt_id)
def _load_prompts(self) -> None:
"""Load all .prompt files from the prompt directory."""
if not self.prompt_directory or not self.prompt_directory.exists():
raise ValueError(f"Prompt directory does not exist: {self.prompt_directory}")
prompt_files: Final = list(self.prompt_directory.glob("*.prompt"))
for prompt_file in prompt_files:
try:
prompt_id = prompt_file.stem # filename without extension
template = self._load_prompt_file(prompt_file, prompt_id)
self.prompts[prompt_id] = template
# Optional: print(f"Loaded prompt: {prompt_id}")
except Exception:
# Optional: print(f"Error loading prompt file {prompt_file}")
pass
def _load_prompts_from_json(self, prompt_data: dict[str, dict[str, Any]], prompt_id: str | None = None) -> None:
"""Load prompts from JSON data structure.
Expected format:
{View on GitHub (pinned to 77b7c6c40c)