A Practical Guide to Multimodal LLM Diagram Reconstruction

    This guide explains how to convert diagrams into compilable, reusable vector descriptions with multimodal large language models. It breaks the task into four verifiable stages—element inventory, relation inference, structural abstraction, and symbol generation—and covers prompt design, occlusion and layer reasoning, constraint validation with automated correction loops, layered evaluation metrics, and engineering deployment on Baidu AI Cloud. Readers will learn how to reduce errors, expose issues early, and achieve more stable diagram reconstruction.

    1. Why Reconstruction Goes Beyond “Reading” an Image

    Converting a diagram into a compilable, reusable vector description is a typical cross-modal task. It requires more than recognizing what appears in the image. The model must complete three progressive layers of work:

    1. Perception: identify shapes, text, and colors.
    2. Reasoning: infer the 3D structure, occlusion relationships, and layer order behind a 2D projection.
    3. Generation: map the reasoning results into structured fields such as coordinates, paths, solid and dashed lines, fill regions, and drawing order.

    These layers are difficult because of information loss and overlapping constraints. An image is the result of projecting a continuous signal, so depth information is compressed. A vector description, by contrast, is a strongly constrained symbolic system: coordinates must be consistent, paths must be closed, and drawing order must match actual occlusion. A deviation at any layer produces an output that either “looks right but does not compile” or “compiles but has the wrong structure.”

    2. Task Breakdown: Turning Complex Diagrams into Verifiable Intermediate Representations

    Split the task into four independently verifiable stages to avoid the unpredictability of one-shot generation.

    1. Element inventory: list all visible elements, including geometric shapes, text labels, arrows, and connector lines, with rough bounding boxes.
    2. Relation inference: annotate relative positions, containment, intersections, and front-to-back occlusion to form a relation graph.
    3. Structural abstraction: map the relation graph to a layered model that identifies background elements, main subjects, and top-level annotations.
    4. Symbol generation: generate the vector description in layer order, drawing lower layers first and upper layers later so occlusion holds naturally.

    The main benefit of this staged approach is locatability. When an output is wrong, you can quickly determine whether the error came from perception, relations, or symbolization, rather than concluding vaguely that “the model is not good enough.”

    3. Prompt and Context Design: Constraining Output with Examples

    Structured generation is far more sensitive to prompts than open-ended question answering. A practical prompt usually contains four types of information: task instructions, input data, output schema, and constraints. For example:

    1. Task: Convert a diagram into a layered vector description.
    2. Input: <an image or a structured description of the image>
    3. Output schema:
    4. {
    5. "layers": [
    6. {"order": 1, "elements": [{"type": "rect", "x": 0, "y": 0, "w": 10, "h": 6, "fill": "none"}]}
    7. ],
    8. "relations": [{"from": "e1", "to": "e2", "type": "occludes"}]
    9. }
    10. Constraints:
    11. 1. Coordinates must fall within the canvas.
    12. 2. Draw occluded elements first.
    13. 3. Use dashed lines only for hidden edges.
    14. 4. Do not add elements that do not exist in the diagram.

    More context examples are not always better. A common practice is to provide examples by difficulty: one simple example to fix the output schema, one example with occlusion to demonstrate drawing order, and one example with hidden edges to demonstrate solid and dashed lines. Too many examples crowd the context and introduce noise; too few allow the output schema to drift.

    4. Occlusion and Layer Reasoning: Inferring Structure from a Projection

    The key to occlusion reasoning is a visibility-first criterion: first determine which edges are visible solid lines and which are occluded hidden edges, then arrange the drawing order accordingly. A three-step method works well:

    • Build candidate occlusion pairs from intersection and containment relations.
    • Determine front-to-back order for each candidate pair; if a single view is insufficient, explicitly mark it as uncertain.
    • Return uncertain items as annotations instead of forcing a conclusion.

    At the symbol level, hidden edges are usually expressed with dashed lines, and occluded elements are placed at lower layer orders. Even with local uncertainty in reasoning, the output remains structurally consistent and easy for manual review.

    5. Constraint Validation and Automated Loops: Exposing Errors at Compile Time

    Always validate the output before delivery. Use three types of checks:

    1. Syntax validation: whether the structure is parseable, fields are complete, and numeric types are correct.
    2. Geometry validation: whether coordinates are out of bounds, paths are closed, and dimensions are non-negative.
    3. Semantic validation: whether the number of elements matches the element inventory, whether occlusion pairs match the relation graph, and whether any elements were added from nothing.

    When validation fails, return structured error messages to the model and restrict it to fixing only the problematic fields. This avoids introducing new deviations through a full rewrite. This “generate–validate–targeted correction” loop is usually more stable than a single long output.

    1. Validation failure example:
    2. {"error": "element e7 out of canvas", "hint": "clamp x to [0, 10]"}

    6. Evaluation: Layered Metrics Are More Reliable Than a Single Similarity Score

    A single overall similarity score does not reflect the true quality of this task. A more practical approach is layered evaluation: element recall measures missing elements, coordinate error measures localization accuracy, relation consistency measures occlusion and containment judgments, and compile pass rate measures output usability. Observing the four metrics together distinguishes two failure modes: “drawing less but accurately” and “drawing more but messily.”

    Also, fix an evaluation set containing simple diagrams, diagrams with occlusion, and diagrams with hidden edges. Run regression tests after every prompt or model version change to avoid local improvements causing overall degradation.

    7. Engineering Deployment: Building a Stable Pipeline on Baidu AI Cloud

    To productize the workflow, combine general cloud capabilities: object storage for original images and output versions, a message queue to smooth peaks and decouple generation from validation, a container platform to host stateless inference services for elastic scaling, and logging and monitoring with alerts to track success rate, latency, and validation failure distribution. Keys and access credentials should be managed centrally by a key management capability rather than hard-coded.

    For cost control, use a tiered strategy: start with a low-resource tier for quick drafts, and escalate only samples that fail validation to a higher-capability tier for retries. This concentrates compute on the samples that are genuinely difficult.

    8. Common Pitfalls and Improvement Directions

    • Pitfall 1: pursuing a perfect result in one generation. Improvement: staged generation with targeted correction.
    • Pitfall 2: ignoring drawing order. Improvement: treat layer order as a first-class output field and validate it strictly.
    • Pitfall 3: using overall similarity as the only metric. Improvement: layered metrics plus a fixed regression set.
    • Pitfall 4: forcing a conclusion under uncertainty. Improvement: explicitly output uncertainty markers and leave them for manual review or a second reasoning pass.

    Overall, converting a 2D diagram into a structured vector description is an engineering problem of “perception–reasoning–constrained generation–validation loop.” Whoever designs clearer intermediate representations and moves validation earlier will achieve more stable and maintainable reconstruction on complex diagrams.