Systems that turn an image of a chart into the plotting code that reproduces it work in a loop. They write code, render it, ask a vision-language model (a model that reads images and writes text) how the rendered picture differs from the target, and then edit the code. The weak link is that last judge. Vision-language models routinely describe things that are not in the image. A judge that reports a missing legend or a wrong color that is not actually wrong pushes the generator into breaking code that was correct. The rendered half of that comparison never needed to be seen, though. The program that drew it knows exactly which lines, bars, labels, and colors it contains. We propose to read the rendered side directly from the plotting library's own object tree, to ask the vision model only narrow, checkable questions about the target image, and to edit only the code lines that produced the elements in question.
The idea borrows from schema pruning in text-to-SQL, where a model writing a database query is shown only the small subset of tables and columns it needs, because showing the whole database dilutes attention and invites invented column names. Here the "schema" is the figure's element tree. Each refinement round shrinks both what the critic must look at and what the code editor must read to the few elements with a verified discrepancy. We expect this to cut critic hallucinations, regressions between rounds, and token cost at the same time. All three are documented weaknesses of current refinement loops.
Core Claim
In chart-to-code refinement, most hallucinated critique comes from asking a vision model to describe two images freely and compare them. A plotting library exposes every drawn element of the rendered chart: its type, text, color, position, and bounding box. Each element can also be traced back to the code line that created it. Our claim is that a refinement loop built on this fact will match or beat free-form image-comparison critics at lower cost, and will show fewer rounds in which a correct element gets broken. The loop reads the rendered chart symbolically, turns critique into element-level yes/no checks on cropped regions of the reference image, rejects any critic claim that contradicts the rendered object tree, and passes the editor only the provenance-linked code lines. We do not claim the vision model's perception of the reference image becomes reliable. We claim that removing its unnecessary perception of the rendered image, and constraining the rest, measurably shrinks the error channel.
What Exists and Where This Differs
The closest work is ChartIR. It generates a structured description of the reference chart, renders candidate code, and prompts a multimodal model to describe differences between the two full images across several dimensions before refining. CITL does the analogous thing for web pages, with a visual critic, a code critic, and an improver. It acknowledges that its vision judge has inherent biases and that context grows across rounds. Both systems motivate this proposal and supply the overall loop we reuse. Both also perceive the rendered output through pixels, accept the critic's claims unchecked, and pass the full code forward. Our proposal changes those three points.
The hallucination literature explains why unchecked claims are dangerous. POPE documents "Yes" response rates near 99% on binary object queries for some models. MERLIM shows models keep asserting objects after they are inpainted away, and that answers swing by up to 26.5% under rephrasing. Why LVLMs Are More Prone to Hallucinations in Longer Responses shows attention drifting from the image toward the model's own text as outputs lengthen, which is exactly what a long, multi-dimensional difference report is. Work on vision models as judges (Chen et al., Kaiyi Huang) reports them inventing errors. ChartMimic adds that chart-to-code models invent text labels and confuse chart types such as violin and box plots. These papers constrain the design. They tell us to avoid long free-form critiques and unverified "is there a difference?" questions. That is why our critic asks about one element on one crop and is checked against a symbolic record.
Three papers supply method. SQL-to-Schema and ASTReS prune a database schema by parsing a draft query for the elements it references. We parse the draft figure's object tree in the same way. COCOGEN treats a compiler error as a request to retrieve exactly the missing definitions. We treat a verified visual discrepancy as a request for exactly the responsible code lines. COCOGEN operates only on text and compile errors. SQL-to-Schema notes that pruning from a draft can permanently exclude a needed element, and we address that failure explicitly below. MEIC supplies the rollback rule: revert any edit that makes things worse. MLS also converts a visual input into a compact structural blueprint before generating code, but it is a one-pass pipeline with no execution feedback. We use structure inside the loop, not before it.
Research Program
The system has four parts, built for Matplotlib because both target benchmarks use it.
The first part is a rendered-side extractor. After executing candidate code, it walks the figure's object tree and records, for every drawn element, its type, text, color, marker, line style, data extent, and pixel bounding box. It also records the source line that created the element, captured by wrapping plotting calls with a lightweight tracer. The result is a symbolic description of the rendered chart that is exact by construction.
The second part is a reference-side element proposer. Once, at the start, the vision model produces a structured inventory of the reference chart, in the spirit of ChartIR's first stage. Each inventory entry is aligned to rendered elements by type and approximate position.
The third part is the verifier critic, and it replaces free-form comparison. For each aligned pair, the system crops the reference region and asks a narrow question whose rendered-side answer is already known, for example "Is the line in this crop dashed?" or "Does this label read 'Accuracy (%)'?" A discrepancy is accepted only if two conditions hold. It must survive a rephrased version of the question, a cheap guard against the prompt sensitivity MERLIM documents. And it must not contradict the rendered record: a claim that "the legend is missing" is discarded outright if the object tree contains a legend.
To limit the cascading-exclusion failure that SQL-to-Schema identifies, any region where a simple pixel difference between reference and render is large but no element was flagged is sent back to the proposer as a possibly unmodeled element. The full inventory is also re-proposed once every few rounds.
The fourth part is a provenance-scoped editor. It receives the accepted discrepancies and only the code lines linked to the affected elements, plus their immediate dependencies. It does not receive the whole script or the transcript of earlier rounds. Each edit is kept only if a cheap low-level similarity score does not drop and no previously verified-correct element changes. Otherwise it is rolled back, as in MEIC.
Analysis accompanies the system. We will measure how often critics hallucinate under each design, how often an edit breaks a correct element, and how tokens per round grow with and without scoping.
Baselines
The naive reference point is direct generation, meaning one pass from image to code with no refinement, using the same backbone. On ChartMimic Direct Mimic, ChartMimic reports GPT-4o at an overall score of 81.2 with a 93.2% execution success rate.
The strongest existing method is ChartIR. ChartIR reports a GPT-4o Score of 7.15 on ChartMimic and 6.56 on Plot2Code with GPT-4o as backbone. With Qwen2-VL it reports 3.86 on ChartMimic and 3.54 on Plot2Code, up from 3.12 for direct generation on Plot2Code. We will reimplement ChartIR on the same backbones, with the same maximum number of rounds, the same sampling temperature, and the same prompt-tuning budget given to our system. We will report both our reproduction and the published numbers, so that any gap between the two is visible. Beating ChartIR means a higher score than our reproduction of ChartIR on the same backbone at an equal or smaller multimodal-token budget, consistent across three seeds. It also means a lower regression rate, defined as the fraction of rounds in which some previously correct element becomes wrong.
A second strong baseline is ChartIR with MEIC-style rollback added, using the same low-level similarity score we use. This isolates how much of any gain comes merely from refusing bad edits. It is the competitor most likely to close the gap, as discussed below.
The ablations each remove one ingredient. The first restores pixel-based reading of the rendered side while keeping element-level questions; this is the key test of the symbolic-grounding claim. The second keeps symbolic reading but returns to free-form critique. The third drops the contradiction check against the rendered record. The fourth passes the full script and transcript to the editor instead of provenance-scoped lines. The fifth drops the pixel-difference recall guard.
Why not just…?
Why not just add anti-hallucination decoding such as RITUAL to ChartIR's critic? RITUAL raises LLaVA-1.5's POPE accuracy from 84.13% to 88.87% by mixing predictions on transformed images. That gain comes on short object-presence questions, not long two-image difference reports, and it multiplies forward passes. More importantly, it still perceives the rendered chart through pixels, when that information is free and exact. We will run ChartIR with a RITUAL-style critic as an additional arm. If it matches our critic-precision numbers on the controlled benchmark below, the symbolic-reading component is not earning its complexity, and we will say so.
Why not just use rollback, as MEIC does, and keep the free-form critic? This is the real threat. Rollback stops hallucinated critiques from degrading the code, and it might capture most of the score gain. What it cannot do is turn wasted rounds into useful ones: a rejected edit still costs a full critique, and the loop may plateau early, as Yan et al. report. The ChartIR-plus-rollback baseline settles this. If it matches our score and our cost per accepted fix, the contribution reduces to rollback, and the proposal would pivot to a study of critic error alone.
Why not just use a pixel or perceptual similarity score as the critic and skip the vision model? Low-level scores can rank candidates but cannot say what to change in code. A score drop does not distinguish a wrong marker from a shifted axis. CITL's finding that refinement without a critic yields only a 1.5% improvement, against 17.8% with one, suggests feedback content matters. We still use such a score for rollback and recall, and will include a score-guided best-of-N sampling arm at matched compute to measure how far content-free feedback goes.
Why not just give a long-context model the whole history and image every round? Schema-pruning results in text-to-SQL (ASTReS, Text2Sql) and the long-response drift result above both point the other way. The full-context editor ablation tests this directly in our setting.
Proposed Experiments
The main evaluation runs on ChartMimic, using both Direct and Customized Mimic tasks, and on Plot2Code, with GPT-4o and Qwen2-VL backbones. We report each benchmark's own metrics, the GPT-4o Score used by ChartIR, execution success rate, regression rate, and multimodal tokens per round and in total. Because the GPT-4o Score is itself produced by a vision judge, a 100-chart subset will also receive blinded human pairwise judgments between our system and the ChartIR reproduction.
The decisive check is a controlled critic benchmark that we build from benchmark code. We take reference scripts and apply known perturbations, such as changing a color, removing a legend, swapping a marker, altering a tick label, or changing a chart type. This gives render pairs whose true discrepancies are known exactly. Null pairs, where both renders come from identical code, measure invented flaws directly: a POPE-style false-alarm rate for critics. We measure claim precision and recall for ChartIR's free-form critic, the RITUAL-augmented critic, and our verifier critic.
The proposal's central claim predicts a large drop in false alarms on null pairs and a precision gain on perturbed pairs, with recall within a few points of the free-form critic. If precision improves but recall collapses, the pruning is too aggressive. That outcome would point to the recall guard, which the corresponding ablation tests. If the pixel-reading ablation performs as well as symbolic reading, the core idea is wrong for charts.
A secondary transfer study applies the same design to web pages on Design2Code, where the rendered document's element tree plays the role of the figure's object tree. This tests whether the approach generalizes beyond a single plotting library.
References
- Improved Iterative Refinement for Chart-to-Code Generation via Structured Instruction
- Vision-Guided Iterative Refinement for Frontend Code Generation
- Evaluating Object Hallucination in Large Vision-Language Models
- Behind the Magic, MERLIM: Multi-modal Evaluation Benchmark for Large Image-Language Models
- Why LVLMs Are More Prone to Hallucinations in Longer Responses: The Role of Context
- MLLM-as-a-Judge: Assessing Multimodal LLM-as-a-Judge with Vision-Language Benchmark
- T2I-CompBench: A Comprehensive Benchmark for Open-world Compositional Text-to-image Generation
- ChartMimic: Evaluating LMM's Cross-Modal Reasoning Capability via Chart-to-Code Generation
- SQL-to-Schema Enhances Schema Linking in Text-to-SQL
- Improving Retrieval-augmented Text-to-SQL with AST-based Ranking and Schema Pruning
- Iterative Refinement of Project-Level Code Context for Precise Code Generation with Compiler Feedback
- MEIC: Re-thinking RTL Debug Automation using LLMs
- Modular Layout Synthesis (MLS): Front-end Code via Structure Normalization and Constrained Generation
- RITUAL: Random Image Transformations as a Universal Anti-hallucination Lever in LVLMs
- CodeTransOcean: A Comprehensive Multilingual Benchmark for Code Translation
- Text2Sql: Pure Fine-Tuning and Pure Knowledge Distillation