ScrapeGraphAI/Scrapegraph-ai · error · AnalysisError
Semantic analysis failed: {str(e)}
Error message
Semantic analysis failed: {str(e)} What it means
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.
Source
Thrown at scrapegraphai/utils/code_error_analysis.py:335
prompt = PromptTemplate(
template=get_optimal_analysis_template("semantic"),
input_variables=["generated_code", "differences", "explanation"],
)
chain = prompt | llm_model | StrOutputParser()
# Execute chain with validated inputs
return chain.invoke(
{
"generated_code": validated_state.generated_code,
"differences": json.dumps(comparison_result["differences"], indent=2),
"explanation": comparison_result["explanation"],
}
)
except KeyError as e:
raise InvalidStateError(f"Missing required key: {e}")
except Exception as e:
raise AnalysisError(f"Semantic analysis failed: {str(e)}")
View on GitHub (pinned to 532dfffbf6)
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
Example fix
# before
semantic_focused_analysis(state, {"differences": llm_obj, "explanation": ""}, llm)
# after
semantic_focused_analysis(state, {"differences": llm_obj if isinstance(llm_obj, (list, dict)) else str(llm_obj), "explanation": ""}, llm) Defensive patterns
Strategy: try-catch
Validate before calling
import json json.dumps(comparison_result["differences"]) # raises early if not serializable
Type guard
def differences_serializable(cr) -> bool:
try:
json.dumps(cr.get("differences"))
return True
except TypeError:
return False Try / catch
from scrapegraphai.utils.code_error_analysis import AnalysisError
try:
semantic_focused_analysis(state, comparison_result, llm_model)
except AnalysisError as e:
logger.error("semantic analysis failed: %s", e)
raise Prevention
- Coerce differences to plain dicts/lists before calling
- Verify API key and provider connectivity
- Retry transient provider failures with backoff
When it happens
Trigger: 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.
Common situations: differences containing non-serializable objects (e.g. LangChain return objects), provider rate limits, invalid API key, timeouts on long code snippets.
Related errors
- Validation code generation failed: {str(e)}
- Syntax analysis failed: {str(e)}
- Execution analysis failed: {str(e)}
- Validation analysis failed: {str(e)}
- Syntax code generation failed: {str(e)}
AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28).
Data as JSON: /api/errors/7b021cec08355d47.
Report an issue: GitHub.