{"record":{"id":"6fcaf1909441f514","repo":"run-llama/llama_index","slug":"depth-cannot-be-a-negative-number","errorCode":null,"errorMessage":"Depth cannot be a negative number!","messagePattern":"Depth cannot be a negative number!","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/node_parser/relational/hierarchical.py","lineNumber":64,"sourceCode":"    for node in nodes:\n        if NodeRelationship.CHILD not in node.relationships:\n            continue\n\n        children_ids.extend([r.node_id for r in (node.child_nodes or [])])\n\n    child_nodes = []\n    for candidate_node in all_nodes:\n        if candidate_node.node_id not in children_ids:\n            continue\n        child_nodes.append(candidate_node)\n\n    return child_nodes\n\n\ndef get_deeper_nodes(nodes: List[BaseNode], depth: int = 1) -> List[BaseNode]:\n    \"\"\"Get children of root nodes in given nodes that have given depth.\"\"\"\n    if depth < 0:\n        raise ValueError(\"Depth cannot be a negative number!\")\n    root_nodes = get_root_nodes(nodes)\n    if not root_nodes:\n        raise ValueError(\"There is no root nodes in given nodes!\")\n\n    deeper_nodes = root_nodes\n    for _ in range(depth):\n        deeper_nodes = get_child_nodes(deeper_nodes, nodes)\n\n    return deeper_nodes\n\n\nclass HierarchicalNodeParser(NodeParser):\n    \"\"\"\n    Hierarchical node parser.\n\n    Splits a document into a recursive hierarchy Nodes using a NodeParser.\n\n    NOTE: this will return a hierarchy of nodes in a flat list, where there will be","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/node_parser/relational/hierarchical.py#L46-L82","documentation":"Error \"Depth cannot be a negative number!\" thrown in run-llama/llama_index.","triggerScenarios":"Thrown at llama-index-core/llama_index/core/node_parser/relational/hierarchical.py:64 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a depth >= 0 to HierarchicalNodeParser.from_defaults."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}