BerriAI/litellm · error · ValueError

Template ' ' not found

Error message

Template '{template_id}' not found

What it means

ValueError raised by BitBucketPromptManager.render_template when the requested template_id is not a key in the in-memory self.prompts dict. That dict is populated by listing the configured directory at init and downloading each .prompt file; because a 404 or empty file content is silently skipped during load, a file that 'should exist' can still be absent from the cache at render time.

Solutions

  1. List what actually loaded: print(manager.list_templates()) and compare against the id you passed
  2. Confirm the file exists on the configured branch: check <workspace>/<repo>/src/<branch>/<dir>/<id>.prompt in BitBucket UI
  3. Fix typos and case — ids are exact-match keys
  4. If the file is empty, add content; empty files are silently skipped at load time

Example fix

// before
out = manager.render_template("summarize-v2", {"text": t})

// after
if "summarize-v2" not in manager.list_templates():
    raise KeyError(f"prompt not loaded; available: {manager.list_templates()}")
out = manager.render_template("summarize-v2", {"text": t})
Defensive patterns

Strategy: validation

Validate before calling

available = set(manager.list_templates())
if template_id not in available:
    raise KeyError(f"template '{template_id}' not loaded; available: {sorted(available)}")
out = manager.render_template(template_id, variables)

Type guard

def can_render(manager, template_id: str) -> bool:
    return template_id in manager.prompts

Try / catch

try:
    out = manager.render_template(template_id, variables)
except ValueError as e:
    if "not found" in str(e):
        ...  # reload templates / fix id
    raise

Prevention

When it happens

Trigger: Calling render_template with a typo'd or case-mismatched id; the .prompt file not existing in the configured BitBucket directory (load-time 404 was swallowed); the file existing but being empty ('' is falsy so it is never cached); rendering before the file was pushed to the repo; wrong prompts directory configured so nothing was loaded.

Common situations: Case-sensitivity mistakes ('Summarize' vs 'summarize'); prompts pushed to a different branch than the configured 'branch' (default 'main'); CI deploying the proxy before the prompts repo is updated; directory config pointing at a folder that has no .prompt files.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/1bf680fbec2a2b27. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/bitbucket/bitbucket_prompt_manager.py:168

                key, value = line.split(":", 1)
                key = key.strip()
                value = value.strip()

                # Try to parse value as appropriate type
                if value.lower() in ["true", "false"]:
                    result[key] = value.lower() == "true"
                elif value.isdigit():
                    result[key] = int(value)
                elif value.replace(".", "").isdigit():
                    result[key] = float(value)
                else:
                    result[key] = value.strip("\"'")
        return result

    def render_template(self, template_id: str, variables: dict[str, Any] | None = None) -> str:
        """Render a template with the given variables."""
        if template_id not in self.prompts:
            raise ValueError(f"Template '{template_id}' not found")

        template: Final = self.prompts[template_id]
        jinja_template: Final = self.jinja_env.from_string(template.content)

        return jinja_template.render(**(variables or {}))

    def get_template(self, template_id: str) -> BitBucketPromptTemplate | None:
        """Get a template by ID."""
        return self.prompts.get(template_id)

    def list_templates(self) -> list[str]:
        """List all available template IDs."""
        return list(self.prompts.keys())


class BitBucketPromptManager(CustomPromptManagement):
    """
    BitBucket prompt manager that integrates with LiteLLM's prompt management system.

View on GitHub (pinned to 77b7c6c40c)