DEV Community

Cover image for Debugging Claude Fable 5.2 Code Art: Truncated SVG, Broken Canvas, Working Render
boluo
boluo

Posted on

Debugging Claude Fable 5.2 Code Art: Truncated SVG, Broken Canvas, Working Render

The first big Canvas request did not give me a finished picture. Another returned HTTP 200 with no usable body. I could have kept raising the output limit, but a longer SVG attempt had already ended inside an XML tag. The useful change was to ask Claude Fable 5.2 for a smaller, complete artifact, open it, and only then build a richer scene in parts.

I tested this on November 18, 2026, with a late-autumn village in southern China: hills, white houses with gray roofs, harvested rice fields, a water channel, and an old bicycle. Everything in the final scene was drawn by code; the page did not load an image generator or outside assets. My short SVG request finished in about 37 seconds and rendered, though the art was simple. The later Canvas picture looked better, but it took continuation, assembly, and a manual correction.

AI disclosure: An AI assistant generated this article from saved test records. Its technical details were checked against the requests, response summaries, and rendered result.

The failed request that changed the workflow

An X thread collecting code-made art and interactive work prompted the experiment. It included a shopping-cart painting described as a Python-programmed image. I liked its lighting and empty parking-lot composition, but I did not replay the thread's videos or reproduce that painting. I chose an ordinary brief with enough depth and small objects to expose weak composition.

The brief asked for a village at dusk. It prohibited external images, fonts, libraries, CDNs, and image-model calls. My first instinct was to ask for the whole Canvas page. That failed as a deliverable. One shorter Canvas try returned an empty body with finish_reason=length despite HTTP 200; a more expansive one did the same at a larger output limit. The connection worked, but I had no page to open.

A static SVG request produced 14,399 characters, then stopped midway through a tag with finish_reason=length. This was a useful failure: it showed that more text could still leave me with an invalid file. I changed the task from “make the best picture” to “return one complete SVG under 6,000 characters.”

That compact request returned 5,585 characters in about 37 seconds with finish_reason=stop. It parsed as XML and opened in a browser. At that point I finally had something I could inspect, version, and improve. The houses, hills, fields, water, and bicycle were there. The houses were also too evenly arranged, and the bicycle and stubble read like icons. A runnable file had solved the delivery problem, not the visual one.

Reproducing the compact SVG request

Here is the complete request for the smallest successful artifact. The test used Crazyrouter's OpenAI-compatible endpoint, model ID claude-fable-5-2, max_tokens=5000, reasoning_effort=low, and stream=false. A client configured with a Base URL would use https://api.crazyrouter.com/v1; this direct HTTP example calls https://api.crazyrouter.com/v1/chat/completions. The endpoint documentation distinguishes the two forms. Check the exact model ID available to your account before running it.

Save this as test_fable.py, run python test_fable.py with Python 3, then open rural-scene.svg in a browser. The prompt stays in Chinese because that is what I sent in the recorded test. Translating it would change the input condition.

import getpass
import json
import urllib.request
import xml.etree.ElementTree as ET
from pathlib import Path

API_URL = "https://api.crazyrouter.com/v1/chat/completions"
MODEL = "claude-fable-5-2"
PROMPT = "只输出完整SVG源码,不要Markdown或解释。总长度严格控制在6000字符以内,首行为<svg,末尾为</svg>。用纯SVG矢量画一幅1200×800的中国南方普通农村晚秋傍晚:前景收割后的稻田、窄水沟和田埂;中景三栋错落的白墙灰瓦民居、一辆旧自行车;远景低矮青山。光线统一、冷暖有层次、空间连续,避免灯笼、牌坊、标语和景点风格。用渐变、路径和少量重复图形表现绘画感。不要外部资源、脚本或图像模型。优先保证文件完整可渲染,不足的细节可以省略。"

key = getpass.getpass("Crazyrouter API Key: ").strip()
if not key:
    raise SystemExit("No API key entered")

payload = {
    "model": MODEL,
    "messages": [{"role": "user", "content": PROMPT}],
    "max_tokens": 5000,
    "reasoning_effort": "low",
    "stream": False,
}
request = urllib.request.Request(
    API_URL,
    data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
    headers={"Authorization": f"Bearer {key}", "Content-Type": "application/json"},
    method="POST",
)
with urllib.request.urlopen(request, timeout=120) as response:
    result = json.load(response)

choice = result["choices"][0]
svg = choice["message"]["content"].strip()
if choice.get("finish_reason") != "stop":
    raise SystemExit(f"Incomplete response: {choice.get('finish_reason')}")
ET.fromstring(svg)
Path("rural-scene.svg").write_text(svg, encoding="utf-8")
print("Saved rural-scene.svg; open it in a browser")
Enter fullscreen mode Exit fullscreen mode

This code checks for a completed response and valid XML before it writes the file. It does not score the composition. A later run might produce a different SVG, and it will not recreate the Canvas image below. That image took a separate sequence of prompts and manual work.

What it took to finish the Canvas scene

For more detail, I split the drawing into layers. The village segment stopped inside a roof-tile loop, so I asked for a continuation. The foreground segment completed. I assembled the generated pieces into an offline HTML page. The code then failed because one function treated the random-number function R as if it carried width and height. I supplied R.w=1200 and R.h=800 in the test wrapper before the page rendered.

The final three API calls in this segmented phase took 48.6, 20.5, and 36.6 seconds: about 106 seconds of API time. That does not include reading the output, joining the parts, fixing the parameter issue, or rendering the page. It also is not a direct speed comparison with the 37-second SVG call: the outputs and amount of work differ.

Code-rendered village at dusk, with hills, tiled houses, rice fields, a water channel, and a bicycle

The finished Canvas scene has roof tiles, worn walls, drying corn, rice stubble, a deeper channel, and a recognizable bicycle frame. The forms remain regular, especially around the hills and houses. I would call it a detailed programmatic illustration, not evidence that this model beats a dedicated image generator. I did not run a matched image-model comparison.

A code art workflow I'd reuse

I would keep the compact SVG as a working baseline, then ask for one visual change at a time: reposition the houses, change the foreground scale, add texture to the roofs, and check the light direction. For a Canvas version, I would request named sections with clear interfaces, run each section as it arrives, and inspect the joins before adding more detail. If a response ends with length, I would treat that section as incomplete, not as a file to publish.

This experiment left me with a practical boundary. Claude Fable 5.2 could produce code for an editable scene, and the rendered image improved when I broke the work into parts. The final picture also depended on my continuation request, assembly, and correction. For code art, the generated program is the start of the review, not the review itself.

Top comments (0)