HaVen: Hallucination-Mitigated LLM for Verilog Code Generation Aligned with HDL Engineers

Yiyao Yang, Fu Teng, Pengju Liu, Mengnan Qi, Chenyang Lv, Ji Li, Xuhong Zhang, Zhezhi He

Abstract

While Large Language Models (LLMs) have revolutionized software engineering, their application to Hardware Description Languages (HDLs) like Verilog remains hampered by significant "hallucinations." These errors often stem from a misalignment between symbolic hardware representations and the linear nature of text-based models. This paper introduces HaVen, a framework that mitigates these hallucinations through a Symbolic Interpretation based Chain-of-Thought (SI-CoT) strategy and high-quality, hardware-aligned datasets. HaVen demonstrates superior performance over state-of-the-art models, including GPT-4, particularly in complex symbolic and logical design tasks.

Introduction

Large Language Models have become remarkably proficient at writing software in languages like Python and C++. However, they frequently stumble when tasked with Verilog, the primary language for hardware design. This discrepancy arises from a "hallucination gap": models generate code that appears syntactically correct but fails to account for hardware-specific nuances such as timing, concurrency, and industry-standard design conventions.

HaVen addresses two primary hurdles in the field: Symbolic Misalignment, where models struggle to translate visual concepts like state diagrams into code, and Data Scarcity, caused by the lack of high-quality, descriptive natural language instructions in open-source Verilog repositories.

The Hallucination Taxonomy

To systematically address these failures, the authors categorized Verilog errors into three distinct types:

  1. Symbolic Hallucinations: Misinterpreting or ignoring symbolic inputs like truth tables or state transition diagrams.
  2. Knowledge Hallucinations: Violating standard HDL conventions or hardware-specific constraints.
  3. Logical Hallucinations: Failing to correctly implement the underlying boolean logic or state machine transitions requested by the user.

The HaVen Framework

HaVen employs a three-pronged approach to mitigate these hallucinations and align LLM output with the practices of professional HDL engineers.

Symbolic Interpretation based Chain-of-Thought (SI-CoT)

Standard LLMs often fail when jumping directly from a symbolic description to code. HaVen introduces SI-CoT, a specialized prompting mechanism that requires the model to first "describe" symbolic components—such as state transitions or truth table rules—in structured natural language. This intermediate step serves as a cognitive bridge, ensuring the model correctly interprets the logic before attempting to generate the final Register-Transfer Level (RTL) code.

Knowledge and Logical Dataset Generation

To overcome the noise of raw GitHub data, the researchers developed two specialized datasets:

  • K-dataset (Knowledge): Utilizing GPT-3.5, the team rewrote 550,000 "vanilla" code samples into high-quality instruction-code pairs. These were aligned with "exemplars" from hardware textbooks to ensure the model learned professional coding styles.
  • L-dataset (Logical): This dataset consists of synthetic logic problems, such as Karnaugh maps and complex boolean expressions, designed to train the model on rigorous logical reasoning and edge-case handling.

Automated Verification

To ensure data integrity, all generated training samples were passed through an industry-standard Verilog compiler. Only syntactically correct and logically sound code was included in the final fine-tuning set, known as the KL-Dataset.

Experimental Results

HaVen was evaluated using base models such as CodeLlama, DeepSeek-Coder, and CodeQwen across several benchmarks, including VerilogEval and RTLLM.

  • State-of-the-Art Performance: HaVen-DeepSeek (6.7B) achieved a pass@1 rate that outperformed the previous state-of-the-art model, OriGen, by 4.7% on the VerilogEval-Machine benchmark.
  • Surpassing GPT-4: In symbolic reasoning tasks involving truth tables and state diagrams, HaVen-CodeQwen achieved a 47.4% pass@1 rate, more than doubling the 22.7% achieved by GPT-4.
  • Human-Centric Alignment: On the VerilogEval-Human benchmark, which uses prompts designed to mimic real-world engineering requests, HaVen showed a 6.7% improvement in pass@1 over competing models.

Discussion and Future Work

The success of HaVen suggests that the bottleneck in HDL generation is not syntax, but the interpretation of symbolic logic. By aligning training data with textbook-style exemplars and utilizing SI-CoT, HaVen produces code that reflects the expertise of a professional engineer.

However, limitations remain. The KL-dataset, while high-quality, is relatively small at 19,000 pairs. Additionally, the reliance on closed-source models like GPT-3.5 for data augmentation may introduce subtle biases. Future research will focus on scaling these datasets and integrating hardware constraints such as power consumption and area optimization directly into the generation process.

Conclusion

HaVen represents a significant step forward in automated hardware design. By addressing the root causes of LLM hallucinations in Verilog, the framework provides a path toward AI assistants that can reliably support HDL engineers in complex RTL design tasks.

Summary updated

BibTeX
@inproceedings{yang2025haven,
  author = {Yiyao Yang and Fu Teng and Pengju Liu and Mengnan Qi and Chenyang Lv and Ji Li and Xuhong Zhang and Zhezhi He},
  title = {{HaVen: Hallucination-Mitigated LLM for Verilog Code Generation Aligned with HDL Engineers}},
  booktitle = {DATE},
  year = {2025},
  doi = {10.23919/date64628.2025.10993072},
}
Figure