{"record":{"id":"baa06c0f87f280e9","repo":"BerriAI/litellm","slug":"failed-to-load-prompt-prompt-id-from-bitbucket","errorCode":null,"errorMessage":"Failed to load prompt '{prompt_id}' from BitBucket: {e}","messagePattern":"Failed to load prompt '(.+?)' from BitBucket: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/bitbucket/bitbucket_prompt_manager.py","lineNumber":108,"sourceCode":"            comment_start_string=\"{#\",\n            comment_end_string=\"#}\",\n        )\n\n        # Load prompts from BitBucket if prompt_id is provided\n        if self.prompt_id:\n            self._load_prompt_from_bitbucket(self.prompt_id)\n\n    def _load_prompt_from_bitbucket(self, prompt_id: str) -> None:\n        \"\"\"Load a specific .prompt file from BitBucket.\"\"\"\n        try:\n            # Fetch the .prompt file from BitBucket\n            prompt_content: Final = self.bitbucket_client.get_file_content(f\"{prompt_id}.prompt\")\n\n            if prompt_content:\n                template: Final = self._parse_prompt_file(prompt_content, prompt_id)\n                self.prompts[prompt_id] = template\n        except Exception as e:\n            raise Exception(f\"Failed to load prompt '{prompt_id}' from BitBucket: {e}\")\n\n    def _parse_prompt_file(self, content: str, prompt_id: str) -> BitBucketPromptTemplate:\n        \"\"\"Parse a .prompt file content and extract metadata and template.\"\"\"\n        # Split frontmatter and content\n        if content.startswith(\"---\"):\n            parts: Final = content.split(\"---\", 2)\n            if len(parts) >= 3:\n                frontmatter_str = parts[1].strip()\n                template_content = parts[2].strip()\n            else:\n                frontmatter_str = \"\"\n                template_content = content\n        else:\n            frontmatter_str = \"\"\n            template_content = content\n\n        # Parse YAML frontmatter\n        metadata: dict[str, Any] = {}","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/bitbucket/bitbucket_prompt_manager.py#L90-L126","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nmanager.async_compile_prompt_helper(\"docs/../my_prompt\", vars, params)\n\n// after\nprompt_id = \"my_prompt\"  # flat id matching <id>.prompt in the repo; no '..' or URL chars\nmanager.async_compile_prompt_helper(prompt_id, vars, params)","handlingStrategy":"validation","validationCode":"def prompt_exists(client: \"BitBucketClient\", prompt_id: str) -> bool:\n    # 404 -> None; 401/403 raise — so also keep credentials valid\n    if any(c in prompt_id for c in (\"#\", \"?\")) or \"..\" in prompt_id.split(\"/\"):\n        return False  # _sanitize_file_path would reject this id\n    return client.get_file_metadata(f\"{prompt_id}.prompt\") is not None","typeGuard":null,"tryCatchPattern":"try:\n    manager._load_prompt_from_bitbucket(prompt_id)  # or go through compile\nexcept Exception as e:\n    raise RuntimeError(f\"failed to load prompt '{prompt_id}': {e}\") from e","preventionTips":["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"],"tags":["bitbucket","prompt-management","litellm-prompts","path-validation"],"backgroundTag":"http-request-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}