{"record":{"id":"e201715628dca581","repo":"run-llama/llama_index","slug":"could-not-format-attribute-attribute-name-with-v","errorCode":null,"errorMessage":"Could not format attribute {attribute_name} with value {template_str} to type {att_type}","messagePattern":"Could not format attribute (.+?) with value (.+?) to type (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/base/llms/types.py","lineNumber":228,"sourceCode":"            # If the attribute is a binary string, we need to coerce to string for formatting,\n            # but then we need to re-encode to bytes after formatting, which is what the code below does.\n            formatted_kwargs = {\n                k: resolve_binary(v, as_base64=True).read().decode()\n                if isinstance(v, bytes)\n                else v\n                for k, v in kwargs.items()\n            }\n            if template_str:\n                formatted_str = format_string(template_str, **formatted_kwargs)\n                if att_type is str:\n                    formatted_attrs[attribute_name] = formatted_str\n                elif att_type is bytes:\n                    formatted_attrs[attribute_name] = formatted_str.encode()\n                else:\n                    try:\n                        formatted_attrs[attribute_name] = att_type(formatted_str)  # type: ignore\n                    except Exception:\n                        raise ValueError(\n                            \"Could not format attribute {attribute_name} with value {template_str} to type {att_type}\"\n                        )\n        return type(self).model_validate(self.model_copy(update=formatted_attrs))\n\n    @staticmethod\n    def mimetype_from_inline_url(url: str) -> filetype.Type | None:\n        if url.startswith(\"data:\"):\n            try:\n                mimetype = url.split(\";base64,\")[0].split(\"data:\")[1]\n                return filetype.get_type(mime=mimetype)\n            except Exception:\n                try:\n                    data = url.split(\";base64,\")[1]\n                    decoded_data = base64.b64decode(data)\n                    return filetype.guess(decoded_data)\n                except Exception:\n                    return None\n        return None","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/base/llms/types.py#L210-L246","documentation":"Raised while formatting a templated media attribute (e.g. in ImageBlock/AudioBlock/VideoBlock.format or partial_format flows) when the formatted string cannot be converted to the field's declared type att_type. Only str and bytes targets are handled directly; other types go through att_type(formatted_str) and any exception triggers this error. Note: the message uses literal braces, so attribute names/types appear uninterpolated in the raised text.","triggerScenarios":"Calling block.partial_format(...) / format(...) on a block whose typed attribute template resolves to a value that its type constructor rejects, e.g. a URL field templated to a string that a stricter validator (like a Pydantic URL type) cannot parse.","commonSituations":"Templating prompt-time media attributes (paths, URLs) whose runtime substitutions produce empty or malformed values; partial_format leaving unresolved {placeholders} that the target type cannot parse.","solutions":["Inspect the block's attributes before formatting and ensure every template placeholder receives a value valid for the target type (e.g. full URL with scheme for URL-typed fields).","Avoid templating non-str fields; resolve the value in your code and assign the final typed value directly instead of relying on format conversion.","If a placeholder may be empty, give it a syntactically valid default (e.g. 'https://placeholder.local/x.png') or remove the attribute."],"exampleFix":"# before\nblock = ImageBlock(url=\"{base}/img.png\")\nblock.partial_format(base=\"\")  # empty base -> invalid URL -> ValueError\n\n# after\nblock = ImageBlock(url=f\"{base}/img.png\" if base else DEFAULT_IMAGE_URL)","handlingStrategy":"try-catch","validationCode":"missing = [k for k in placeholder_names if k not in provided_kwargs]\nif missing:\n    raise ValueError(f\"missing template values: {missing}\")  # fail before formatting","typeGuard":null,"tryCatchPattern":"try:\n    block = block.partial_format(**kwargs)\nexcept ValueError as e:\n    if \"Could not format attribute\" in str(e):\n        # resolve values manually and assign typed attributes directly\n        block.url = HttpUrl(f\"{base}/img.png\")\n    else:\n        raise","preventionTips":["Resolve non-string attribute values in code instead of templating them.","Supply every placeholder before calling format/partial_format."],"tags":["llama-index","formatting","templates","multimodal","blocks"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}