BerriAI/litellm · error · HTTPException

File must have .prompt extension

Error message

File must have .prompt extension

What it means

Upload validation on the .prompt file conversion endpoint: the uploaded file's name does not end with the '.prompt' extension, so it is not recognized as a dotprompt file and conversion is refused with 400 before the file is parsed.

Source

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

)
async def convert_prompt_file_to_json(
    file: UploadFile = File(...),
    user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
) -> dict[str, Any]:
    """
    Convert a .prompt file to JSON format.

    This endpoint accepts a .prompt file upload and returns the equivalent JSON representation
    that can be stored in a database or used programmatically.

    Returns the JSON structure with 'content' and 'metadata' fields.
    """
    global general_settings
    from litellm.integrations.dotprompt.prompt_manager import PromptManager

    # Validate file extension
    if not file.filename or not file.filename.endswith(".prompt"):
        raise HTTPException(status_code=400, detail="File must have .prompt extension")

    temp_file_path = None
    try:
        # Read file content
        file_content: Final = await file.read()

        # Create temporary file — use safe_filename to prevent path traversal
        temp_file_path = Path(tempfile.mkdtemp()) / safe_filename(file.filename)
        temp_file_path.write_bytes(file_content)

        # Create a PromptManager instance just for conversion
        prompt_manager: Final = PromptManager()

        # Convert to JSON
        json_data: Final = prompt_manager.prompt_file_to_json(temp_file_path)

        # Extract prompt ID from filename
        prompt_id: Final = temp_file_path.stem

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Upload a file with the .prompt extension; rename the file if necessary.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/prompts/prompt_endpoints.py:1334 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/9bcbab5fa2aaf2da. Report an issue: GitHub.