Integrating LLMs with CAD: A Practical Guide to Automated Topology Recognition

    This article explores why extracting topological relationships from CAD drawings is a high-precision task that pushes general-purpose LLMs to their limits, and presents an engineering architecture built around a three-layer decoupling of perception, decision, and execution. It covers two common failure modes, a multi-modal fallback chain, stability constraints for tool-calling layers, an explicit state machine, and evaluation metrics that prioritize reliable partial results over single-shot success. Readers will learn how to turn an unreliable model attempt into a measurable production pipeline.

    1. Background: Why Extracting Topology from Graphical Relationships Is the Hard Zone for LLMs

    In engineering design, extracting adjacency, containment, intersection, and connection relationships between drawing elements from a finished diagram, and then outputting a topology structure, is a typical “low-semantics, high-precision” task. It demands three capabilities from the model at the same time. First, spatial reasoning: determining whether two 2D objects intersect and which one contains the other. Second, tool orchestration: repeatedly reading drawing data through external interfaces. Third, exception recovery: adjusting strategy on its own when an interface times out or an instruction requires secondary confirmation.

    These three points are exactly where current general-purpose LLMs are weak. In real-world deployment, the correct expectation is therefore not “success on the first try,” but a pipeline designed to allow trial and error, rollback, and human takeover. Any approach that stakes delivery quality on a single inference will basically fail.

    2. Two Abstract Failure Paradigms: Mechanical and Drifting

    Abstracting how different models behave on the same type of task yields two typical failure modes. They are unrelated to any specific product and depend only on the reasoning strategy.

    The first is mechanical execution. Once a model picks a technical path, it rigidly keeps doubling down on it: if reading coordinates fails, it switches to another way of reading coordinates; if that fails too, it reads coordinates of more surrounding objects, and never switches the perception channel. The result is slow speed, heavy token consumption, and going further and further down the wrong path. The essence of this behavior is a lack of the metacognition needed for “strategy switching.”

    The second is task drift. The model skips steps, forgets earlier constraints, and delivers incomplete output, like a careless executor. It is not that it cannot do the work; it lacks external state constraints, and key instructions get diluted in a long context.

    The engineering fix is the same for both: do not count on the model to self-reflect. Instead, write “when to switch paths” and “which step we are on now” into external code.

    3. Architecture: Decoupling Perception, Decision, and Execution

    The recommended minimum viable architecture has three layers.

    The perception layer converts drawing state into information the model can read, with at least three channels: a structured element list, precise coordinates and geometry parameters, and rendered bitmaps of locally zoomed-in regions. The key is that all three channels must be freely switchable, not fixed to one.

    The decision layer only chooses the next action, and its output must be a constrained structured result rather than free text. An example:

    1. {
    2. "action": "perceive",
    3. "channel": "render_zoom",
    4. "target": {"layer": "A-WALL", "bbox": [120, 88, 340, 260]},
    5. "hypothesis": "This rectangle intersects the wall on the left",
    6. "fallback": ["read_coords", "ask_human"]
    7. }

    The execution layer calls external interfaces, handles timeouts and retries, and suspends to wait for human input when an instruction needs secondary confirmation. Putting the confirmation logic in the execution layer rather than in the model is the key to avoiding a stalled process.

    4. Multi-Modal Fallback Chain: Don’t Hang Everything on One Tree

    The most valuable observation in the original discussion is this: when coordinates are hard to use, switch to rendered image recognition; when precision is insufficient, zoom in locally; after human correction, go back to coordinates for verification. Formalized, this becomes a fallback chain with priorities and termination conditions:

    1. First read structured data and coordinates, which has the lowest cost;
    2. If geometric objects are non-point-like and insertion points carry no discriminative meaning, render and recognize the drawing as a whole;
    3. If the resolution of the overall rendering is insufficient, re-render a locally zoomed region based on the bounding box;
    4. If human feedback indicates a recognition error, go back to coordinates for cross-validation to determine whether it is a perception error or a reasoning error;
    5. If confidence does not improve for two consecutive rounds, suspend, and output intermediate artifacts plus a list of open questions.

    The value of this chain is that it turns the unverifiable question of “whether the model has multi-modal capability” into the verifiable engineering question of “whether every step is guaranteed to have an alternative channel.”

    5. Stability Constraints for the Tool-Calling Layer

    When an external interface is hammered into unresponsiveness, it is usually not the model being malicious but a lack of budget control. Four gates must be added at the tool layer: a cap on the number of records returned per single call, a cap on the number of calls per unit of time, a cap on the total number of calls per task, and an explicit allowlist for high-risk bulk actions such as full scans. It is also advisable to agree on paginated reads and filtering by layer to avoid pulling all elements at once.

    For instructions that need secondary confirmation or contain branches, it is recommended to maintain a pending-confirmation queue in the execution layer and save a context snapshot along with it, so that after human handling the flow can resume from the breakpoint instead of running the whole process again.

    6. State Machine and Prompt Constraints

    Carrying the flow with an explicit state machine can significantly suppress task drift:

    1. INIT -> PERCEIVE -> HYPOTHESIZE -> VERIFY -> (COMMIT | FALLBACK | ASK_HUMAN)
    2. FALLBACK -> PERCEIVE
    3. ASK_HUMAN -> VERIFY

    The prompt only needs to emphasize three hard constraints: output exactly one action per round; always state the current hypothesis and how it will be verified; never repeat a channel already judged invalid.

    7. Evaluation and Acceptance

    Do not use “did it get it right on the first try” as the metric. Four metrics are recommended instead: topology relationship accuracy, number of human takeovers, total number of tool calls, and end-to-end latency per task. Also keep complete trajectory logs so it is easy to locate whether the problem is a perception error, a reasoning error, or an interface error. For tasks beyond the capability boundary, the acceptance criterion should be “output trustworthy partial results with a clear list of open questions,” not full correctness.

    8. Conclusion

    When handing a high-difficulty task to a model, what really determines success or failure is not how clever a single inference is, but whether the surrounding engineering provides multi-channel perception, hard resource budgets, and state management that can be suspended and resumed. If rendering, logging, and task scheduling need to run in the cloud, you can use object storage to keep intermediate artifacts, a container platform to run rendering and the interface proxy, and logging and monitoring services with alerting to track call trajectories, turning one unreliable attempt into a measurable, convergent production pipeline.