run-llama/llama_index · error · Exception

File type not supported: {file_path}

Error message

File type not supported: {file_path}

What it means

The `llama-index-cli upgrade` command rewrites files that use the old llama_index -> llama_index.core import paths, but upgrade_file() only handles three extensions: .ipynb (upgrade_nb_file), and .py/.md (upgrade_py_md_file). Any other extension raises a generic Exception listing the path.

Source

Thrown at llama-index-core/llama_index/core/command_line/upgrade.py:272

    installed_modules = ["llama-index-core"]  # default installs
    new_lines, new_installs = parse_lines(lines, installed_modules)

    with open(file_path, "w", encoding="utf-8") as f:
        f.write("".join(new_lines))

    if len(new_installs) > 0:
        print("New installs:")
    for install in new_installs:
        print(install.strip().replace("%", ""))


def upgrade_file(file_path: str) -> None:
    if file_path.endswith(".ipynb"):
        upgrade_nb_file(file_path)
    elif file_path.endswith((".py", ".md")):
        upgrade_py_md_file(file_path)
    else:
        raise Exception(f"File type not supported: {file_path}")


def _is_hidden(path: Path) -> bool:
    return any(part.startswith(".") and part not in [".", ".."] for part in path.parts)


def upgrade_dir(input_dir: str) -> None:
    file_refs = list(Path(input_dir).rglob("*.py"))
    file_refs += list(Path(input_dir).rglob("*.ipynb"))
    file_refs += list(Path(input_dir).rglob("*.md"))
    file_refs = [x for x in file_refs if not _is_hidden(x)]
    for file_ref in file_refs:
        if file_ref.is_file():
            upgrade_file(str(file_ref))

View on GitHub (pinned to afd0fef371)

Solutions

  1. Only run the upgrade command on .py, .md, or .ipynb files
  2. Rename or copy the file to a supported extension first (e.g. script.txt -> script.py) if it really contains Python
  3. Use upgrade_dir() on a directory — it rglobs only *.py, *.ipynb and *.md, skipping unsupported files for you

Example fix

// before
$ llama-index-cli upgrade notes.txt
Exception: File type not supported: notes.txt

// after
$ cp notes.txt notes.md && llama-index-cli upgrade notes.md
# or upgrade a whole directory (only .py/.md/.ipynb are touched):
$ llama-index-cli upgrade-dir ./my_project
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
SUPPORTED = {".py", ".md", ".ipynb"}
if Path(file_path).suffix not in SUPPORTED:
    raise ValueError(f"unsupported: {file_path}; expected one of {SUPPORTED}")

Type guard

from pathlib import Path

def is_upgradeable(path: str) -> bool:
    return Path(path).suffix in {".py", ".md", ".ipynb"}

Try / catch

from llama_index.core.command_line.upgrade import upgrade_file
try:
    upgrade_file(path)
except Exception as e:
    if "File type not supported" in str(e):
        print(f"skipping {path}: not a .py/.md/.ipynb file")
    else:
        raise

Prevention

When it happens

Trigger: Running `llama-index-cli upgrade <file>` (or upgrade_file(path) programmatically) on a file whose extension is not .py, .md, or .ipynb — e.g. .pyw, .txt, .rst, .jmd, or a file with no extension.

Common situations: Pointing the migration CLI at a directory entry or scratch file with an unusual extension; passing a Jupyter notebook saved as .json; shell globs that accidentally match non-source files.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/832e27a04753af60. Report an issue: GitHub.