Source-linked AI summary
CAD-Coder: Text-to-CAD Generation with Chain-of-Thought and Geometric Reward
Yandong Guan, Xilin Wang, Ximing Xing, Jing Zhang, Dong Xu, Qian Yu
TL;DR
Text-to-CAD workflows remain expertise-intensive, difficult to validate, limited in operation diversity, and hard to interpret. CAD-Coder generates CadQuery code from natural language using a two-stage SFT-plus-GRPO pipeline with CoT planning and CAD-specific rewards; it achieves strong geometric accuracy while retaining valid-code generation, although complex spatial structures remain challenging.
Problem
Traditional and command-sequence-based CAD approaches require substantial expertise and offer limited validation, operation diversity, and interpretability, motivating more accessible natural-language-driven generation.
Method
CAD-Coder reformulates text-to-CAD as CadQuery code generation and combines supervised fine-tuning, GRPO reinforcement learning with CAD-specific rewards, and CoT planning.
Results
CAD-Coder achieves the best results across reported metrics, including Mean CD 6.54 and Median CD 0.17, while generating precise and structurally valid CAD models.
Takeaways & Limitations
CadQuery provides an interpretable, diverse, and geometrically valid representation for natural-language CAD generation, supported by a dataset of 110K text–CadQuery–3D model triplets and 1.5K CoT samples.
Takeaways & Limitations
The model sometimes lacks geometric accuracy and struggles with complex structures requiring multi-step or spatial reasoning.
Abstract
from arXiv · showhide
In this work, we introduce CAD-Coder, a novel framework that reformulates text-to-CAD as the generation of CadQuery scripts - a Python-based, parametric CAD language. This representation enables direct geometric validation, a richer modeling vocabulary, and seamless integration with existing LLMs. To further enhance code validity and geometric fidelity, we propose a two-stage learning pipeline: (1) supervised fine-tuning on paired text-CadQuery data, and (2) reinforcement learning with Group Reward Policy Optimization (GRPO), guided by a CAD-specific reward comprising both a geometric reward (Chamfer Distance) and a format reward. We also introduce a chain-of-thought (CoT) planning process to improve model reasoning, and construct a large-scale, high-quality dataset of 110K text-CadQuery-3D model triplets and 1.5K CoT samples via an automated pipeline. Extensive experiments demonstrate that CAD-Coder enables LLMs to generate diverse, valid, and complex CAD models directly from natural language, advancing the state of the art of text-to-CAD generation and geometric reasoning.
1 Introduction
CAD-Coder reframes text-to-CAD as generating Python-based CadQuery code, addressing validation, modeling-vocabulary, and interpretability limits of command-sequence approaches. Its two-stage training, CoT planning, CAD-specific rewards, and verified dataset target syntactic validity and geometric plausibility.
- Motivation: Traditional CAD workflows require substantial expertise and time, motivating natural-language interfaces for broader accessibility and faster iteration.LLM advances in language understanding and code generation create an opportunity to streamline CAD processes.
- Motivation: Command-sequence text-to-CAD methods are difficult to validate, support limited operations, and produce representations that are hard to interpret and edit.These limitations constrain generated-model diversity and complicate understanding and debugging.
- Representation: CAD-Coder reformulates text-to-CAD as generating Python-based CadQuery code, enabling direct geometric validation, diverse geometries, and more interpretable semantic constructs.CadQuery also leverages existing LLM code-generation capabilities.
- Training and rewards: The method uses supervised fine-tuning followed by GRPO reinforcement learning to establish syntax and mapping, then improve planning and reasoning with a CAD-specific reward.The reward addresses the task’s combined programming and 3D-modeling requirements.
- Training and rewards: CoT planning and CAD-specific rewards jointly target syntactic correctness and geometric plausibility in generated CAD models.The geometric reward uses Chamfer Distance, while the format reward enforces reasoning-process and code-syntax requirements.
- Data: The authors construct an automated, geometrically verified dataset containing 110K text–CadQuery-3D model triplets and 1.5K CoT samples.The dataset is intended to facilitate further research in text-to-CAD generation and geometric reasoning.
2 Related Work
CAD-Coder builds on LLM code generation and CAD representations by using executable, parametric CadQuery scripts instead of low-level command sequences. Its two-stage SFT-plus-RL strategy combines syntax learning with geometric refinement for natural-language CAD generation.
- CadQuery Representation: CadQuery is a Python-based, executable representation that supports modular, readable modeling procedures and high-fidelity geometry generation.Scripts can be directly executed and rendered into 3D geometry.
- CadQuery Representation: Unlike sketch-extrusion command sequences, CadQuery offers more interpretable and flexible geometric operations for language-model-based CAD generation.Traditional command sequences are linearized, low-level, and require post-processing.
- CAD-Coder Training: The pipeline first uses supervised fine-tuning to teach CadQuery syntax and text-to-operation mappings, then reinforcement learning to improve geometric accuracy and output validity.The two stages address syntax learning and geometric refinement respectively.
- CAD-Coder Training: The training data includes verified natural-language and CadQuery-code pairs, with 8K synthetic examples used for supervised fine-tuning.Ground-truth code is verified for executability and filtered by geometric correctness.
- CAD-Coder Training: Chain-of-thought planning and CAD-specific reinforcement learning target the model’s remaining difficulty with geometric accuracy and complex multi-step structures.After supervised fine-tuning, valid code generation remains limited on spatially complex cases.
4 Dataset Construction
The dataset pipeline converts Text2CAD descriptions and geometries into executable, geometrically filtered CadQuery programs, then adds manually refined chain-of-thought samples for reinforcement learning.
- Text2CAD’s 178K descriptions and geometries lacked executable CadQuery code, motivating an annotation pipeline based on structurally aligned CAD command sequences.
- A code-generation LLM produced multiple CadQuery candidates for each Text2CAD sample, which were filtered for executability and geometric accuracy.
- Samples were divided by CDgt into 70K medium-quality cases with CDgt < 1 × 10^-3, 32K low-quality hard cases with CDgt > 1 × 10^-3, and higher-quality cases with CDgt < 1 × 10^-4.
- The authors selected hard cases to generate CoT-formatted CadQuery code, retaining executable and geometrically accurate candidates before manual refinement.
- The final CoT dataset contains 1.5K high-quality CoT samples.
5 Experiments
Experiments evaluate executable correctness and geometric fidelity using CD, Invalidity Ratio, qualitative comparisons, and component ablations. The full method achieves the strongest reported performance, while high-quality SFT data improves subsequent results.
- Evaluation Setup: Mean CD measures average geometric discrepancy, Median CD captures typical error, and Invalidity Ratio measures the proportion of non-executable CadQuery programs.Together, these metrics assess both geometric fidelity and executable correctness.
- Evaluation Setup: The experiments compare the full SFT+CoT+GRPO method with Text2CAD and directly prompted open-source and proprietary LLMs.The evaluated baselines include Text2CAD, Qwen2.5 models, DeepSeek-V3, Claude-3.7-sonnet, and GPT-4o.
- Main Results: 6.54 Mean CD and 0.17 Median CD are achieved by the full method, with lower code invalidity and better target-shape alignment than prior methods.The reported results indicate improved geometric accuracy, structural validity, and executability.
- Ablation Study: 6.54 Mean CD and 0.17 Median CD are obtained by the full method, compared with 74.55 Mean CD and 0.33 Median CD for SFT alone.Without SFT, Mean CD is 76.20; GRPO without CoT reduces Mean CD to 17.34 and Median CD to 0.20.
- Ablation Study: More effective training strategies produce CD distributions skewed toward smaller values and fewer invalid results, while CD intervals distinguish substantial from near-identical geometric differences.CD > 1 × 10^-1 indicates substantial difference, whereas CD ≤ 1 × 10^-4 indicates near identity.
- Ablation Study: 8K high-quality SFT samples outperform 70K medium-quality samples, yielding 6.54 Mean CD and 0.17 Median CD versus 9.89 Mean CD for the larger dataset.The results identify data quality as more important than quantity for the SFT foundation.
6 Conclusion
The conclusion presents CAD-Coder as a text-to-CAD approach using CadQuery as an intermediate representation. It combines SFT, GRPO, CAD-specific rewards, and CoT reasoning with a geometrically verified dataset to generate complex CAD models from natural language.
- Conclusion: CAD-Coder leverages CadQuery as an intermediate representation for text-to-CAD generation.The approach combines Python-based code generation with CadQuery’s interpretability.
- Conclusion: The two-stage strategy combines SFT with GRPO and a CAD-specific reward to target syntactic correctness and geometric plausibility.CoT supports reasoning and planning during generation.
- Conclusion: The geometrically verified dataset supports research on generating complex CAD models from natural language.The conclusion identifies accessibility, efficiency, and flexibility as supported directions for CAD generation.
Overview of Supplementary Material
The supplementary material provides implementation details, reward-design analysis, generation examples, and additional supporting content for CAD-Coder.
- Section A: Section A covers hardware and software configurations, training durations, and the Chamfer Distance evaluation protocol.These details document the experimental setup and metric procedure.
- Section B: Section B shows that using only Chamfer Distance as the reward leads to training failure, motivating multi-faceted reward design.The supplement emphasizes the importance of combining geometry-based and code-related supervision.
- Section C: Section C provides a detailed CAD-generation example including prompts, CoT reasoning steps, and final CadQuery output.The example includes part decomposition, coordinate planning, sketch construction, and extrusion logic.
A Additional Implementation Details
Implementation details report the compute environment and evaluation normalization used for CAD-Coder experiments. Direct CD comparison with some prior systems is infeasible because their normalization procedures are undisclosed and reported values differ substantially.
- Implementation: Experiments use 8 NVIDIA A800 GPUs; SFT takes 7 hours and GRPO takes 146 hours with distributed training.DeepSpeed and Ray support training, while vLLM supports inference and CadQuery 2.3.1 executes and validates scripts.
- Evaluation Protocol: Chamfer Distance uses the same implementation as Text2CAD, including normalized generated meshes for consistent evaluation.This choice is intended to support fair and reproducible comparison.
- Evaluation Protocol: Direct CD comparison with CAD-Translator and CAD-LLaMA is infeasible because their normalization procedures are unclear and reported values differ by an order of magnitude.Their implementations are not open-sourced, limiting comparability of the published scores.
B Extended Ablation Studies
The ablation shows that using only Chamfer Distance during GRPO training leads to invalid code, reward-evaluation failures, and premature training termination, underscoring the need for code-aware reward shaping.
- After approximately 200 steps, training with only Chamfer Distance began producing invalid CadQuery code.
- Invalid syntax or structural inconsistencies prevented mesh generation, so the CD-based reward pipeline could no longer provide feedback.
- The resulting reward failures ultimately caused reinforcement learning to halt prematurely.
- The ablation highlights the importance of robust code supervision and reward shaping beyond pure geometry-based metrics.
C Step-by-Step CoT Reasoning in CAD Generation
CAD-Coder uses structured chain-of-thought reasoning before generating CadQuery scripts. The process decomposes parts, plans coordinates and sketches, organizes operations, and produces executable code for the target geometry.
- C Step-by-Step CoT Reasoning in CAD Generation: The model parses a prompt into part decomposition, coordinate planning, sketch construction, extrusion logic, and executable CadQuery scripts.
- Description Analysis: Description analysis identifies each component’s dimensions, rotations, translations, and spatial relationships before implementation.
- Coordinate System Planning: Coordinate-system planning maps Euler-angle rotations and translation vectors from local part coordinates to the global model.
- Sketch Construction Strategy: Sketch construction plans loops, lines, points, scaling factors, and transformations into 3D space.
- Extrusion Operation Planning: Extrusion planning specifies direction, distance, whether solids merge, and dimensional verification against the description.
- Code Implementation Strategy: Code implementation orders CadQuery operations, selects required functions, and applies scaling through explicit factors on coordinates and dimensions.
D Additional Qualitative Comparisons Across Methods
The supplementary comparison figure presents additional qualitative CAD outputs from different methods and uses placeholders when methods fail to produce valid 3D models.
- Figure S2 compares additional CAD models generated by different methods qualitatively.
- Methods that do not produce valid 3D models are represented with placeholders in their results.
E Performance on CAD Editing
Although CAD-Coder was trained for generation from scratch rather than editing, it performs simple instruction-based modifications. The results support possible extension toward interactive CAD editing, while challenging geometries remain problematic.
- Despite no explicit CAD-editing training, the model demonstrates promising generalization to simple instruction-based editing tasks.
- The model modifies dimensions, removes components, and adjusts translation or rotation parameters from natural-language prompts.
- These editing results suggest potential extension toward interactive or instruction-following CAD editing scenarios.
- Failure Cases: Complex multi-component structures can produce spatial dislocations or offsets because of inaccurate module alignment.
- Failure Cases: The model may misclassify extrusion and cutting operations, causing deviations from the intended design.
- Failure Cases: Very thin structures and internal cavities expose reward-hacking behavior under sparse point sampling and tight geometric tolerances.