Manuscript Offprint

arXiv:2610.30946

Tracing Hallucinations in LLM Reasoning for UML Class Diagram Generation: An Empirical Taxonomy and Mitigation Study

Mojdeh Rahmanian, Foutse Khomh, Ashkan Sami, Yanchao Yu

Abstract

Large Language Models (LLMs) can generate Unified Modeling Language (UML) class diagrams from natural-language requirements, but hallucinations may compromise the correctness and completeness of the resulting diagrams. Existing evaluations mostly assess the final diagram, without examining the intermediate traces of reasoning-capable LLMs, which can reveal where these hallucinations arise. We develop an empirical taxonomy of eleven hallucination sub-types organised into three dimensions: Prompt Faithfulness (deviations between requirements and reasoning), Code Faithfulness (discrepancies between reasoning and generated PlantUML code), and Reasoning Quality (problems within the reasoning itself). The taxonomy was derived from 60 manually annotated DeepSeek-R1 traces, applied to 120 further DeepSeek-R1 traces through a dual-LLM annotation pipeline, and examined on 20 DeepSeek-V4-Pro traces. Code Faithfulness was the most frequent dimension for DeepSeek-R1 in both datasets, whereas Prompt Faithfulness dominated for DeepSeek-V4-Pro, suggesting model-dependent failure patterns. In the manually annotated traces, reasoning-trace length showed no significant monotonic association with hallucination frequency, whereas requirement complexity was negatively associated with it, particularly for Prompt Faithfulness errors. In a mitigation experiment on 13 Golden UML ModelSet cases with

Mojdeh Rahmanian

Edinburgh Napier University, Edinburgh, Scotland

E-mail: m.rahmanian@napier.ac.uk

Foutse Khomh

Polytechnique Montréal, Montréal, QC, Canada

E-mail: foutse.khomh@polymtl.ca

Ashkan Sami

Edinburgh Napier University, Edinburgh, Scotland

E-mail: a.sami@napier.ac.uk

Yanchao Yu

Edinburgh Napier University, Edinburgh, Scotland

E-mail: Y.Yu@napier.ac.uk

Mojdeh Rahmanian et al.

three Qwen3-based models, adding Prompt Faithfulness and Reasoning Quality constraints to the generation prompt raised the pooled mean F1F_{1} score by 4.0 percentage points, whereas a post-hoc Code Faithfulness review provided no consistent further benefit. Relationship modelling remained the lowest-scoring element throughout. These results suggest that localising hallucinations within the generation process can inform targeted, prompt-based mitigation. Whether these findings generalise beyond the DeepSeek and Qwen3 model families remains to be tested.

Keywords Hallucination · Large language models · UML class diagrams · Reasoning traces · Empirical software engineering · Taxonomy

1 Introduction

Large language models (LLMs) have rapidly become capable tools for automating a wide range of software engineering activities, including requirements analysis, code generation, and software design Li et al. (2022); Ataei et al. (2025); Fan et al. (2023); Hou et al. (2024). A particularly promising application is the generation of Unified Modeling Language (UML) class diagrams from natural-language requirements Bari et al. (2024); Cámara et al. (2023). Such generation addresses a fundamental challenge in software engineering: translating informal, often incomplete textual requirements into explicit structural representations that can guide subsequent design and implementation. Reliable automation at this stage could accelerate early design activities, strengthen requirements traceability, and support both professional modeling and software engineering education.

The usefulness of such automation, however, depends not only on whether an LLM can produce a syntactically valid diagram, but on whether the diagram faithfully represents the requirements. Existing studies show that LLM-generated UML models can contain hallucinated classes, attributes, operations, or relationships that are unsupported by, inconsistent with, or absent from the requirements Ji et al. (2023); Huang et al. (2025). Recent empirical evaluations show that while LLM outputs are often syntactically valid and understandable, they suffer from significant issues related to completeness and correctness, particularly when requirements are ambiguous or complex Bari et al. (2024); Ferrari et al. (2024); Cámara et al. (2023). This is particularly problematic for software models because structural errors can be deceptively plausible: a fabricated class, an unsupported association, or an incorrect multiplicity may pass superficial inspection while nevertheless influencing downstream design decisions, code generation, consistency checking, and design review. Understanding and preventing these errors is therefore essential if LLM-based modeling is to move from demonstration to dependable software engineering practice.

Hallucination in UML generation also differs fundamentally from hallucination in conventional text generation. Research has extensively studied hallucinations in tasks such as summarisation Maynez et al. (2020), machine translation Raunak et al. (2021), and code synthesis Zhang et al. (2025b). In these settings, hallucination is commonly framed as a mismatch between generated content and a reference source or specification. UML generation introduces an additional challenge: the output is a structured artefact whose correctness depends on multiple transformations between the input requirements, the model's internal reasoning, and the representation used to encode the diagram. Errors may therefore arise not only in the final artefact but at each of these transformations, and may propagate from one to the next.

