{"record":{"id":"2458037e9ea3f008","repo":"BerriAI/litellm","slug":"prompt-template-prompt-id-not-found-245803","errorCode":null,"errorMessage":"Prompt template '{prompt_id}' not found","messagePattern":"Prompt template '(.+?)' not found","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/bitbucket/bitbucket_prompt_manager.py","lineNumber":251,"sourceCode":"\n    def get_prompt_template(\n        self,\n        prompt_id: str,\n        prompt_variables: dict[str, Any] | None = None,\n    ) -> tuple[str, dict[str, Any]]:\n        \"\"\"\n        Get a prompt template and render it with variables.\n\n        Args:\n            prompt_id: The ID of the prompt template\n            prompt_variables: Variables to substitute in the template\n\n        Returns:\n            Tuple of (rendered_prompt, metadata)\n        \"\"\"\n        template: Final = self.prompt_manager.get_template(prompt_id)\n        if not template:\n            raise ValueError(f\"Prompt template '{prompt_id}' not found\")\n\n        # Render the template\n        rendered_prompt: Final = self.prompt_manager.render_template(prompt_id, prompt_variables or {})\n\n        # Extract metadata\n        metadata: Final = {\n            \"model\": template.model,\n            \"temperature\": template.temperature,\n            \"max_tokens\": template.max_tokens,\n            **template.optional_params,\n        }\n\n        return rendered_prompt, metadata\n\n    def pre_call_hook(\n        self,\n        user_id: str | None,\n        messages: list[AllMessageValues],","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/bitbucket/bitbucket_prompt_manager.py#L233-L269","documentation":"ValueError from BitBucketPromptManagementClient.get_prompt_template when prompt_manager.get_template(prompt_id) returns None — i.e. the template is not in the loaded prompts dict. This is the typed-guard style of error 348: a deliberate fail-fast because the manager cannot render a template it never loaded. The subsequent render_template call would raise anyway; this check gives a clearer message.","triggerScenarios":"Passing a prompt_id to the LiteLLM prompt-management flow that was never loaded: wrong file name, new prompt file added post-startup, load skipped because initialization only scans certain directories, or id casing mismatch.","commonSituations":"Using litellm completion with a BitBucket-backed prompt id that does not correspond to a .prompt file; deploying a new prompt without restarting/reloading the proxy.","solutions":["Use prompt_manager.list_templates() to confirm the id exists before the call","Load on demand: if prompt_id not in prompt_manager.prompts: prompt_manager._load_prompt_from_bitbucket(prompt_id)","Match the id exactly to the .prompt file name (case-sensitive)","Trigger a prompt reload/restart after adding prompt files to the repository"],"exampleFix":"# before\nrendered, metadata = client.get_prompt_template(\"summary\", {\"topic\": \"x\"})\n\n# after\nif client.prompt_manager.get_template(\"summary\") is None:\n    client.prompt_manager._load_prompt_from_bitbucket(\"summary\")\nrendered, metadata = client.get_prompt_template(\"summary\", {\"topic\": \"x\"})","handlingStrategy":"type-guard","validationCode":"if client.prompt_manager.get_template(prompt_id) is None:\n    try:\n        client.prompt_manager._load_prompt_from_bitbucket(prompt_id)\n    except Exception:\n        pass\nif client.prompt_manager.get_template(prompt_id) is None:\n    raise KeyError(f\"Unknown prompt '{prompt_id}'; available: {client.prompt_manager.list_templates()}\")","typeGuard":"def has_prompt_template(client, prompt_id: str) -> bool:\n    \"\"\"Narrow: True only when the template object is loaded.\"\"\"\n    return client.prompt_manager.get_template(prompt_id) is not None","tryCatchPattern":"try:\n    rendered, metadata = client.get_prompt_template(prompt_id, variables)\nexcept ValueError as e:\n    if \"not found\" in str(e):\n        raise KeyError(f\"prompt '{prompt_id}' missing; loaded={client.prompt_manager.list_templates()}\") from e\n    raise","preventionTips":["Guard with get_template() before calling get_prompt_template","Include list_templates() output in error logs for fast diagnosis","Reload prompts after repository changes"],"tags":["bitbucket","prompts","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}