Source-linked AI summary

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

Mojdeh Rahmanian, Foutse Khomh, Ashkan Sami, Yanchao Yu

arXiv:2610.30946v1cs.SEcs.CL

TL;DR

LLM-generated UML diagrams can contain hallucinations, while evaluations focused on final diagrams provide limited insight into where they arise in reasoning. This paper develops and validates a taxonomy of reasoning-trace failures and evaluates taxonomy-guided mitigation; adding prompt constraints raised pooled mean Overall F1 by 4.0 pp across evaluated models.

  • Problem

    Final-diagram evaluations provide limited insight into where hallucinations arise across the requirements-to-reasoning-to-code process.

    Source: §1 · p. 2
  • Method

    The paper develops an empirical taxonomy of UML-generation hallucinations across Prompt Faithfulness, Reasoning Quality, and Code Faithfulness, then evaluates taxonomy-derived mitigation.

    Source: §1 · p. 3
  • Results

    4.0 pp increase in pooled mean Overall F1 followed prompt constraints, while post-hoc Code Faithfulness review provided no consistent benefit.

    Source: §8 · p. 31
  • Takeaways & Limitations

    Taxonomy-aware generation improved Overall F1 across all three evaluated models, connecting reasoning-trace failure analysis to a generation-time intervention.

    Source: §6 · p. 28

    Emitted reasoning traces may not faithfully or completely represent the model’s underlying computation.

    Source: §7 · p. 30

Abstract

from arXiv · show

Large Language Models (LLMs) can generate 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). 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 three Qwen3-based models, adding Prompt Faithfulness and Reasoning Quality constraints to the generation prompt raised the pooled mean F1 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.

1 Introduction

LLM-generated UML diagrams must faithfully represent requirements, but final-diagram evaluations reveal little about where hallucinations arise in the reasoning-to-code process. This paper develops a process-level taxonomy and examines its distribution, associations, and use in mitigation.

1 Introduction

  • Because UML generation transforms requirements through reasoning into structured code, errors can arise at multiple stages and propagate between them.A sound reasoning process can also be corrupted when translated into PlantUML.Source: §1 · p. 3
  • Existing UML evaluations largely assess final artefacts, leaving limited insight into hallucination origins and the failure modes targeted mitigation should address.The paper positions process-level characterisation as a first step toward understanding and improving reliability.Source: §1 · pp. 2–3
  • The taxonomy identifies eleven sub-types across Prompt Faithfulness, Reasoning Quality, and Code Faithfulness in the requirements-to-reasoning-to-code process.The dimensions distinguish requirement–reasoning deviations, unsound reasoning, and reasoning–PlantUML discrepancies.Source: §1 · pp. 3–4
  • Code Faithfulness was most frequent in both DeepSeek-R1 datasets, while hallucination distributions differed for DeepSeek-V4-Pro.The dimension-level ordering was consistent across the two DeepSeek-R1 annotation regimes.Source: §1 · p. 4
  • Reasoning-trace length showed no significant monotonic association with hallucination frequency, whereas requirement complexity was negatively associated with overall frequency and Prompt Faithfulness errors.The reported complexity association was observed in Dataset 1.Source: §1 · p. 4
  • Taxonomy-derived generation constraints improved mean diagram quality, while post-hoc Code Faithfulness review provided no consistent additional benefit.The study evaluates interventions across three reasoning-capable models.Source: §1 · p. 4

2 Background & Related Work

Prior work studies hallucinations in text, structured generation, and reasoning traces, while UML studies report structural errors mainly at the output level. The section situates the paper’s taxonomy and taxonomy-guided interventions against those gaps.

2.1 Hallucination in Large Language Models

  • NLG hallucination is framed as fluent output absent from source material or factually incorrect, while structured outputs may be syntactically valid yet semantically wrong.Prior work also examines whether reasoning traces are faithful to underlying computation and internally sound.Source: §2.1 · p. 5, §2.2 · p. 6

2.2 Taxonomies of LLM Errors and Hallucinations

  • Error taxonomies support systematic diagnosis and targeted interventions, and prior work examines both output errors and reasoning-trace failures.The authors state that, to their knowledge, no prior work systematically derives a UML-generation hallucination taxonomy from reasoning traces.Source: §2.2 · pp. 5–6

