Note: Please note that this project was created and used in 2023 for personal projects, it is now public, and whilst it may be of use, it may also be outdated due to the nature of law.
<div style="margin:5 auto;>
Scots Law AI — A Scotland-Focused Legal AI System
A domain-specific Legal AI system built for professional use by Scottish solicitors, advocates, solicitor advocates, in-house legal teams, paralegals, Procurators Fiscal support teams, and other legal professionals working on Scotland-based matters.
Overview
This system combines domain-specific QLoRA SFT fine-tuning to instil Scottish legal tone, procedure, and doctrine, with a Retrieval-Augmented Generation (RAG) pipeline for current, date-aware legislation and case law at the point of inference.
The system's defining value is not generic UK law competence, but reliable performance on Scots law and on mixed-jurisdiction matters affecting Scottish practice.
Architecture
| Component | Choice | Rationale |
|---|---|---|
| Base model | Equall/Saul-7B-Instruct-v1 | Mistral-7B backbone, pre-trained on 190M tokens from legislation.gov.uk (including Scottish Parliament Acts). MIT licence. |
| Training method | QLoRA SFT | 4-bit NF4 quantisation + LoRA adapters (r=128, all-linear, RSLoRA). Fits 24GB VRAM. |
| SFT dataset | RealistSec/scots-law-sft-v1 | 2,996 quality-evaluated exemplars covering 57+ Scottish practice areas. |
| Embedding model (RAG) | BAAI/bge-m3 | 8192-token context, hybrid dense+sparse, MIT licence. |
| RAG scoring | Authority-weighted | 0.5×text_sim + 0.2×authority + 0.2×court_hierarchy + 0.1×jurisdiction_match, with currentness multiplier. |
Dataset
The SFT dataset contains 2,996 exemplars (after quality evaluation, pruning of D/F grades, and enrichment) across 83 practice areas and categories.
Quality Metrics (post-evaluation)
| Dimension | Average Score |
|---|---|
| Terminology correctness | 0.866 |
| Format compliance | 0.924 |
| Jurisdiction classification | 0.969 |
| E&W contamination avoidance | 1.000 |
| Uncertainty flagging | 0.821 |
| Coherence | 0.826 |
| Overall | 0.747 |
Grade distribution: A: 28.2% | B: 60.0% | C: 11.8% | D: 0% | F: 0%
Key Scottish Legal Features
The system is trained on distinctly Scottish legal concepts including:
- Terminology: advocate (not barrister), pursuer/defender (not claimant/defendant), interdict (not injunction), missives, disposition, standard security, delict (not tort), executry (not probate), diligence (not enforcement)
- Civilian heritage: no consideration requirement in contract, numerus clausus of real rights, condictio indebiti, real-right trust analysis
- Criminal law: corroboration rule, three verdicts (guilty/not guilty/not proven), 15-person jury, Moorov doctrine
- Property: post-feudal framework (2000/2003/2004 Acts), real burdens (not restrictive covenants), servitudes (not easements), Land Register of Scotland
- Devolution: Scotland Act 1998 s.29(2)(d) automatic ECHR invalidity, Schedule 5 reserved matters, retained/assimilated EU law
- Institutional writers: Stair, Erskine, Bell, Hume — cited as primary authority, not merely commentary
Project Structure
scots_law_ai/ # Core Python package
├── metadata_schema.py # Legal document metadata + authority scoring
├── chunking.py # Semantic chunkers for legislation/case law/guidance
├── dataset_*.py # Dataset generation, compilation, evaluation, enrichment
├── rag_pipeline.py # FAISS + bge-m3 RAG with authority scoring
├── evaluation.py # 33-case evaluation benchmark
├── practice_area_*.py # Knowledge bases for all 57 practice areas
├── variation_engine.py # Template-based expansion engine
data/ # Generated datasets and quality reports
research/ # 5 deep research documents on Scottish law sources
train_scots_law.py # QLoRA SFT training script (Saul-7B)
Evaluation Benchmark
33 test cases across 8 categories: terminology correctness, jurisdiction awareness, doctrinal competence, authority citation, E&W contamination resistance, refusal discipline, practice area coverage, and output structure.
Data Sources
| Source | Content | Licence |
|---|---|---|
| legislation.gov.uk | All ASPs, SSIs, pre-1707 Acts | OGL v3 ✅ |
| BAILII/SCTS | Scottish court judgments | Crown copyright |
| Archive.org | Bell's Principles, Stair's Institutions, Erskine's Institute | Public domain |
Disclaimer
This system is an AI tool for legal professionals. It is not a substitute for qualified legal advice. All outputs should be verified by a qualified Scottish legal practitioner before being relied upon. The system may contain inaccuracies and should not be used as the sole basis for legal decision-making.
Project Crafted, and Tokens Paid for
by RealistSec.
Do your part to support Safe AI | Read the Autonomous LicensingCompact on GitHub.