invoke-ai/InvokeAI · error · ValueError

Blend is not supported here - you need to get tokens for eac

Error message

Blend is not supported here - you need to get tokens for each of its .children

What it means

get_tokens_for_prompt_object computes the token list of a parsed prompt, but it only handles FlattenedPrompt fragments — not Blend prompt objects. It fails fast with ValueError because blending semantics require handling each child prompt individually.

Source

Thrown at invokeai/app/invocations/compel.py:429

    tokenizer: CLIPTokenizer,
    prompt: Union[FlattenedPrompt, Blend, Conjunction],
    truncate_if_too_long: bool = False,
) -> int:
    if type(prompt) is Blend:
        blend: Blend = prompt
        return max([get_max_token_count(tokenizer, p, truncate_if_too_long) for p in blend.prompts])
    elif type(prompt) is Conjunction:
        conjunction: Conjunction = prompt
        return sum([get_max_token_count(tokenizer, p, truncate_if_too_long) for p in conjunction.prompts])
    else:
        return len(get_tokens_for_prompt_object(tokenizer, prompt, truncate_if_too_long))


def get_tokens_for_prompt_object(
    tokenizer: CLIPTokenizer, parsed_prompt: FlattenedPrompt, truncate_if_too_long: bool = True
) -> List[str]:
    if type(parsed_prompt) is Blend:
        raise ValueError("Blend is not supported here - you need to get tokens for each of its .children")

    text_fragments = [
        (
            x.text
            if type(x) is Fragment
            else (" ".join([f.text for f in x.original]) if type(x) is CrossAttentionControlSubstitute else str(x))
        )
        for x in parsed_prompt.children
    ]
    text = " ".join(text_fragments)
    tokens: List[str] = tokenizer.tokenize(text)
    if truncate_if_too_long:
        max_tokens_length = tokenizer.model_max_length - 2  # typically 75
        tokens = tokens[0:max_tokens_length]
    return tokens


def log_tokenization_for_conjunction(

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Split the Blend and call get_tokens_for_prompt_object on each of its .children separately, then sum/measure per child.
  2. Avoid blend syntax in prompts passed to this helper.
  3. Use a token-counting path that supports Blends if one exists in the compel/prompt parser.

Example fix

# before
count = get_max_token_count(tokenizer, blend_prompt)
# after
child_counts = [get_max_token_count(tokenizer, child) for child in blend_prompt.children]
count = max(child_counts)
Defensive patterns

Strategy: type-guard

Validate before calling

if isinstance(parsed_prompt, Blend):
    token_counts = [get_max_token_count(tokenizer, c) for c in parsed_prompt.children]
else:
    token_counts = [get_max_token_count(tokenizer, parsed_prompt)]

Type guard

from compel.prompt_parser import Blend, FlattenedPrompt
def is_blend(p) -> bool:
    return isinstance(p, Blend)

Try / catch

try:
    count = get_max_token_count(tokenizer, parsed)
except ValueError as e:
    if "Blend" in str(e):
        count = max(get_max_token_count(tokenizer, c) for c in parsed.children)
    else:
        raise

Prevention

When it happens

Trigger: Calling get_max_token_count (or get_tokens_for_prompt_object directly) with a parsed prompt that is a Blend — e.g. prompts using blending syntax ('a AND b' style conditions) passed to token-count estimation code.

Common situations: Prompt-validation/max-token-count utilities encountering conditional/blended prompts during UI token counting; scripting token estimation over arbitrary user prompts that include blend operators.

Related errors


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