invoke-ai/InvokeAI · error · BatchItemsTypeError

All items in a batch must have the same type

Error message

All items in a batch must have the same type

What it means

All items within a single batch datum's item list must share the same Python/Pydantic type, since batch items are substituted into one node field. The BatchItemsTypeError is raised by validate_types when an item's type differs from the first item's type in the list.

Source

Thrown at invokeai/app/services/session_queue/session_queue_common.py:123

    @field_validator("data")
    def validate_types(cls, v: Optional[BatchDataCollection]):
        if v is None:
            return v
        for batch_data_list in v:
            for datum in batch_data_list:
                if not datum.items:
                    continue

                # Special handling for numbers - they can be mixed
                # TODO(psyche): Update BatchDatum to have a `type` field to specify the type of the items, then we can have strict float and int fields
                if all(isinstance(item, (int, float)) for item in datum.items):
                    continue

                # Get the type of the first item in the list
                first_item_type = type(datum.items[0])
                for item in datum.items:
                    if type(item) is not first_item_type:
                        raise BatchItemsTypeError("All items in a batch must have the same type")
        return v

    @field_validator("data")
    def validate_unique_field_mappings(cls, v: Optional[BatchDataCollection]):
        if v is None:
            return v
        paths: set[tuple[str, str]] = set()
        for batch_data_list in v:
            for datum in batch_data_list:
                pair = (datum.node_path, datum.field_name)
                if pair in paths:
                    raise BatchDuplicateNodeFieldError("Each batch data must have unique node_id and field_name")
                paths.add(pair)
        return v

    @model_validator(mode="after")
    def validate_batch_nodes_and_edges(self):
        if self.data is None:

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Normalize all items in each batch data list to one type (e.g. convert everything to str, or all to ImageField)
  2. Split heterogeneous data into separate batch data collections
  3. Add client-side validation that checks isinstance(item, type(items[0])) for all items before submission
  4. Fix JSON payloads where a value was accidentally given as a different JSON type

Example fix

// before: mixed types
items: ["prompt", 42]
// after: homogeneous
items: ["prompt one", "prompt two"]
Defensive patterns

Strategy: validation

Validate before calling

def validate_item_types(batch_data_list):
    for datum in batch_data_list:
        if datum.items:
            first = type(datum.items[0])
            if any(type(i) is not first for i in datum.items):
                raise ValueError(f"Mixed item types in field {datum.field_name}.")

Type guard

def homogeneous(items) -> bool:
    return len({type(i) for i in items}) <= 1

Try / catch

try:
    batch = Batch(**batch_dict)
except BatchItemsTypeError as e:
    logger.error(f"Heterogeneous batch items: {e}")
    # normalize item types and rebuild

Prevention

When it happens

Trigger: Mixing item types within one batch data list, e.g. string prompts alongside ImageField objects, or ints mixed with floats/strings in the same collection, when the Batch model is validated.

Common situations: Programmatically building batch data from heterogeneous inputs without normalizing types; loading batch JSON where one entry was edited to a different type; API clients sending mixed-type arrays.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/86e341126b7a852c. Report an issue: GitHub.