BerriAI/litellm · error · HTTPException

Prompt {prompt_id} not found in environment {environment}

Error message

Prompt {prompt_id} not found in environment {environment}

What it means

Prompt fetch fallback exhausted: neither the DB query for the prompt in the requested environment nor the in-memory registry lookup (including latest-version resolution) produced a prompt with that prompt_id, so nothing can be returned for the given environment.

Source

Thrown at litellm/proxy/prompts/prompt_endpoints.py:688

            where=where_clause,
            order={"version": "desc"},
            take=1,
        )
        if env_prompts:
            prompt_spec = create_versioned_prompt_spec(db_prompt=env_prompts[0])

    # Fallback: use in-memory registry (no environment filter)
    if prompt_spec is None and environment is None:
        prompt_spec = IN_MEMORY_PROMPT_REGISTRY.get_prompt_by_id(prompt_id)
        if prompt_spec is None:
            latest_prompt_id: Final = get_latest_version_prompt_id(
                prompt_id=prompt_id,
                all_prompt_ids=IN_MEMORY_PROMPT_REGISTRY.IN_MEMORY_PROMPTS,
            )
            prompt_spec = IN_MEMORY_PROMPT_REGISTRY.get_prompt_by_id(latest_prompt_id)

    if prompt_spec is None:
        raise HTTPException(
            status_code=400,
            detail=f"Prompt {prompt_id} not found" + (f" in environment {environment}" if environment else ""),
        )

    # Extract version number from the prompt_id
    version_number: Final = get_version_number(prompt_id=prompt_spec.prompt_id)

    # Create a copy of the prompt spec with the base prompt ID (stripped of version)
    prompt_spec_response: Final = PromptSpec(
        prompt_id=get_base_prompt_id(prompt_id=prompt_spec.prompt_id),
        litellm_params=prompt_spec.litellm_params,
        prompt_info=prompt_spec.prompt_info,
        created_at=prompt_spec.created_at,
        updated_at=prompt_spec.updated_at,
        version=version_number,
        environment=prompt_spec.environment,
        created_by=prompt_spec.created_by,
    )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Check the prompt exists in the requested environment (e.g. production vs staging); promote or create it there.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at litellm/proxy/prompts/prompt_endpoints.py:688 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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