LawGPT: Knowledge-Guided Data Generation and Its Application to Legal LLM

Zhi Zhou, Kun-Yang Yu, Shi-Yu Tian, Xiao-Wen Yang, Jiang-Xin Shi, Peng-Xiao Song, Yi-Xuan Jin, Lan-Zhe Guo, Yu-Feng LiarXiv 2025

Abstract

Large language models (LLMs), both proprietary and open-source, have demonstrated remarkable capabilities across various natural language processing tasks. However, they face significant limitations in legal reasoning tasks. Proprietary models introduce data privacy risks and high inference costs, while open-source models underperform due to insufficient legal domain training data. To address these limitations, we study data generation for legal reasoning to improve the legal reasoning performance of open-source LLMs with the help of proprietary LLMs. This is challenging due to the lack of legal knowledge in proprietary LLMs and the difficulty in verifying the generated data. We propose KgDG, a knowledge-guided data generation framework for legal reasoning. Our framework enables leveraging legal knowledge to enhance generation diversity and introduces a refinement and verification process to ensure the quality of generated data. Moreover, we expand the generated dataset to further enhance the LLM reasoning capabilities. Using KgDG, we create a synthetic legal reasoning dataset containing 50K high-quality examples. Our trained model LawGPT outperforms existing legal-specific LLMs and achieves performance comparable to proprietary LLMs, demonstrating the effectiveness of KgDG and LawGPT.

Introduction

While general-purpose LLMs like GPT-4 show promise in legal reasoning, they present two major hurdles for the legal industry: data privacy risks associated with sending sensitive case information to external APIs and high inference costs. Open-source alternatives exist, but they typically underperform because they lack high-quality, domain-specific training data.

Generating synthetic legal data is significantly more complex than generating data for domains like mathematics. In law, reasoning is informal, nuanced, and requires strict adherence to specific statutes. If a model "hallucinates" a law during the data generation phase, the resulting training data becomes toxic. LawGPT introduces a novel framework called Knowledge-Guided Data Generation (KgDG) to bridge this gap, grounding synthetic data generation in a massive database of real-world legal documents and implementing a rigorous "fix-and-verify" pipeline.

Methodology: The KgDG Framework

The core of this research is the KgDG framework, which ensures that synthetic data is diverse, high-quality, and verifiable without relying solely on the internal knowledge of a teacher LLM. The framework consists of four main stages:

  1. KGGEN (Knowledge-Guide Generation): Instead of asking an LLM to brainstorm legal problems, the system uses a Knowledge-Aware Sampler to select real legal documents (criminal and civil). A Knowledge-Guided Writer then extracts core information and generates Q&A pairs grounded in those specific documents.
  2. KGFIX (Knowledge-Guide Fixer): This module acts as an automated editor. The Reference Modifier ensures legal citations are accurate against the knowledge base, while the Reasoning Corrector fixes logical or computational errors in the reasoning path.
  3. DAVER (Data Verifier): A final filter checks if the generated answer can be logically derived from the question using the provided legal references. Data that fails this check is discarded.
  4. MITRA (Mixture Training): To ensure versatility, the model is trained on a mix of "Standard" (Direct Answer) and "Reasoning Path" (Chain-of-Thought) examples, allowing it to provide either quick answers or step-by-step legal justifications.
Overview of the Knowledge-Guided Data Generation (KgDG) framework, featuring the generation, fixing, and verification modules.

Experimental Setup and Datasets

The framework was built using a source knowledge base of 186,197 criminal and 152,452 civil legal documents. Using KgDG, the authors generated 25,000 verified legal problems, which were expanded via Mixture Training into a final dataset of 50,000 high-quality training examples.

Evaluation was conducted on LawBench, covering four critical tasks: Scene-based Article Prediction, Prison Term Prediction (with and without articles), and Criminal Damages Calculation.

Results and Key Insights

LawGPT-3B (based on Qwen-2.5) demonstrated that data quality and grounding can trump raw parameter count. Despite its smaller size, it outperformed specialized 7B and 33B legal models and achieved performance comparable to proprietary giants. On the average score across four tasks, LawGPT-3B (71.8) outperformed GPT-4 (67.4) and GPT-3.5 Turbo (62.0).

Performance scaling of LawGPT across four legal reasoning tasks as training data volume increases from 8K to 50K examples.

Key insights from the study include:

  • Grounding vs. Brainstorming: LLMs are more effective at transforming existing legal knowledge into new scenarios than at recalling laws from memory. Grounding the generator in real documents significantly reduces hallucination rates.
  • The Necessity of Repair: Ablation studies showed that the KGFIX module provided a consistent performance boost. Actively repairing "almost-correct" data is more effective for maintaining volume and quality than simply filtering out bad data.
  • Scalability: Performance showed a clear linear-like improvement as the volume of synthetic data increased from 8K to 50K examples, suggesting that further scaling could yield even stronger results.

Conclusion and Future Work

LawGPT demonstrates that small, open-source models can achieve state-of-the-art legal reasoning performance when trained on high-quality, knowledge-guided synthetic data. While the current study focused on models under 3B parameters, future work will explore applying this framework to larger models (7B or 14B) and refining the Data Verifier (DAVER) to handle more intricate reasoning paths in complex prison term prediction tasks.

Summary updated

BibTeX
@misc{zhou2025lawgpt,
  author = {Zhi Zhou and Kun-Yang Yu and Shi-Yu Tian and Xiao-Wen Yang and Jiang-Xin Shi and Peng-Xiao Song and Yi-Xuan Jin and Lan-Zhe Guo and Yu-Feng Li},
  title = {{LawGPT: Knowledge-Guided Data Generation and Its Application to Legal LLM}},
  year = {2025},
  eprint = {2502.06572},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.06572},
}
Figure