{"record":{"id":"878b0dd75e4bdd57","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"no-parsed-documents-found-in-state","errorCode":null,"errorMessage":"No parsed documents found in state","messagePattern":"No parsed documents found in state","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/nodes/batch_generate_answer_node.py","lineNumber":168,"sourceCode":"\n        Args:\n            state (dict): Must contain:\n                - user_prompt: The user's question.\n                - parsed_docs: List of parsed document contents.\n                - urls: List of source URLs (for result mapping).\n\n        Returns:\n            dict: Updated state with 'results' key containing\n                  a list of answers (one per document).\n        \"\"\"\n        self.logger.info(f\"--- Executing {self.node_name} Node ---\")\n\n        user_prompt = state.get(\"user_prompt\", \"\")\n        parsed_docs = state.get(\"parsed_docs\", [])\n        urls = state.get(\"urls\", [])\n\n        if not parsed_docs:\n            raise ValueError(\"No parsed documents found in state\")\n\n        model_name = self._get_model_name()\n        format_instructions = self._get_format_instructions()\n\n        # Build batch requests with doc_id → URL mapping\n        batch_requests = []\n        doc_id_to_url = {}\n\n        for i, doc in enumerate(parsed_docs):\n            custom_id = f\"doc_{i:04d}\"\n            doc_id_to_url[custom_id] = urls[i] if i < len(urls) else f\"doc_{i}\"\n\n            # Handle chunked documents — use first chunk for batch\n            content = doc[0] if isinstance(doc, list) and len(doc) == 1 else str(doc)\n\n            prompt_text = self._build_prompt_text(\n                user_prompt, content, format_instructions\n            )","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/nodes/batch_generate_answer_node.py#L150-L186","documentation":"BatchGenerateAnswerNode.execute requires the 'parsed_docs' entry in the graph state to be non-empty before it can build batch requests. If state has no parsed_docs or it is an empty list, this ValueError is raised immediately.","triggerScenarios":"Running a batch graph where the parsing step produced no documents; skipping the parse step in the pipeline; passing an empty 'parsed_docs' list in a manually constructed state during tests.","commonSituations":"Upstream ParseNode/FetchNode failed silently or the source URL returned nothing; testing the node in isolation without seeding parsed_docs; wrong graph wiring that skips the parsing node.","solutions":["Verify the upstream fetch/parse nodes ran and populated state['parsed_docs']","Debug the preceding node's output (log len(state['parsed_docs']) before the batch node)","Seed parsed_docs with Document objects when unit-testing the node"],"exampleFix":"# before\nstate = {'user_prompt': 'summarize'}\nnode.execute(state)  # raises\n# after\nfrom langchain_core.documents import Document\nstate = {'user_prompt': 'summarize', 'parsed_docs': [Document(page_content='...')]}\nnode.execute(state)","handlingStrategy":"validation","validationCode":"if not state.get('parsed_docs'):\n    raise RuntimeError('upstream parse produced no docs; skipping batch step')","typeGuard":null,"tryCatchPattern":"try:\n    out = node.execute(state)\nexcept ValueError as e:\n    if 'No parsed documents' in str(e):\n        # re-run fetch/parse or log and skip\n        pass\n    else:\n        raise","preventionTips":["Log len(state['parsed_docs']) after the parse step in orchestration code","Validate state before invoking batch nodes"],"tags":["scrapegraphai","batch","state-validation","empty-input"],"backgroundTag":"empty-required-input","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}