Abstract: Large Language Models (LLMs) frequently struggle with complex software requirements due to the ambiguity of natural language and the implicit nature of data dependencies in standard UML sequence diagrams. This paper presents UML2Dep, a framework designed to improve automated code generation by explicitly inferring missing data dependencies. By utilizing enhanced UML diagrams, mathematical formalization, and reachability-based context pruning, UML2Dep achieves a 92.33% F1 score in dependency inference. Experimental results on industrial microservice datasets demonstrate significant improvements in both compilation and unit test pass rates for generated code.
1. Introduction
Unified Modeling Language (UML) sequence diagrams are the industry standard for software design, yet they possess a significant limitation: they primarily capture control flow while leaving data dependencies implicit. When LLMs attempt to generate code from these diagrams, they face a "dual cognitive load," forced to simultaneously reconstruct logic and guess data relationships. This often results in "hallucinations," where the model invents data sources or misses critical parameters, leading to code that fails in production environments.
2. The UML2Dep Framework
The authors propose UML2Dep to bridge the gap between high-level design and executable code. The framework treats Data Dependency Inference (DDI) as a standalone preprocessing step, decoupling the "thinking" about data from the "writing" of the code.
The framework consists of four primary stages:
- Enhanced UML Sequence Diagrams: Traditional UML syntax is extended by binding Decision Tables (to clarify business logic) and Refined API Specifications (detailing data types and constraints).
- Data Dependency Inference (DDI) Task: The LLM is tasked with building a directed Data Dependency Graph before code generation begins.
- Mathematical Formalization Prompting: Leveraging the reasoning capabilities of models like DeepSeek-R1, the DDI task is defined using formal mathematical sets and graph-theoretic constraints rather than ambiguous prose.
- Reachability-Based Context Pruning: To handle massive industrial diagrams, the system parses the design into an Execution Dependency Graph (EDG) and prunes logically unreachable nodes.
3. Context Pruning and Reachability
Industrial-scale diagrams often contain excessive "noise" that can overwhelm an LLM's context window. UML2Dep addresses this by identifying reachable predecessors for any given target node.
By converting the sequence diagram into an EDG, the framework can identify which function or control nodes are logically relevant to a specific target. Pruning irrelevant information reduces token consumption and prevents "noise amplification," allowing the model to focus on the correct data sources.
4. Experimental Evaluation
The framework was evaluated using an industrial dataset from WeChat Pay, comprising 11 complex microservice design diagrams and 224 ground-truth dependency relations approved by professional engineers.
Key Results:
- Inference Accuracy: The framework achieved 95.06% precision and 89.97% recall (92.33% F1 score) on the dependency inference task.
- Code Quality Improvements: Integrating inferred dependencies into the generation pipeline led to an 8.83% increase in compilation pass rates and an 11.66% increase in unit test pass rates.
- Model Performance: Reasoning-focused models like DeepSeek-R1 significantly outperformed standard models (like DeepSeek-V3) on complex diagrams with many branching paths.
5. Conclusion and Future Work
UML2Dep demonstrates that formalizing data dependencies and pruning irrelevant context significantly reduces LLM hallucinations in industrial settings. While the current requirement for "enhanced" diagrams involves manual effort, future work aims to automate the generation of these specifications from existing documentation and extend the DDI approach to other architectural diagrams, such as State Machine or Activity diagrams.
Summary updated