This process-level view is particularly relevant for reasoning-capable LLMs. Rather than mapping requirements directly to a diagram, these models often generate explicit reasoning traces in which they identify candidate entities, infer attributes and operations, establish relationships, determine multiplicities, and finally translate these decisions into diagram code. This process creates several distinct failure points: an error introduced when interpreting the requirements can propagate through subsequent reasoning; individually plausible reasoning steps can collectively produce an unsound model; and a sound reasoning process can be corrupted during translation into PlantUML. Yet existing evaluations of LLM-generated UML diagrams largely focus on the quality of the final artefact, providing limited insight into where in the reasoning-to-diagram process hallucinations arise, how they propagate, and which failure modes are most prevalent. This lack of process-level understanding limits our ability to design targeted mitigation strategies. For example, although prompt engineering Freeman et al. (2026); Zhang et al. (2025a), retrieval-augmented generation Lewis et al. (2020); Shuster et al. (2021), and post-hoc verification Dhuliawala et al. (2024); Manakul et al. (2023) may address different failure mechanisms, their effectiveness depends on knowing which mechanisms actually drive UML generation errors. A systematic characterisation of these failure modes is therefore a necessary first step toward both understanding and improving the reliability of LLM-generated UML models.

In this paper, we address this gap by constructing and validating an empirical taxonomy of hallucinations in reasoning-capable LLMs generating UML class diagrams, and by demonstrating how the taxonomy can be translated into actionable mitigation strategies. The taxonomy identifies three dimensions corresponding to the generation process: Prompt Faithfulness, capturing deviations between the requirements and the model's reasoning; Reasoning Quality, capturing unsoundness within the reasoning chain; and Code Faithfulness, capturing discrepancies between the reasoning and the resulting PlantUML representation. Across these dimensions, we identify eleven hallucination sub-types. We construct the taxonomy through manual analysis of reasoning traces, examine its distribution and generalisability using an independent dataset and a dual-LLM annotation pipeline, investigate the relationship between hallucination frequency and input and reasoning characteristics, and operationalise the taxonomy as generation-time constraints and post-hoc verification mechanisms across multiple reasoning-capable models.

To structure our investigation, we address four research questions:

Mojdeh Rahmanian et al.

RQ1. What categories of hallucinations arise during the reasoning traces of LLMs generating UML class diagrams, and how can they be organised into a taxonomy? We identify three dimensions, namely Prompt Faithfulness, Code Faithfulness, and Reasoning Quality, with eleven sub-types corresponding to distinct failure modes in the requirements-to-reasoning-to-code pipeline.

RQ2. How are hallucinations distributed across the taxonomy categories, and is the distribution stable when the taxonomy is applied to an independent dataset through automated annotation? Code Faithfulness is the most frequent dimension in both DeepSeek-R1 datasets, and the dimension-level ordering is consistent across annotation regimes.

RQ3. How are hallucination frequencies related to the length of the model's reasoning trace and the complexity of the input requirements? Reasoning-trace length shows no significant monotonic association with hallucination frequency, while requirement complexity is negatively associated with overall hallucination frequency and Prompt Faithfulness errors.

RQ4. To what extent can embedding taxonomy-derived rules into the generation and verification pipeline improve the quality of LLM-generated UML class diagrams? Taxonomy-derived constraints embedded in the generation prompt improve mean diagram quality across all evaluated models, while an additional post-hoc Code Faithfulness review provides no consistent additional benefit.

The paper makes four contributions:

  1. An evidence-based, empirical taxonomy of hallucination types in UML class-diagram generation, organised along three dimensions that reflect the multi-stage reasoning process.

  2. A dual-LLM evaluation pipeline for automated hallucination detection and verification at scale, without requiring human ground-truth annotations for each evaluated trace, with its consistency assessed against human annotations on a sample of traces.

  3. A quantitative analysis of hallucination distributions and their relationships with reasoning-trace length and requirement complexity.

  4. An empirical evaluation of a taxonomy-guided generation and verification pipeline across three reasoning-capable models, showing improvements in mean diagram quality from taxonomy-aware generation, while finding no consistent additional benefit from post-hoc Code Faithfulness review.

The remainder of this paper is organised as follows. Section 2 reviews related work on hallucination and LLMs in software engineering. Section 3 presents the study design for RQ1–RQ3, including the datasets, annotation procedures, and analyses. Section 4 reports the results for RQ1–RQ3; it first presents the hallucination taxonomy and its definitions with illustrative examples (Section 4.2), and then reports the distribution of hallucinations and their associations with reasoning length and requirement complexity. Section 5 describes the design and results of the taxonomy-guided mitigation experiment.

addressing RQ4. Section 6 synthesises the findings and discusses their practical implications. Finally, Sections 7 and 8 discuss threats to validity and conclude the paper.

References (37)