Building Vertical LLMs for Legal Use Cases: A Practical Technical Guide
This article outlines a practical approach to building vertical large language models for legal scenarios. It explains why general-purpose models struggle with legal text, then walks through the three-stage technical pipeline: domain-adaptive pretraining, supervised fine-tuning, and reinforcement learning from human feedback. It also covers how to correctly interpret legal benchmark metrics, how to integrate models into real workflows such as contract review, evidence analysis, and compliance planning, and which baseline controls to apply in private deployments. The key takeaway is that reliability comes from task decomposition, traceable citations, and understanding metric limits—not from replacing legal judgment.
1. Why Legal Scenarios Need Vertical LLMs
General-purpose LLMs often behave in a deceptively problematic way in legal settings: the language is fluent, but the conclusions are unstable. Three characteristics of legal text explain this gap:
- High terminology density with a long-tail distribution. Fixed expressions in statutes, judicial interpretations, and contract clauses must be reproduced precisely.
- Long reasoning chains. A single conclusion typically requires linking fact-finding, norm retrieval, and rule application.
- Low error tolerance. One imprecise phrase in the output can alter rights and obligations.
For these reasons, the industry commonly follows a three-stage route: a lightweight base model + domain intermediate training + post-training alignment.
The main reason for choosing a lightweight base is inference cost and deployment flexibility. Legal workflows are mostly high-frequency, long-document, interactive tasks. A model with moderate parameter count but sufficient domain adaptation usually delivers better throughput per unit cost than a much larger general-purpose model.
2. Three Technical Stages of Capability Building
2.1 Domain-Adaptive Pretraining (DAPT)
The goal is to shift general language capability toward the legal corpus distribution. Engineering work usually focuses on three points:
- Corpus mixing ratio: Blend legal and general text in a controlled proportion to avoid catastrophic forgetting that degrades general understanding.
- Long-context adaptation: Contracts and case files can easily reach tens of thousands of words, so the context window must be extended with corresponding adjustments to positional encoding.
- Data cleaning: Remove duplicate clauses, and de-identify personal information and trade secrets to keep training compliant.
2.2 Supervised Fine-Tuning (SFT)
Structure samples as “task instruction—evidence—conclusion” so the model learns to locate the basis first and then give a judgment, instead of generating a conclusion directly. A typical contract review sample looks like this:
{"instruction": "Review clause risk and provide revision suggestions","context": "Article 8 Payment and Acceptance...","evidence": ["relevant Civil Code provisions", "internal compliance baseline"],"output": {"risk_level": "high","issue": "acceptance criteria are not quantifiable","suggestion": "add quantitative metrics and a dispute window"}}
2.3 Reinforcement Learning Post-Training (RLHF / Preference Alignment)
Legal answers often have “multiple acceptable phrasings but clearly poor ones,” which makes them well suited to preference optimization. Building preference pairs such as “more rigorous / more vague” and “cited / uncited” can significantly improve the model’s citation awareness and conservativeness, reducing hallucination risk caused by overconfidence.
3. How to Interpret Legal Evaluation Metrics Correctly
Legal evaluations typically report two types of metrics, and both are necessary:
- Accuracy: the proportion of individual judgments that are correct; reflects baseline capability.
- All-or-Nothing Pass Rate: a task counts as passed only if every sub-judgment within it is correct.
The second number is necessarily much lower than the first, because it is extremely sensitive to stability across multi-step tasks. Take a combination commonly seen in public evaluations—roughly 80% accuracy and roughly 20% all-or-nothing pass rate. The correct reading is: the model is already usable for single-point judgments, but in end-to-end tasks containing a dozen or more sub-steps, cumulative error remains significant. This directly determines the engineering strategy: do not hand an entire workflow to the model in one shot; instead, design task decomposition and human confirmation points.
Also note that open-weight and closed-weight models are of limited comparability. Open weights make private deployment and further domain training easier, which is a natural advantage in data-sensitive legal scenarios. This is the practical reason such leaderboards attract broad attention.
4. Integration Design for Real Legal Workflows
4.1 Contract Review and Document Revision
The ideal form is a model that outputs structured review results, which a document processing layer then converts into reviewable revisions and comments. A sample flow:
document parsing -> clause segmentation -> risk identification -> basis retrieval -> structured results-> revision/comment rendering -> human confirmation -> version audit trail
The key design point is traceability: every comment should carry its source and a confidence score. Low-confidence items should not be rewritten automatically by default; they should only be flagged.
4.2 Evidence Analysis
Retrieval-augmented generation (RAG) should be standard: vector retrieval handles semantic recall, keyword retrieval handles exact matches such as IDs and dates, and a reranking model handles final ordering. All conclusions must point back to the original evidence fragments; generation without citations is not allowed.
4.3 Compliance Planning
Compliance is a strongly time-sensitive task. Build a three-layer structure of “regulation library—obligation list—control items,” with the model performing obligation extraction and control-item mapping. When rules change, only the knowledge base needs updating; the model does not need retraining.
5. Private Deployment and Risk Control
If an enterprise builds a private environment on general capabilities such as compute, container platforms, object storage, and log monitoring from Baidu AI Cloud, it can deploy model services, the knowledge base, and audit logs in separate layers so that data never leaves the domain. Four baselines are recommended:
- Least-privilege access with operation audit trails.
- Dual-channel output validation (rules engine + model review).
- Mandatory human sign-off for high-risk scenarios.
- A local evaluation set to continuously track domain adaptation, rather than relying on a single public leaderboard result.
In summary, the value of a legal vertical model is not to “replace legal judgment,” but to automate standardizable retrieval, comparison, and prompting work and embed it into existing processes in an auditable way. Understanding metric boundaries, decomposing tasks properly, and ensuring traceable evidence are the keys to reliable deployment.
