run-llama/llama_index · error · ValueError

Unsupported pydantic program mode: {pydantic_program_mode}

Error message

Unsupported pydantic program mode: {pydantic_program_mode}

What it means

get_program_for_pydantic_model dispatches on the PydanticProgramMode enum. Any value not handled by the if/elif chain (i.e. not the default or LM_FORMAT_ENFORCER modes) reaches the else branch and raises this ValueError. This typically means an unknown enum value, a stale enum member removed from the dispatch, or a custom mode passed as a string.

Source

Thrown at llama-index-core/llama_index/core/program/utils.py:135

    elif pydantic_program_mode == PydanticProgramMode.LM_FORMAT_ENFORCER:
        try:
            from llama_index.program.lmformatenforcer import (
                LMFormatEnforcerPydanticProgram,
            )  # pants: no-infer-dep
        except ImportError:
            raise ImportError(
                "This mode requires the `llama-index-program-lmformatenforcer package. Please"
                " install it by running `pip install llama-index-program-lmformatenforcer`."
            )

        return LMFormatEnforcerPydanticProgram.from_defaults(
            output_cls=output_cls,
            llm=llm,
            prompt=prompt,
            **kwargs,
        )
    else:
        raise ValueError(f"Unsupported pydantic program mode: {pydantic_program_mode}")


def _repair_incomplete_json(json_str: str) -> str:
    """
    Attempt to repair incomplete JSON strings.

    Args:
        json_str (str): Potentially incomplete JSON string

    Returns:
        str: Repaired JSON string

    """
    if not json_str.strip():
        return "{}"

    # Add missing quotes
    quote_count = json_str.count('"')

View on GitHub (pinned to afd0fef371)

Solutions

  1. Use a supported PydanticProgramMode member: default (omit) or LM_FORMAT_ENFORCER.
  2. Align llama-index-* package versions so the enum and dispatch agree (pip install -U llama-index-core or the meta-package).
  3. If you need a custom program, construct LLMTextCompletionProgram directly instead of via this helper.

Example fix

# before
program = get_program_for_pydantic_model(
    output_cls, pydantic_program_mode='function_call'  # unsupported
)
# after
from llama_index.core.program import PydanticProgramMode
program = get_program_for_pydantic_model(
    output_cls, pydantic_program_mode=PydanticProgramMode.LM_FORMAT_ENFORCER
)
# or omit pydantic_program_mode for the default
Defensive patterns

Strategy: validation

Validate before calling

from llama_index.core.program import PydanticProgramMode
SUPPORTED = {PydanticProgramMode.DEFAULT, PydanticProgramMode.LM_FORMAT_ENFORCER}
if pydantic_program_mode not in SUPPORTED:
    raise ValueError(f"unsupported mode: {pydantic_program_mode}")

Type guard

from llama_index.core.program import PydanticProgramMode

def is_supported_mode(mode) -> bool:
    return mode in (PydanticProgramMode.DEFAULT,
                    PydanticProgramMode.LM_FORMAT_ENFORCER)

Prevention

When it happens

Trigger: Passing an unrecognized pydantic_program_mode, e.g. a new/removed enum member or a raw string like 'custom'; version skew where the caller's enum has members this llama-index-core version does not handle.

Common situations: Mixing llama-index package versions after a partial upgrade; passing a mode constant imported from a different integration; typos in string literals used as modes.

Related errors


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