BerriAI/litellm · error · KeyError

Prompt ' ' not found. Available prompts

Error message

Prompt '{prompt_id}'{version_str} not found. Available prompts: {available_prompts}

What it means

PromptManager.render looks up the template with get_prompt(prompt_id, version); when no template is registered under that id (or that exact version), it raises KeyError including the id, the requested version, and the list of ids actually loaded. This is the manager's explicit not-found signal instead of a silent empty render. Note the directory loader swallows per-file errors, so a prompt whose file failed to parse simply never registers and shows up only through this error.

Solutions

  1. Inspect the error's 'Available prompts' list — it tells you exactly what registered and what the real id is
  2. If the list is empty or missing the prompt, fix loading first (directory exists, frontmatter valid, id key matches)
  3. Pass version=None to use the base template, or verify the specific version exists before requesting it
  4. Pre-check with manager.get_prompt(prompt_id=..., version=...) is not None before render

Example fix

# before
text = manager.render('summarize', {'topic': 'litellm'})

# after
if manager.get_prompt(prompt_id='summarize') is None:
    raise ValueError(
        f"prompt 'summarize' not loaded; loaded ids: {list(manager.prompts.keys())}"
    )
text = manager.render('summarize', {'topic': 'litellm'})
Defensive patterns

Strategy: validation

Validate before calling

if manager.get_prompt(prompt_id=prompt_id, version=version) is None:
    raise ValueError(
        f"prompt {prompt_id!r} (version={version}) not loaded; "
        f"available: {sorted(manager.prompts.keys())}"
    )
text = manager.render(prompt_id, variables, version=version)

Type guard

def prompt_is_available(manager, prompt_id: str, version: int | None = None) -> bool:
    return manager.get_prompt(prompt_id=prompt_id, version=version) is not None

Try / catch

try:
    text = manager.render(prompt_id, variables)
except KeyError as e:
    raise ValueError(f'unknown prompt requested: {prompt_id}') from e

Prevention

When it happens

Trigger: render('summarize') before any load call registered that id; render('summarize', version=3) when only the base template or versions {1,2} exist; a typo or case mismatch in the id; the .prompt file existed but failed frontmatter parsing during directory load (silently skipped); prompt_data key not matching the render id.

Common situations: Renaming a .prompt file without updating call sites; requesting a pinned version after regenerating prompts without version history; environments where the prompts directory path differed so nothing loaded (then Available prompts: []); assuming prompt_file loading keyed by filename stem when a custom id was passed.

Related errors


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

Appendix: source

Thrown at litellm/integrations/dotprompt/prompt_manager.py:210

        Args:
            prompt_id: The ID of the prompt template to render
            prompt_variables: Variables to substitute in the template
            version: Optional version number. If provided, looks for {prompt_id}.v{version}

        Returns:
            The rendered prompt string

        Raises:
            KeyError: If prompt_id is not found
            ValueError: If template rendering fails
        """
        # Get the template (versioned or base)
        template: Final = self.get_prompt(prompt_id=prompt_id, version=version)

        if template is None:
            available_prompts: Final = list(self.prompts.keys())
            version_str: Final = f" (version {version})" if version else ""
            raise KeyError(f"Prompt '{prompt_id}'{version_str} not found. Available prompts: {available_prompts}")

        variables: Final = prompt_variables or {}

        # Validate input variables against schema if defined
        if template.input_schema:
            self._validate_input(variables, template.input_schema)

        try:
            # Create Jinja2 template and render
            jinja_template: Final = self.jinja_env.from_string(template.content)
            rendered: Final = jinja_template.render(**variables)
            return rendered
        except Exception as e:
            raise ValueError(f"Error rendering template '{prompt_id}': {e}")

    def _validate_input(self, variables: dict[str, Any], schema: dict[str, Any]) -> None:
        """Basic validation of input variables against schema."""
        for field_name, field_type in schema.items():

View on GitHub (pinned to 77b7c6c40c)