2.3 LLMs for UML and Software Modelling

  • UML-generation studies report unsupported, missing, or contradictory diagram elements, but primarily treat them as output-level phenomena rather than tracing their origins.Prior examples include degradation in completeness and correctness for ambiguous requirements and issues on complex exercises.Source: §2.3 · p. 7

2.4 Hallucination Mitigation

  • Mitigation includes training-time, inference-time, post-hoc, and prompt-based approaches, but UML prompting has largely lacked domain-specific error awareness.This motivates evaluating taxonomy-derived generation constraints and post-hoc verification rules.Source: §2.4 · pp. 7–8

3 Study Design

The study combines three complementary datasets with manual taxonomy construction, automated validation, and analyses of hallucination frequency against trace length and requirement complexity. A separate gold-standard dataset supports the mitigation experiment.

3 Study Design

  • Three datasets serve complementary purposes: 20 Bari exercises for taxonomy construction and distribution analysis, 120 Bozyigit descriptions for validation, and 13 Golden UML ModelSet cases for mitigation.The selected ModelSet cases span 13 domains and have verified PlantUML gold-standard solutions.Source: §3 · p. 8

3.1 RQ1: Taxonomy Construction

  • For taxonomy construction, DeepSeek-R1 generated 60 paired reasoning traces and PlantUML diagrams from 20 exercises at three temperature settings.Two authors open-coded 20 traces, then one author and a master's student independently annotated the remaining 40 and resolved disagreements by discussion.Source: §3.1 · pp. 9–10

3.2 RQ2 & RQ3: Taxonomy Validation and Predictor Analysis

  • A Claude annotator and GPT-4o judge applied the taxonomy to 120 independent descriptions; one author compared pipeline outputs with human annotations on 30 traces using pairwise F1.The analyses related hallucination counts to trace length and a complexity score combining sentence count, total words, unique words, and non-stop words.Source: §3.2 · pp. 10–11

4 Results

The results define an 11-subtype taxonomy across three stages of UML diagram generation and show that hallucination patterns vary across datasets and models. In manual annotations, trace length was not significantly associated with error frequency, while requirement complexity was negatively associated with overall errors and Prompt Faithfulness errors.

4 Results

  • The taxonomy was developed from 60 traces through joint open coding of 20 traces and independent application to 40 more; overall pre-consensus micro-F1 was 81.79%.Pre-consensus consistency was lower for Reasoning Quality (61.90%) than for Prompt Faithfulness (79.78%) or Code Faithfulness (94.04%).Source: §4.1 · pp. 11–12

4.2 Hallucination Taxonomy

  • The taxonomy maps 11 subtypes onto prompt-to-reasoning, reasoning-to-code, and within-chain failures: Prompt Faithfulness, Code Faithfulness, and Reasoning Quality.Its subtypes are Unsupported Entity, Unsupported Relation, Over-specific Detail, Missed Requirement; Dropped Step, Fabricated Code, Contradiction, Structural Mismatch; and Speculative Branch, Goal Drift, Tool Misuse.Source: §4.1 · pp. 11–12, Figure 1 · p. 12

4.2.1 Dimension A: Prompt Faithfulness (Prompt →Reasoning)

  • Prompt Faithfulness covers reasoning-chain content introduced or omitted relative to requirements, with committed elements requiring explicit prompt support.Its subtypes distinguish unsupported entities or relations, over-specific details, and missed requirements.Source: §4.2.1 · pp. 13–14

4.2.2 Dimension B: Code Faithfulness (Reasoning →PlantUML)

  • Code Faithfulness captures discrepancies between the reasoning plan and PlantUML, including dropped, fabricated, contradicted, or structurally changed elements.The evaluation compares parsed fact sets of entities, attributes, operations, and relations.Source: §4.2.2 · pp. 16–17

4.2.3 Dimension C: Reasoning Quality (Within-Chain Soundness)

  • Reasoning Quality assesses the soundness of the reasoning chain itself, including unsupported speculation, goal drift, and misuse of UML or PlantUML constructs.A proposed construct can count as Tool Misuse even if the final code omits it.Source: §4.2.3 · pp. 17–20

