{"record":{"id":"7b021cec08355d47","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"semantic-analysis-failed-str-e","errorCode":null,"errorMessage":"Semantic analysis failed: {str(e)}","messagePattern":"Semantic analysis failed: (.+?)","errorType":"error_code","errorClass":"AnalysisError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/utils/code_error_analysis.py","lineNumber":335,"sourceCode":"        prompt = PromptTemplate(\n            template=get_optimal_analysis_template(\"semantic\"),\n            input_variables=[\"generated_code\", \"differences\", \"explanation\"],\n        )\n        chain = prompt | llm_model | StrOutputParser()\n\n        # Execute chain with validated inputs\n        return chain.invoke(\n            {\n                \"generated_code\": validated_state.generated_code,\n                \"differences\": json.dumps(comparison_result[\"differences\"], indent=2),\n                \"explanation\": comparison_result[\"explanation\"],\n            }\n        )\n\n    except KeyError as e:\n        raise InvalidStateError(f\"Missing required key: {e}\")\n    except Exception as e:\n        raise AnalysisError(f\"Semantic analysis failed: {str(e)}\")\n","sourceCodeStart":317,"sourceCodeEnd":336,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/utils/code_error_analysis.py#L317-L336","documentation":"Catch-all failure of the semantic-focused LLM analysis chain; the original exception is appended to the message. Indicates prompt/LLM failure rather than a state-shape problem.","triggerScenarios":"semantic_focused_analysis / semantic_comparison_loop invoked with failing llm_model (auth, quota, network) or when json.dumps of comparison_result['differences'] raises because differences is not JSON-serializable.","commonSituations":"differences containing non-serializable objects (e.g. LangChain return objects), provider rate limits, invalid API key, timeouts on long code snippets.","solutions":["Inspect str(e); if serialization, coerce differences to plain dicts/lists before calling","Verify differences/explanation are JSON-safe (json.dumps test)","Check llm_model auth/connectivity; retry on transient provider errors"],"exampleFix":"# before\nsemantic_focused_analysis(state, {\"differences\": llm_obj, \"explanation\": \"\"}, llm)\n# after\nsemantic_focused_analysis(state, {\"differences\": llm_obj if isinstance(llm_obj, (list, dict)) else str(llm_obj), \"explanation\": \"\"}, llm)","handlingStrategy":"try-catch","validationCode":"import json\njson.dumps(comparison_result[\"differences\"])  # raises early if not serializable","typeGuard":"def differences_serializable(cr) -> bool:\n    try:\n        json.dumps(cr.get(\"differences\"))\n        return True\n    except TypeError:\n        return False","tryCatchPattern":"from scrapegraphai.utils.code_error_analysis import AnalysisError\ntry:\n    semantic_focused_analysis(state, comparison_result, llm_model)\nexcept AnalysisError as e:\n    logger.error(\"semantic analysis failed: %s\", e)\n    raise","preventionTips":["Coerce differences to plain dicts/lists before calling","Verify API key and provider connectivity","Retry transient provider failures with backoff"],"tags":["llm","semantic-analysis","chain-invocation","serialization"],"backgroundTag":"llm-chain-invocation-failed","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}