Building Legal LLMs: From General-Purpose Foundation Models to Professional Legal Assistants

    This article explains why general-purpose large language models struggle with legal work, and walks through the typical three-stage path for building a legal-domain LLM: foundation model selection, mid-training with domain data, and post-training alignment. It also covers evaluation design, key application scenarios such as contract review, evidence analysis, and compliance planning, along with practical engineering recommendations for teams deploying legal AI solutions.

    Legal work places demands on AI systems that differ significantly from everyday general-purpose tasks, mainly in three ways.

    First, the knowledge domain is closed and time-sensitive. Legal knowledge consists of statutes, judicial interpretations, administrative regulations, local rules, and a large volume of case precedents, with a clear hierarchical structure and strict boundaries of legal effect. General-purpose LLMs are trained on open internet corpora that mix outdated regulations, social media commentary, and inaccurate explainers. As a result, models may confidently cite repealed provisions or confuse relationships between rules at different levels of authority.

    Second, the reasoning chain is composite. A typical legal task requires completing multiple sub-steps at once: identifying case facts, locating applicable provisions, comparing evidence chains, assessing likely judicial outcomes, forming a conclusion, and flagging risks. If any intermediate step fails, the final conclusion collapses. General models tend to jump straight to an answer without a verifiable reasoning process — a fatal flaw in legal scenarios.

    Third, evaluation is multi-dimensional. Legal tasks are judged not only on whether the answer is correct, but also on whether citations are accurate, whether the logic is self-consistent, and whether the conclusion covers all disputed points. A single accuracy metric cannot reflect real capability, which calls for stricter composite evaluation standards such as “all tasks passed.”

    Following common industry practice, building a usable legal LLM typically involves three steps: foundation model selection, mid-training, and post-training alignment.

    1. Foundation Model Selection: Balancing Lightweight Design and Reasoning Ability

    Legal deployment usually relies on private, on-premise hosting and cost-controlled inference services. The foundation model therefore does not need to be the largest available; it must balance reasoning capability, context length, and deployment cost. Contract review often requires ingesting documents of tens of thousands — even hundreds of thousands — of characters, so long-context capability is a hard requirement. Meanwhile, daily query volumes at law firms and in-house legal teams are relatively limited, so a lightweight foundation model often offers better engineering cost-effectiveness.

    2. Mid-Training: The Right Way to Inject Domain Knowledge

    The core task of the mid-training (continued pre-training) stage is to feed the model high-quality legal corpora, including:

    • Normative texts: Full texts and revised versions of statutes, administrative regulations, and judicial interpretations, annotated with effective dates and validity status;
    • Practice documents: Real-world documents such as judgments, rulings, contract templates, attorney letters, and compliance memoranda;
    • Q&A and reasoning data: Legal consultation Q&A and case analyses reviewed by practicing professionals, with emphasis on complete reasoning processes.

    At this stage, data mixing ratios must be carefully controlled to prevent the model from acquiring domain knowledge while losing its general language understanding and instruction-following abilities. The usual approach is to blend general-purpose corpora into the domain data at a fixed ratio during mixed training.

    3. Post-Training: Aligning with Real Workflows via Reinforcement Learning

    Mid-training addresses “what the model knows”; post-training addresses “how it works.” Post-training for legal tasks typically consists of supervised fine-tuning (SFT) and reinforcement learning based on verifiable signals:

    • In the SFT stage, model answers written by senior legal professionals teach the model to produce structured analytical reports;
    • In the reinforcement learning stage, verifiable rules — such as “are citations real,” “does the conclusion hold,” and “are any risks missed” — serve as reward signals, driving the model from “answering like a lawyer” to “producing reasoning that a lawyer would accept.”

    Evaluation: Worth More Investment Than Training Itself

    Validating a legal model requires a multi-dimensional evaluation matrix. Common industry practice covers:

    1. End-to-end task sets: Simulated real practice scenarios — for example, given a contract, find all risky clauses and propose revisions. Evaluation uses strict standards such as “full task pass rate”: failing any single sub-requirement fails the entire task;
    2. Knowledge benchmarks: Basic capabilities such as citation accuracy, understanding of statutory meaning, and judgment of legal effect hierarchy;
    3. Double-blind human review: Practicing lawyers professionally score model outputs without knowing their source.

    A common pitfall is optimizing only for knowledge benchmark scores, producing a model that “memorizes statutes well but handles cases poorly.” A sound evaluation design should treat end-to-end task performance as the final validation, with knowledge metrics serving only as intermediate diagnostics.

    Typical Application Scenarios and Engineering Practices

    1. Contract Review

    Contract review is usually the first scenario where legal models scale. A typical system architecture works as follows: a document parsing layer converts Word/PDF files into structured text; the model layer identifies risk points clause by clause (such as unbalanced liability terms, missing penalty clauses, or unfavorable dispute resolution clauses); and an output layer writes revision suggestions back into the original document as tracked changes and comments, letting legal professionals complete the review loop in familiar office software. This “assist, don’t replace” design improves efficiency while keeping humans in control of final decisions.

    2. Evidence Analysis

    Evidence analysis requires the model to organize large volumes of unstructured materials (chat logs, emails, receipts) into facts, outputting timelines and evidence relationship maps. In practice, teams typically adopt a “retrieval-augmented, chunked reasoning” strategy: split materials by fact dimension, extract key information chunk by chunk, then aggregate everything into a complete fact-finding report, avoiding omissions caused by reasoning directly over long documents.

    3. Compliance Planning

    Compliance scenarios emphasize continuous monitoring of business operations, with the model producing remediation suggestions in light of the latest regulatory changes. Deployment usually pairs the model with a regularly updated regulatory database and retrieval pipeline, ensuring that cited rules are always current and in force.

    Recommendations for Technical Teams

    • Build evaluation first, then talk about models: Without a reliable evaluation set, any training or tuning is blind experimentation;
    • Prioritize private deployment and security: Legal documents are highly sensitive; the deployment plan must support intranet environments and keep data on-premise;
    • Embed into workflows rather than standalone Q&A: Model capabilities create real business value only when connected to existing tools such as document editors and approval systems;
    • Keep a human review step: AI output should be positioned as an assistive draft for professionals, not the final conclusion.

    Overall, the value of legal LLMs lies not in “replacing lawyers” but in freeing legal professionals from repetitive first-pass screening work. For development teams, mastering the engineering path of “lightweight foundation model + domain mid-training + reinforcement learning alignment + rigorous evaluation” is a general methodology for building vertical-domain models — one that transfers equally well to other knowledge-intensive industries such as healthcare and finance.