Skip to main content
Cookbook & Real-World Examples
Legal Document Analyzer
Cookbook Blueprint

Legal Contract Analyzer

Train a private legal extraction model to parse indemnification clauses, liability caps, and governing jurisdiction with strict verbatim quotation constraints.

What You'll Build

  • A localized Qwen2.5 or Llama-3.2 model fine-tuned on commercial agreements, NDAs, and Master Services Agreements (MSAs).
  • Zero-hallucination extraction: every output value is constrained to be an exact verbatim substring of the input contract text.
  • 100% attorney-client privileged local execution: training weights, source contracts, and extracted outputs never touch external cloud APIs.

Step 1: Prepare Contract Training Data

Contract Clause Extraction Dataset

3 sample rows · JSONL format · CC-BY-4.0 · pre-validated for moro data build

Download .jsonl

Format training contracts into prompt/response JSONL with structured JSON extraction:

cat > contracts_data.jsonl << 'EOF'
{"messages": [{"role": "system", "content": "You are a legal contract analysis engine. Extract clauses strictly as JSON without commentary. Every extracted value must be an exact verbatim substring from the source contract."}, {"role": "user", "content": "Extract indemnification, liability cap, and governing law:

Section 14. Indemnification. Service Provider agrees to defend, indemnify, and hold harmless Customer from any gross negligence. Section 15. Liability. Total liability shall not exceed total fees paid in the prior 12 months. Section 19. Forum. Governed by the laws of Delaware."}, {"role": "assistant", "content": "{"indemnification": "defend, indemnify, and hold harmless Customer from any gross negligence", "liability_cap": "not exceed total fees paid in the prior 12 months", "governing_law": "laws of Delaware"}"}]}
EOF
  

Step 2: Scaffolding & Configuration

moro init legal-reviewer --template legal-analyzer
cd legal-reviewer
cp ../contracts_data.jsonl data/raw/
  

In moro.yaml, enforce strict PII scrubbing and conservative token cleaning:

name: "legal-reviewer"
version: "1.0.0"

dataset:
  source: ./data/raw/contracts_data.jsonl
  format: jsonl
  pii_scan: true                      # Strips real client names, SSNs, and banking details
  mi_guard_threshold: 0.88            # Protects rare statutory citations (e.g. Del. C. § 102(b)(7))

model:
  base: "Qwen/Qwen2.5-7B-Instruct"
  quantization: "nf4"

training:
  learning_rate: 1.8e-4
  micro_batch_size: 1
  gradient_accumulation_steps: 16
  gradient_checkpointing: true
  auto_heal: true
  

Step 3: Compile & Train

moro data build
moro train
  

Step 4: Citation & Substring Grounding Evaluation

cat > eval/legal_eval.yaml << 'EOF'
name: "legal-grounding-suite"
tests:
  - id: "test_nda_extraction"
    prompt: "Extract clauses from: [Sample NDA Excerpt]"
    expected_keywords: ["indemnify", "liability", "Delaware"]
EOF

moro eval run --checkpoint ./runs/best/ --suite eval/legal_eval.yaml
  

Step 5: Local Air-Gapped Deployment

moro release export --run-id best --version v1.0.0 --quant Q4_K_M
moro release deploy --target ollama --version v1.0.0 --name legal-reviewer
  

Privilege & Governance Guarantees

100% on-premise execution preserves Attorney-Client Privilege.
Zero telemetry egress or external logging verified by moro doctor --privacy.