HKUDS/DeepTutor · error · GenerationFailure

figure failed validation after repair: {residual_error}

Error message

figure failed validation after repair: {residual_error}

What it means

After the FigureGenerator produces (possibly repaired) code, the block re-validates it with validate_visualization(final_code, render_type). If validation still fails after the repair pass, this GenerationFailure is raised with the residual validation error — meaning the generated SVG/Mermaid/Chart.js code is structurally invalid.

Source

Thrown at deeptutor/book/blocks/figure.py:113

                    changed=False,
                    review_notes="Passed local validation.",
                )
            else:
                review = await pipeline.run_repair(
                    user_input=user_input,
                    analysis=analysis,
                    code=code,
                    error=validation_error,
                )
        except Exception as exc:
            logger.warning(f"FigureGenerator failed: {exc}", exc_info=True)
            raise GenerationFailure(f"figure generation failed: {exc}") from exc

        final_code = review.optimized_code or code
        render_type = analysis.render_type
        final_ok, residual_error = validate_visualization(final_code, render_type)
        if not final_ok:
            raise GenerationFailure(f"figure failed validation after repair: {residual_error}")
        lang_tag = {
            "svg": "svg",
            "mermaid": "mermaid",
            "chartjs": "javascript",
        }.get(render_type, "svg")

        return (
            {
                "render_type": render_type,
                "code": {"language": lang_tag, "content": final_code},
                "description": analysis.description,
                "chart_type": analysis.chart_type,
            },
            [],
            {
                "review_changed": review.changed,
                "review_notes": review.review_notes,
            },

View on GitHub (pinned to 3e82f13042)

Solutions

  1. Read the residual_error text — it pinpoints the syntax problem (e.g. Mermaid node id, unbalanced XML tag)
  2. Retry generation, optionally with a stronger model or a simpler figure prompt
  3. Verify render_type detection matches the actual code language so the right validator runs
  4. If persistent, manually supply or edit the figure code instead of relying on generation
Defensive patterns

Strategy: retry

Type guard

def looks_like_render_type(code: str) -> str:
    c = code.strip()
    if c.startswith('<svg'):
        return 'svg'
    if 'graph ' in c or 'flowchart' in c:
        return 'mermaid'
    return 'chartjs'

Try / catch

attempts = 2
for i in range(attempts):
    try:
        return await figure_block.generate(ctx)
    except GenerationFailure as exc:
        if 'failed validation after repair' in str(exc) and i < attempts - 1:
            ctx = simplify_request(ctx)  # smaller/simpler figure
            continue
        raise

Prevention

When it happens

Trigger: Calling figure _generate when the final optimized/repaired code still fails validate_visualization for its render_type (svg, mermaid, or chartjs) — e.g. malformed SVG XML, invalid Mermaid syntax, or Chart.js config with a JS syntax error.

Common situations: LLM produces syntactically broken Mermaid/SVG that the single repair pass can't fix; render_type misdetected (chartjs code validated as svg); stricter validator rules after a dependency upgrade; long/complex figures exceeding model capability.

Related errors


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/6b97d0deb6caed90. Report an issue: GitHub.