{"record":{"id":"8678fdefe2ca84be","repo":"run-llama/llama_index","slug":"node-must-be-a-textnode-to-get-text","errorCode":null,"errorMessage":"Node must be a TextNode to get text.","messagePattern":"Node must be a TextNode to get text\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/schema.py","lineNumber":1071,"sourceCode":"    @classmethod\n    def class_name(cls) -> str:\n        return \"NodeWithScore\"\n\n    ##### pass through methods to BaseNode #####\n    @property\n    def node_id(self) -> str:\n        return self.node.node_id\n\n    @property\n    def id_(self) -> str:\n        return self.node.id_\n\n    @property\n    def text(self) -> str:\n        if isinstance(self.node, TextNode):\n            return self.node.text\n        else:\n            raise ValueError(\"Node must be a TextNode to get text.\")\n\n    @property\n    def metadata(self) -> Dict[str, Any]:\n        return self.node.metadata\n\n    @property\n    def embedding(self) -> Optional[List[float]]:\n        return self.node.embedding\n\n    def get_text(self) -> str:\n        if isinstance(self.node, TextNode):\n            return self.node.get_text()\n        else:\n            raise ValueError(\"Node must be a TextNode to get text.\")\n\n    def get_content(self, metadata_mode: MetadataMode = MetadataMode.NONE) -> str:\n        return self.node.get_content(metadata_mode=metadata_mode)\n","sourceCodeStart":1053,"sourceCodeEnd":1089,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/schema.py#L1053-L1089","documentation":"NodeWithScore.text proxies to the underlying node but only when it is a TextNode; ImageNode-without-text variants or other BaseNode subclasses make the property raise ValueError. The wrapper deliberately refuses to guess content extraction for non-text nodes.","triggerScenarios":"Accessing .text on a NodeWithScore wrapping an ImageNode (or any non-TextNode), e.g. printing retrieved nodes or feeding them to a text-only response synthesizer.","commonSituations":"Multi-modal retrieval pipelines where image nodes flow through code written for text nodes; custom node classes subclassing BaseNode directly instead of TextNode.","solutions":["Use .get_content() instead — it dispatches on node type and works for all node classes","Type-check isinstance(nws.node, TextNode) before accessing .text","For custom node classes, subclass TextNode so the text API is available"],"exampleFix":"# before\nprint(nws.text)  # ValueError for ImageNode\n\n# after\nprint(nws.get_content())  # type-aware content access","handlingStrategy":"type-guard","validationCode":"from llama_index.core.schema import TextNode\ntext = nws.text if isinstance(nws.node, TextNode) else nws.get_content()","typeGuard":"from llama_index.core.schema import TextNode\ndef wraps_text_node(nws) -> bool:\n    return isinstance(nws.node, TextNode)","tryCatchPattern":null,"preventionTips":["Prefer get_content() over .text for mixed node sets","Filter retrieved nodes by type before text-only formatting","Subclass TextNode for custom nodes that need text APIs"],"tags":["schema","nodes","multimodal","content"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}