{"record":{"id":"1f7008321784ad33","repo":"invoke-ai/InvokeAI","slug":"blend-is-not-supported-here-you-need-to-get-toke","errorCode":null,"errorMessage":"Blend is not supported here - you need to get tokens for each of its .children","messagePattern":"Blend is not supported here - you need to get tokens for each of its \\.children","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/compel.py","lineNumber":429,"sourceCode":"    tokenizer: CLIPTokenizer,\n    prompt: Union[FlattenedPrompt, Blend, Conjunction],\n    truncate_if_too_long: bool = False,\n) -> int:\n    if type(prompt) is Blend:\n        blend: Blend = prompt\n        return max([get_max_token_count(tokenizer, p, truncate_if_too_long) for p in blend.prompts])\n    elif type(prompt) is Conjunction:\n        conjunction: Conjunction = prompt\n        return sum([get_max_token_count(tokenizer, p, truncate_if_too_long) for p in conjunction.prompts])\n    else:\n        return len(get_tokens_for_prompt_object(tokenizer, prompt, truncate_if_too_long))\n\n\ndef get_tokens_for_prompt_object(\n    tokenizer: CLIPTokenizer, parsed_prompt: FlattenedPrompt, truncate_if_too_long: bool = True\n) -> List[str]:\n    if type(parsed_prompt) is Blend:\n        raise ValueError(\"Blend is not supported here - you need to get tokens for each of its .children\")\n\n    text_fragments = [\n        (\n            x.text\n            if type(x) is Fragment\n            else (\" \".join([f.text for f in x.original]) if type(x) is CrossAttentionControlSubstitute else str(x))\n        )\n        for x in parsed_prompt.children\n    ]\n    text = \" \".join(text_fragments)\n    tokens: List[str] = tokenizer.tokenize(text)\n    if truncate_if_too_long:\n        max_tokens_length = tokenizer.model_max_length - 2  # typically 75\n        tokens = tokens[0:max_tokens_length]\n    return tokens\n\n\ndef log_tokenization_for_conjunction(","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/compel.py#L411-L447","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Split the Blend and call get_tokens_for_prompt_object on each of its .children separately, then sum/measure per child.","Avoid blend syntax in prompts passed to this helper.","Use a token-counting path that supports Blends if one exists in the compel/prompt parser."],"exampleFix":"# before\ncount = get_max_token_count(tokenizer, blend_prompt)\n# after\nchild_counts = [get_max_token_count(tokenizer, child) for child in blend_prompt.children]\ncount = max(child_counts)","handlingStrategy":"type-guard","validationCode":"if isinstance(parsed_prompt, Blend):\n    token_counts = [get_max_token_count(tokenizer, c) for c in parsed_prompt.children]\nelse:\n    token_counts = [get_max_token_count(tokenizer, parsed_prompt)]","typeGuard":"from compel.prompt_parser import Blend, FlattenedPrompt\ndef is_blend(p) -> bool:\n    return isinstance(p, Blend)","tryCatchPattern":"try:\n    count = get_max_token_count(tokenizer, parsed)\nexcept ValueError as e:\n    if \"Blend\" in str(e):\n        count = max(get_max_token_count(tokenizer, c) for c in parsed.children)\n    else:\n        raise","preventionTips":["Check prompt type before token-count helpers","Handle Blend children recursively in utilities","Test token estimation with blended prompts"],"tags":["prompt","tokenizer","compel","unsupported-operation"],"backgroundTag":"unsupported-input-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}