{"record":{"id":"0032da0b7ae91f81","repo":"HKUDS/DeepTutor","slug":"figure-generation-failed-exc","errorCode":null,"errorMessage":"figure generation failed: {exc}","messagePattern":"figure generation failed: (.+?)","errorType":"exception","errorClass":"GenerationFailure","httpStatus":null,"severity":"error","filePath":"deeptutor/book/blocks/figure.py","lineNumber":107,"sourceCode":"                analysis=analysis,\n            )\n            ok, validation_error = validate_visualization(code, analysis.render_type)\n            if ok:\n                review = ReviewResult(\n                    optimized_code=code,\n                    changed=False,\n                    review_notes=\"Passed local validation.\",\n                )\n            else:\n                review = await pipeline.run_repair(\n                    user_input=user_input,\n                    analysis=analysis,\n                    code=code,\n                    error=validation_error,\n                )\n        except Exception as exc:\n            logger.warning(f\"FigureGenerator failed: {exc}\", exc_info=True)\n            raise GenerationFailure(f\"figure generation failed: {exc}\") from exc\n\n        final_code = review.optimized_code or code\n        render_type = analysis.render_type\n        final_ok, residual_error = validate_visualization(final_code, render_type)\n        if not final_ok:\n            raise GenerationFailure(f\"figure failed validation after repair: {residual_error}\")\n        lang_tag = {\n            \"svg\": \"svg\",\n            \"mermaid\": \"mermaid\",\n            \"chartjs\": \"javascript\",\n        }.get(render_type, \"svg\")\n\n        return (\n            {\n                \"render_type\": render_type,\n                \"code\": {\"language\": lang_tag, \"content\": final_code},\n                \"description\": analysis.description,\n                \"chart_type\": analysis.chart_type,","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/book/blocks/figure.py#L89-L125","documentation":"The figure block wraps the whole FigureGenerator pipeline (analysis → code generation → validation/review) in a try/except; any exception escaping it — LLM API errors, parsing errors, internal assertion failures — is re-raised as GenerationFailure('figure generation failed: ...'). The original exception is chained and logged with a warning traceback.","triggerScenarios":"Calling figure _generate when FigureGenerator throws: LLM provider network/auth error, unparseable LLM JSON for analysis/code, missing API key, or an internal bug in the generator's analysis/codegen steps.","commonSituations":"Expired/missing LLM API key; provider rate limits or timeouts mid multi-step figure generation; model returns markdown-wrapped JSON the generator can't parse; version mismatch between the figure generator package and the block's expected interface.","solutions":["Check the logged warning traceback (exc_info=True) to identify the underlying exc — it names the real cause","Fix provider-level issues first: API key, rate limit, network, model name","Retry the block once; multi-step LLM pipelines fail transiently","If it's a parsing failure, use a more capable model or fix the prompt/output-format settings in the figure generator"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"from deeptutor.services.config.runtime_settings import get_llm_settings\ns = get_llm_settings()\nassert s.api_key, 'LLM API key missing before figure generation'","typeGuard":null,"tryCatchPattern":"try:\n    payload, refs, meta = await figure_block.generate(ctx)\nexcept GenerationFailure as exc:\n    logger.warning('figure block failed: %s', exc)\n    payload = fallback_static_figure(ctx)  # or skip block","preventionTips":["Validate LLM credentials/quota before starting multi-step figure pipelines","Keep the figure generator package version pinned and matched to the block","Always inspect the chained cause in logs — the real failure is the inner exc"],"tags":["figure","llm-pipeline","wrapper-exception","generation"],"backgroundTag":"llm-generation-pipeline-failure","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}