4.3 RQ2: Hallucination Distribution

  • Code Faithfulness led DeepSeek-R1 in both datasets (48.2% manually; 41.7% automated), while Prompt Faithfulness led DeepSeek-V4-Pro (56.7%).Over-specific Detail led Prompt Faithfulness across the DeepSeek-R1 datasets; Tool Misuse led Reasoning Quality manually, while Speculative Branch led it under automated annotation.Source: §4.3 · pp. 20, 22, Figure 12 · p. 21, Figure 13 · p. 21

4.4 RQ3: Reasoning Length and Requirement Complexity

  • Reasoning-trace length had no significant monotonic association with overall hallucination frequency (ρ = −0.011, p = 0.934) or any individual dimension.Quartile means suggested an inverted-U pattern, but the authors treat it as descriptive rather than statistically established.Source: Figure 15 · p. 23, §4.4 · p. 23
  • Requirement complexity was negatively associated with overall hallucination frequency (ρ = −0.325, p = 0.011) and Prompt Faithfulness errors (ρ = −0.375, p = 0.003).Associations with Reasoning Quality and Code Faithfulness were not statistically significant, and the analysis does not establish causality.Source: §4.4 · p. 23

5 Taxonomy-Guided Mitigation Experiment

The experiment tested taxonomy-derived generation constraints and a post-hoc Code Faithfulness review across three models. Taxonomy-Aware Generation improved pooled Overall F1, while the additional review showed no consistent further benefit.

5 Taxonomy-Guided Mitigation Experiment

  • Taxonomy-Aware Generation constrained Prompt Faithfulness and Reasoning Quality, while the added review checked Code Faithfulness in the reasoning trace and PlantUML code.Generation constraints included textual support for entities, classes, and multiplicities; the review checked for dropped steps, fabricated code, contradictions, and structural mismatches.Source: §5 · p. 24
  • The evaluation averaged F1 across classes, attributes, and relationships, combining correctness and completeness for diagrams compared with gold-standard solutions.The experiment evaluated three models across 13 Golden UML ModelSet cases.Source: §5 · pp. 24–25
  • Taxonomy-Aware Generation raised pooled Overall F1 by +4.0 pp (W = 90, p < 0.001), with gains for all three evaluated models.Model-specific gains were +5.2 pp for DeepSeek-R1-Qwen3-8B, +4.3 pp for Qwen3-32B, and +2.6 pp for Qwen3-8B.Source: §5 · pp. 25–26
  • Adding the Code Faithfulness review lowered Overall F1 by 1.0 pp for DeepSeek-R1-Qwen3-8B and 1.3 pp for Qwen3-32B, but raised it by 0.8 pp for Qwen3-8B.The pooled improvement relative to Baseline was +3.5 pp (p < 0.001); after Bonferroni correction, only three of six per-model comparisons against Baseline remained significant.Source: §5 · p. 26
  • Relationship F1 was the lowest of the three metrics across all models and conditions, ranging from 67.5% to 86.2%.The endpoints were 67.5% for DeepSeek-R1-Qwen3-8B under Baseline and 86.2% for Qwen3-32B under Taxonomy-Aware Generation.Source: §5 · p. 26

6 Discussion

The discussion reports model-dependent hallucination patterns, mixed associations with trace and requirement characteristics, and improved diagram quality from taxonomy-aware generation. Relationship modelling remained difficult, while prompt echoing was identified as a potential diagnostic cue.

