BerriAI/litellm · error · Exception
Failed to load prompt
Error message
Failed to load prompt '{prompt_id}' from BitBucket: {e} What it means
Raised by BitBucketPromptManager._load_prompt_from_bitbucket when fetching or parsing a '{prompt_id}.prompt' file fails. Important nuance: a 404 from get_file_content returns None, which is silently skipped (falsy check), so this error indicates an actual failure — 401/403 from BitBucket, other HTTP errors, network exceptions, or a ValueError from _sanitize_file_path when the prompt_id contains '#', '?', or '..' traversal segments.
Solutions
- Check the prompt_id for '#', '?', and '..' segments — sanitize_file_path rejects these before any HTTP call
- Reproduce the fetch manually: curl -H "Authorization: Bearer $TOKEN" "https://api.bitbucket.org/2.0/repositories/<ws>/<repo>/src/main/<prompt_id>.prompt"
- Verify token validity and repository read permissions if the wrapped cause mentions authentication or access
- Warm prompts at startup (load_all_prompts) so failures surface during deployment rather than at request time
Example fix
// before
manager.async_compile_prompt_helper("docs/../my_prompt", vars, params)
// after
prompt_id = "my_prompt" # flat id matching <id>.prompt in the repo; no '..' or URL chars
manager.async_compile_prompt_helper(prompt_id, vars, params) Defensive patterns
Strategy: validation
Validate before calling
def prompt_exists(client: "BitBucketClient", prompt_id: str) -> bool:
# 404 -> None; 401/403 raise — so also keep credentials valid
if any(c in prompt_id for c in ("#", "?")) or ".." in prompt_id.split("/"):
return False # _sanitize_file_path would reject this id
return client.get_file_metadata(f"{prompt_id}.prompt") is not None Try / catch
try:
manager._load_prompt_from_bitbucket(prompt_id) # or go through compile
except Exception as e:
raise RuntimeError(f"failed to load prompt '{prompt_id}': {e}") from e Prevention
- Use flat prompt ids without '#', '?', or '..' segments
- Keep the BitBucket token fresh and scoped to the prompts repo
- Warm-load all prompts at startup so failures appear during deploy, not at request time
When it happens
Trigger: Compiling a prompt whose id contains URL-special characters or '..' (ValueError from path sanitization); loading a prompt while the access token is expired (401 wrapped as generic Exception), the token lacks repo read scope (403), or the network to BitBucket is down. Raised lazily from async_compile_prompt_helper when the prompt was not preloaded.
Common situations: prompt_id values derived from filenames containing '#', '?', or subdirectory paths with '..'; token expiry between proxy start and first prompt use; workspace permission changes after token issuance.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- bitbucket_config is required for BitBucket prompt…
- BitBucket configuration not found. Please set…
- Error compiling prompt
- Error listing files in
- prompt_id is required for BitBucket prompt manager
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/baa06c0f87f280e9.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/bitbucket/bitbucket_prompt_manager.py:108
comment_start_string="{#",
comment_end_string="#}",
)
# Load prompts from BitBucket if prompt_id is provided
if self.prompt_id:
self._load_prompt_from_bitbucket(self.prompt_id)
def _load_prompt_from_bitbucket(self, prompt_id: str) -> None:
"""Load a specific .prompt file from BitBucket."""
try:
# Fetch the .prompt file from BitBucket
prompt_content: Final = self.bitbucket_client.get_file_content(f"{prompt_id}.prompt")
if prompt_content:
template: Final = self._parse_prompt_file(prompt_content, prompt_id)
self.prompts[prompt_id] = template
except Exception as e:
raise Exception(f"Failed to load prompt '{prompt_id}' from BitBucket: {e}")
def _parse_prompt_file(self, content: str, prompt_id: str) -> BitBucketPromptTemplate:
"""Parse a .prompt file content and extract metadata and template."""
# Split frontmatter and content
if content.startswith("---"):
parts: Final = content.split("---", 2)
if len(parts) >= 3:
frontmatter_str = parts[1].strip()
template_content = parts[2].strip()
else:
frontmatter_str = ""
template_content = content
else:
frontmatter_str = ""
template_content = content
# Parse YAML frontmatter
metadata: dict[str, Any] = {}View on GitHub (pinned to 77b7c6c40c)