mlflow/mlflow · error · ValueError

Invalid type: {item['type']}.

Error message

Invalid type: {item['type']}.

What it means

check_content dispatches each dict content item by its 'type' value; only input_text (validated as ResponseInputTextParam), input_image, and input_file are accepted. Any other 'type' string raises this ValueError. OpenAI Responses-API part types like output_text or input_audio are not accepted for user input content in MLflow's schema.

Source

Thrown at mlflow/types/responses_helpers.py:359

    role: str
    status: str | None = None
    type: str = "message"

    @model_validator(mode="after")
    def check_content(self) -> "Message":
        if self.content is None:
            raise ValueError("content must not be None")
        if isinstance(self.content, list):
            for item in self.content:
                if isinstance(item, dict):
                    if "type" not in item:
                        raise ValueError(
                            "dictionary type content field values must have key 'type'"
                        )
                    if item["type"] == "input_text":
                        ResponseInputTextParam(**item)
                    elif item["type"] not in {"input_image", "input_file"}:
                        raise ValueError(f"Invalid type: {item['type']}.")
        return self

    @model_validator(mode="after")
    def check_role(self) -> "Message":
        if self.role not in {"user", "assistant", "system", "developer"}:
            raise ValueError(
                f"Invalid role: {self.role}. Must be 'user', 'assistant', 'system', or 'developer'."
            )
        return self


class FunctionCallOutput(Status):
    call_id: str
    output: str | list[dict[str, Any]]
    type: str = "function_call_output"


class BaseRequestPayload(Truncation, ToolChoice):

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Rename the type to one of: input_text, input_image, input_file
  2. For text parts include the 'text' key too, since input_text items are validated as ResponseInputTextParam(text=..., type='input_text')
  3. Map Chat Completions parts to Responses equivalents before constructing the Message ('text' -> 'input_text', 'image_url' -> 'input_image')

Example fix

// before
Message(role="user", content=[{"type": "text", "text": "hello"}])
// after
Message(role="user", content=[{"type": "input_text", "text": "hello"}])
Defensive patterns

Strategy: validation

Validate before calling

ALLOWED = {"input_text", "input_image", "input_file"}
def validate_types(content):
    for item in content if isinstance(content, list) else []:
        if isinstance(item, dict) and item.get("type") not in ALLOWED:
            raise ValueError(f"unsupported content type: {item.get('type')}")
    return True

Type guard

def is_valid_part(item: dict) -> bool:
    return item.get("type") in {"input_text", "input_image", "input_file"}

Try / catch

try:
    msg = Message(role=role, content=content)
except ValueError as e:
    if str(e).startswith("Invalid type:"):
        bad = str(e).split("Invalid type: ")[1].rstrip(".")
        raise TypeError(f"Replace content part type {bad!r} with input_text/input_image/input_file") from e
    raise

Prevention

When it happens

Trigger: Message(content=[{'type': 'output_text', ...}]) or any dict item whose 'type' is not one of input_text/input_image/input_file, e.g. {'type': 'text', 'text': 'hi'} (Chat Completions style).

Common situations: Reusing Chat Completions content part types ('text', 'image_url') instead of Responses API types; passing model output parts back as input; typos like 'input_Text'.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29). Data as JSON: /api/errors/cc6c6afa84412147. Report an issue: GitHub.