A Practical Guide to Building Vertical Large Language Models for Legal Practice

    This article explains how to adapt general-purpose large language models into vertical models for legal work. It covers a four-layer architecture (base model, domain retrieval index, domain tool plugins, and security and retention policies), domain adaptation through continued pre-training, instruction tuning, and preference alignment, and the engineering details of hybrid retrieval, reranking, and passage extraction. It also breaks legal assistant capabilities into evaluable subtasks, proposes a three-layer evaluation approach with a retrieval-off control group, outlines a zero-retention privacy and compliance design, and recommends a phased rollout gated by citation verifiability and false-positive rates.

    General-purpose large models can talk about the law but cannot actually handle a case. Legal text has three distinctive properties. First, citations are dense: every conclusion must trace back to a specific statute or a specific passage of a case opinion. Second, semantic precision requirements are extremely high — a “core holding” and “obiter dicta” carry entirely different legal weight. Third, responsibility boundaries are clear, because the output feeds into real determinations of rights and obligations.

    The value of a vertical model therefore lies not in parameter count but in engineering domain knowledge, the retrieval pipeline, and compliance constraints together.

    From an engineering perspective, verticalization typically has four layers: the base model, a domain retrieval index, domain tool plugins, and security and retention policies. None of the four can be skipped. Without the retrieval layer, the model produces plausible-looking but wrong citations. Without the tool layer, it cannot connect to the actual case workflow. Without a retention policy, it will not pass an enterprise compliance review.

    2. Domain Adaptation: From “Generally Correct” to “Professionally Correct”

    The goal of domain adaptation is to shift the answer distribution from public corpora to professional corpora. The common approach has three stages: continued pre-training, instruction tuning, and preference alignment. Continued pre-training injects terminology and writing style. Instruction tuning fixes the task shape as “retrieve — locate — draft — verify.” Preference alignment uses ranking data from senior practitioners to settle the tradeoff between “verbose but harmless” and “concise but missing citations.”

    Adaptation does not mean making the model memorize cases. Memory-based adaptation introduces two risks: stale knowledge and no traceability. The more robust route is “light adaptation plus strong retrieval” — keep volatile knowledge in an external index and keep stable reasoning ability in the model.

    An illustrative organization of training data:

    1. {
    2. "task": "contract_risk_review",
    3. "input": {"clause": "...", "context_type": "service_agreement"},
    4. "output": {
    5. "risk_items": [{"type": "missing liability cap", "severity": "high", "evidence_span": [12, 47]}],
    6. "suggested_revision": "..."
    7. },
    8. "meta": {"jurisdiction": "US", "reviewed_by": "senior_lawyer"}
    9. }

    evidence_span is the key field: it forces the model to emit a locatable evidence range, which makes downstream citation verification straightforward.

    3. Retrieval Augmentation: Engineering a Vertical Retrieval Index

    The accuracy ceiling of legal question answering is largely determined by the retrieval layer. A usable domain retrieval system has at least three parts: a structured index of statutes and case opinions, supplementary web-scale corpus, and passage-level localization.

    The recommended design is a three-stage pipeline: hybrid retrieval, reranking, and passage extraction.

    1. Hybrid retrieval: keyword search guarantees exact matches on statute numbers and case numbers, while vector search guarantees semantic near-neighbor recall.
    2. Reranking: a cross-encoder scores candidate passages and suppresses distractors that are “topically similar but reach the opposite conclusion.”
    3. Passage extraction: output must land on specific passages rather than whole documents, so lawyers can verify quickly.

    Coverage matters just as much. Published opinions, statutory law, and court rules update at different frequencies, so incremental sync and version tagging are required; otherwise the system will cite rules that are no longer in force. An illustrative wrapper for the retrieval call:

    1. def legal_search(query, top_k=20, jurisdiction="US"):
    2. # exact match first, semantic recall as a supplement
    3. exact = keyword_index.search(query, filters={"jurisdiction": jurisdiction})
    4. semantic = vector_index.search(embed(query), top_k=top_k)
    5. merged = rerank(query, exact + semantic)[:top_k]
    6. return [extract_passage(d) for d in merged]

    In practice, the gains from vertical retrieval show up in two metrics: the number of relevant cases recalled, and the precision of key-passage localization. The first drives “finding everything”; the second drives “citing accurately.” These two metrics should be measured separately, so that a single accuracy number does not mask insufficient recall.

    4. Breaking Down Core Case-Handling Capabilities

    Turning a “case assistant” into evaluable subtasks is the prerequisite for deployment.

    • Similar-case retrieval: input factual elements, output similar cases plus points of difference. The hard part is extracting factual elements — compressing a long narrative into structured elements.
    • Holding stratification: separating the core reasoning of a judgment from obiter dicta, which determines whether a citation can serve as an authoritative basis.
    • Adverse precedent mining: proactively recalling cases that go against your own side. This is counter-evidence retrieval and requires an adversarial objective in the ranking stage.
    • Document drafting: pleadings and memos are highly templated, which suits a combination of “template + retrieved evidence + generation.”
    • Contract risk identification: split clauses into decidable risk types and give each a severity level and a revision suggestion.
    • Argument logic mapping: map issues, evidence, and statutes into a tree structure to expose logical gaps.

    Illustrative output structure (issue tree):

    1. issue_tree:
    2. - issue: "whether a contract was formed"
    3. elements: ["offer", "acceptance", "consideration"]
    4. evidence: ["doc#12:3-9", "case#88:15-21"]
    5. gaps: ["no evidence that acceptance was delivered"]

    5. Evaluation: Validating Beyond a Single Benchmark Score

    A single benchmark accuracy figure is not enough to establish usability. A three-layer evaluation is recommended:

    1. Knowledge layer: terminology explanation, and judging the conditions under which a statute applies.
    2. Retrieval layer: recall rate, passage localization hit rate, and citation verifiability rate.
    3. Task layer: drafting completeness, risk recall rate, and false-positive rate.

    In industry practice, vertical models typically score significantly higher on professional benchmarks than general versions built on the same base, and the gain comes mainly from retrieval and alignment rather than from the base model. Evaluation reports should therefore include a control group with retrieval turned off, to quantify the retrieval contribution and avoid recording an engineering gain as a model gain.

    6. Privacy and Compliance: A Path to Zero Retention

    The sensitivity of legal data means the architecture must default to “data does not land and is not used for training.” Practical measures include encryption in transit and at rest, tenant-level key isolation, no request-level log retention, and disabling training data reflow. Three engineering points also need attention. First, the cache layer needs a very short lifetime and support for per-tenant purge. Second, observability data must be field-masked so that case text never ends up in distributed traces. Third, plugin calls must follow least privilege, with the retrieval tool returning only the necessary passages.

    Enterprises that self-host can deploy inference services on a container platform, hold masked index snapshots in object storage, use a message queue for incremental sync, and rely on logging plus monitoring and alerting for audit and capacity observation. Baidu AI Cloud is commonly used to carry these general capabilities in such scenarios, though the specific selection still needs to be assessed against data classification and compliance requirements.

    7. Plugin Tool Layer and Open Interfaces

    Domain capabilities ultimately enter the workflow through tool calls. Plugins are best grouped into retrieval, validation, generation, and collaboration, with each plugin declaring its input and output schema and its permission scope. When exposing interfaces externally, provide idempotency keys, quotas, and audit fields to avoid duplicate billing and duplicate writes on long-text tasks.

    1. {
    2. "tool": "citation_check",
    3. "input": {"claim": "...", "citations": ["case#88:15-21"]},
    4. "output": {"verified": true, "mismatch": []},
    5. "permission": ["read:index"]
    6. }

    8. A Phased Rollout Plan

    Phase one is a read-only assistant focused on retrieval and citation verification, which carries the lowest risk. Phase two opens drafting and risk identification with human review in the loop. Phase three opens write-back into business systems once permissions and auditing are mature. Each phase should gate expansion on citation verifiability rate and false-positive rate, not on user count as the only metric.