{"record":{"id":"921d0365fd5da90e","repo":"run-llama/llama_index","slug":"first-argument-to-readability-constructor-should-b","errorCode":null,"errorMessage":"First argument to Readability constructor should be a document object.","messagePattern":"First argument to Readability constructor should be a document object\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"llama-index-integrations/readers/llama-index-readers-web/llama_index/readers/web/readability_web/Readability.js","lineNumber":33,"sourceCode":" */\n\n/*\n * This code is heavily based on Arc90's readability.js (1.7.1) script\n * available at: http://code.google.com/p/arc90labs-readability\n */\n\n/**\n * Public constructor.\n * @param {HTMLDocument} doc     The document to parse.\n * @param {Object}       options The options object.\n */\nfunction Readability(doc, options) {\n  // In some older versions, people passed a URI as the first argument. Cope:\n  if (options && options.documentElement) {\n    doc = options;\n    options = arguments[2];\n  } else if (!doc || !doc.documentElement) {\n    throw new Error(\n      \"First argument to Readability constructor should be a document object.\",\n    );\n  }\n  options = options || {};\n\n  this._doc = doc;\n  this._docJSDOMParser = this._doc.firstChild.__JSDOMParser__;\n  this._articleTitle = null;\n  this._articleByline = null;\n  this._articleDir = null;\n  this._articleSiteName = null;\n  this._attempts = [];\n\n  // Configurable options\n  this._debug = !!options.debug;\n  this._maxElemsToParse =\n    options.maxElemsToParse || this.DEFAULT_MAX_ELEMS_TO_PARSE;\n  this._nbTopCandidates =","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-integrations/readers/llama-index-readers-web/llama_index/readers/web/readability_web/Readability.js#L15-L51","documentation":"Raised by BaseDocumentStore.get_node (sync) when the object stored under node_id exists in the docstore but is not an instance of BaseNode. get_node first fetches via get_document; if that returns a non-BaseNode object (e.g. a raw dict, a legacy Document schema object, or data deserialized by a custom store incorrectly), the isinstance check fails and this ValueError is thrown. It signals corrupted or incompatible docstore contents rather than a missing node (a missing node raises 'Node {node_id} not found' instead).","triggerScenarios":"Calling docstore.get_node(node_id) where the stored value was written without proper serialization (e.g. a plain dict was put into the store), or reading a docstore persisted by an incompatible/older llama-index version whose deserialization (doc_to_dict/json_to_doc) produced an unexpected type, or a custom DocumentStore implementation whose get_document returns a Document typed object that is not a BaseNode subclass.","commonSituations":"Upgrading llama-index across major versions and reusing persisted SimpleDocumentStore JSON files; custom docstore backends that store raw dicts; stores populated by external processes that bypass add_documents; partially migrated legacy data using legacy_json_to_doc.","solutions":["Inspect what get_document(node_id) actually returns: print(type(docstore.get_document(node_id, raise_error=False))) to identify the offending type.","If the store holds raw dicts, re-insert nodes properly via docstore.add_documents([...]) using BaseNode objects (TextNode, Document, etc.) so serialization goes through doc_to_dict.","If data was persisted by an older llama-index version, rebuild the docstore from source documents and re-persist.","If using a custom DocumentStore, ensure get_document deserializes with llama_index.core.storage.docstore.utils.json_to_doc / legacy_json_to_doc so it returns BaseNode instances."],"exampleFix":"# before\nraw = {\"text\": \"hello\", \"id_\": \"n1\"}\ndocstore.put_document(raw)  # stores non-BaseNode\ndocstore.get_node(\"n1\")  # ValueError: Document n1 is not a Node.\n\n# after\nfrom llama_index.core.schema import TextNode\nnode = TextNode(id_=\"n1\", text=\"hello\")\ndocstore.add_documents([node], allow_update=True)\ndocstore.get_node(\"n1\")  # ok","handlingStrategy":"type-guard","validationCode":"doc = docstore.get_document(node_id, raise_error=False)\nif doc is None or not isinstance(doc, BaseNode):\n    # do not call get_node with raise_error=True\n    ...","typeGuard":"from llama_index.core.schema import BaseNode\n\ndef is_stored_node(docstore, node_id: str) -> bool:\n    doc = docstore.get_document(node_id, raise_error=False)\n    return isinstance(doc, BaseNode)","tryCatchPattern":"try:\n    node = docstore.get_node(node_id)\nexcept ValueError as e:\n    if \"not a Node\" in str(e):\n        # corrupt entry: re-ingest or quarantine node_id\n        ...\n    else:\n        raise","preventionTips":["Always write nodes via docstore.add_documents so serialization goes through doc_to_dict.","Never put raw dicts into the docstore collection directly.","Keep llama-index versions aligned across all processes writing the store.","After loading a persisted docstore, spot-check get_node on one id before bulk processing."],"tags":["docstore","serialization","data-corruption","llama-index"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}