{"record":{"id":"eba7a7802f3ca974","repo":"zylon-ai/private-gpt","slug":"artifact-exceeds-the-self-max-content-nodes-node","errorCode":null,"errorMessage":"Artifact exceeds the {self.max_content_nodes} node limit","messagePattern":"Artifact exceeds the (.+?) node limit","errorType":"error_code","errorClass":"ContentRequestLimitError","httpStatus":413,"severity":"error","filePath":"private_gpt/server/content/content_service.py","lineNumber":184,"sourceCode":"        return cast(TreeNode, root_nodes[0]) if root_nodes else None\n\n    def _filter_tree_nodes(\n        self,\n        root: TreeNode,\n        include: list[type[NodeType]] | None = None,\n        exclude: list[type[NodeType]] | None = None,\n        node_ids: list[str] | None = None,\n        include_children: bool = True,\n        include_ancestors: bool = False,\n    ) -> Generator[str, None, None]:\n        \"\"\"Flatten tree and apply type filters.\"\"\"\n        all_nodes: list[TreeNode] = []\n        stack = [root]\n        while stack:\n            node = stack.pop()\n            all_nodes.append(node)\n            if len(all_nodes) > self.max_content_nodes:\n                raise ContentRequestLimitError(\n                    f\"Artifact exceeds the {self.max_content_nodes} node limit\"\n                )\n            stack.extend(reversed(node.children))\n        node_map = {node.id_: node for node in all_nodes}\n\n        nodes_to_include: set[str] | None = None\n\n        if node_ids:\n            node_ids_set = set(node_ids)\n            nodes_to_include = set()\n\n            for node_id in node_ids_set:\n                if node_id in node_map:\n                    node = node_map[node_id]\n                    nodes_to_include.add(node_id)\n\n                    if include_children:\n                        descendants = list(reversed(node.children))","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/server/content/content_service.py#L166-L202","documentation":"ContentRequestLimitError raised while flattening a document tree: the iterative stack walk has collected more than max_content_nodes nodes. This is a hard safety cap (self.max_content_nodes) preventing unbounded memory use on huge artifacts, checked incrementally as nodes are appended.","triggerScenarios":"Calling the tree-flattening path (get content / context building) with an artifact whose total node count exceeds the configured max_content_nodes.","commonSituations":"Very large ingested documents (whole-book splits, deep HTML trees); defaults tuned for small docs; sudden increase in document granularity (per-paragraph nodes) pushing counts over the cap.","solutions":["Raise the max_content_nodes setting if the deployment legitimately handles larger artifacts.","Use context_filter.artifacts / node_ids / include-exclude filters so only the needed subtree is flattened.","Re-ingest the source with coarser chunking to reduce node count."],"exampleFix":"# before\nnodes = list(service._flatten_tree(root))  # 200k-node artifact, cap 100k\n\n# after\nnodes = list(service._flatten_tree(root, node_ids=['sec-3'], include_children=True))  # targeted subtree","handlingStrategy":"validation","validationCode":"total = count_nodes(root)\nif total > service.max_content_nodes:\n    raise ValueError(f'artifact too large ({total} nodes); filter it first')","typeGuard":null,"tryCatchPattern":"try:\n    nodes = list(flatten_tree(root, node_ids=target_ids))\nexcept ContentRequestLimitError:\n    nodes = list(flatten_tree(root, node_ids=target_ids[:10]))  # narrow scope","preventionTips":["Pass node_ids/include filters instead of flattening whole artifacts","Size max_content_nodes to your real documents at deployment","Coarsen chunking at ingestion if artifacts create huge node counts"],"tags":["content","limits","tree","ingestion"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}