6 Discussion

  • Code Faithfulness led DeepSeek-R1 hallucinations in both datasets (48.2%, 41.7%), while Prompt Faithfulness (56.7%) and Reasoning Quality (37.5%) led for DeepSeek-V4-Pro.The cross-model analysis used 20 DeepSeek-V4-Pro traces, so its transferability evidence is preliminary.Source: §6 · pp. 26–27
  • In Dataset 1, reasoning-trace length had no significant monotonic association with hallucination frequency, whereas requirement complexity was negatively associated with overall frequency and Prompt Faithfulness errors.The proposed explanation that complex requirements may constrain unsupported inference is speculative; the complexity measure does not independently capture clarity or specificity.Source: §6 · p. 27
  • Whether the observed associations hold across other datasets and models requires further investigation.The trace-length and requirement-complexity analysis was restricted to Dataset 1.Source: §6 · pp. 27–28
  • Taxonomy-Aware Generation improved Overall F1 across all three evaluated models, while adding the Code Faithfulness review provided no consistent further benefit.Because the interventions differed in both timing and targeted taxonomy dimension, the results do not establish that generation-time constraints are generally more effective than post-hoc verification.Source: §6 · p. 28
  • Relationship F1 remained the lowest-scoring metric, and implicit relationship properties or information spread across requirements were proposed as untested explanations.Suggested future directions include few-shot relationship examples, explicit relationship inventories, and multiplicity verification.Source: §6 · p. 28
  • In a project trace, echoing “produces” preceded unsupported composition; sliding-window matching could flag echo-then-commit transitions for review.The verb supports a general association but not the lifecycle dependency implied by composition.Source: §6 · p. 29, Figure 16 · p. 29
  • Practitioners may benefit from checking generated relationships and multiplicities against requirements and using modelling-specific mechanisms to ground structural decisions.Relationship F1 was the lowest structural metric across all evaluated models and conditions.Source: §6 · pp. 29–30

7 Threats to Validity

The study’s validity is constrained by trace interpretation and annotation uncertainty, the educational character and small size of its datasets, and limits in taxonomy coverage and statistical power.

Internal Validity

  • Reasoning traces may not faithfully represent underlying computation, so the identified patterns describe observable discrepancies rather than definitive internal decision-making.Manual category boundaries and borderline classifications may also reflect researcher interpretation; Reasoning Quality had lower pre-consensus agreement.Source: §7 · p. 30

External Validity

  • The datasets and 13-case mitigation benchmark are rooted mainly in educational or domain-modelling tasks, limiting evidence about industrial requirements and broader modelling tasks.The benchmark covers 13 domains, but its educational context and small per-condition sample constrain generalisation.Source: §7 · p. 30
  • The taxonomy was developed on DeepSeek-R1 and examined on only 20 DeepSeek-V4-Pro traces; mitigation used three Qwen-based models, leaving transfer to other architectures and non-reasoning LLMs uncertain.Source: §7 · p. 30

Construct Validity

  • The taxonomy omits diagram-quality aspects such as layout and readability, while the dual-LLM pipeline may retain shared biases or classification errors despite using different providers.Reasoning Quality also had the lowest pre-consensus pairwise F1, indicating greater annotation uncertainty.Source: §7 · p. 30

Conclusion Validity

  • Only 13 paired cases per model limited mitigation-test power, some gains lost significance after Bonferroni correction, and correlations from 60 traces cannot establish causality or reliably detect small associations.The authors call for confirmation with larger, more diverse samples.Source: §7 · p. 31

8 Conclusion

The paper characterises hallucinations across the requirements-to-reasoning-to-code process and evaluates taxonomy-guided mitigation. Code Faithfulness was most frequent in both DeepSeek-R1 datasets, but prompt constraints raised pooled mean Overall F1 by 4.0 pp, while relationship modelling remained a persistent challenge.

8 Conclusion

  • Adding Prompt Faithfulness and Reasoning Quality constraints to generation prompts raised pooled mean Overall F1 by 4.0 pp, while post-hoc Code Faithfulness review gave no consistent benefit.Source: §8 · p. 31
  • Code Faithfulness was the most frequent failure dimension in both DeepSeek-R1 datasets, but hallucination distributions varied across models.Source: §8 · p. 31
  • Reasoning-trace length had no significant association with hallucination frequency, whereas requirement complexity was negatively associated with overall hallucinations and Prompt Faithfulness errors.Source: §8 · p. 31
  • Relationship modelling remained the lowest-scoring element across models and conditions; future work targets relationship-specific mitigation, broader UML types, industrial datasets, and human validation.The paper also proposes investigating prompt echoing as a possible runtime signal for unsupported structural commitments.Source: §8 · p. 31
  • The paper argues that examining hallucinations along the generation process offers a foundation for more reliable and controllable LLM-based engineering tools.Source: §8 · p. 31
Loading 2610.30946v1…