{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/bitbucket/bitbucket_prompt_manager.py#L233-L269","documentation":"ValueError raised by BitBucketPromptManager.get_prompt_template when prompt_manager.get_template(prompt_id) returns None — the same root cause as render_template's 'Template not found' but on the get/render path used when compiling prompts for chat completion. The template was never loaded into the in-memory prompts dict (missing file, empty content, typo, wrong branch/directory).","triggerScenarios":"Calling get_prompt_template (directly or via compile_prompt_helper after a failed silent load) for an id that is not in self.prompts: file absent from the BitBucket directory on the configured branch, empty file content skipped at load, case/typo mismatch, or load happening before the file was committed.","commonSituations":"Prompt ids passed in request params ('prompt_id') that don't match repo filenames; prompts merged to a feature branch while the client watches 'main'; trailing whitespace in ids; teams expecting hot-reload when the manager only loads at init.","solutions":["Verify the id against the loaded set: prompt_manager.get_template(prompt_id) should be non-None before calling get_prompt_template","Confirm <prompt_id>.prompt exists in the configured directory on the configured branch in BitBucket","Restart/reinitialize the prompt manager after adding new prompt files — loading is not hot-reloaded","Fix case mismatches and stray whitespace in the prompt_id"],"exampleFix":"// before\nrendered, meta = manager.get_prompt_template(\"code-review\", vars)\n\n// after\ntmpl = manager.prompt_manager.get_template(\"code-review\")\nif tmpl is None:\n    raise ValueError(f\"'code-review' not loaded; have {manager.prompt_manager.list_templates()}\")\nrendered, meta = manager.get_prompt_template(\"code-review\", vars)","handlingStrategy":"type-guard","validationCode":"if manager.prompt_manager.get_template(prompt_id) is None:\n    raise ValueError(f\"prompt '{prompt_id}' not loaded; have {manager.prompt_manager.list_templates()}\")","typeGuard":"from litellm.integrations.bitbucket import BitBucketPromptManagementClient\n\ndef prompt_template_ready(client: BitBucketPromptManagementClient, prompt_id: str) -> bool:\n    return client.prompt_manager.get_template(prompt_id) is not None","tryCatchPattern":"try:\n    rendered, meta = manager.get_prompt_template(prompt_id, variables)\nexcept ValueError as e:\n    if \"not found\" in str(e):\n        manager.prompt_manager._load_prompt_from_bitbucket(prompt_id)  # retry load once\n        rendered, meta = manager.get_prompt_template(prompt_id, variables)\n    else:\n        raise","preventionTips":["get_template() returns Optional — always None-check before get_prompt_template","Validate prompt ids against the repo contents in CI","Restart the prompt manager (or reload) after prompt files change; loading is not hot-reloaded"],"tags":["bitbucket","prompt-management","resource-not-found","template-render"],"backgroundTag":"resource-not-found","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}