German Legal QA 3B: Domain-Adapted LLM for German Law
A LoRA-adapted Llama 3.2 3B model fine-tuned on German legal question-answering data. Designed for use with a RAG (Retrieval-Augmented Generation) pipeline that grounds answers in actual statutory text.
This model answers questions about German civil, criminal, and procedural law with paragraph citations (§-references).
Note: This model is for educational and research purposes only. It does not constitute legal advice.
Supported Legal Domains
BGB (Civil Code) · StGB (Criminal Code) · ZPO (Civil Procedure) · GG (Basic Law) · HGB (Commercial Code) · ArbGG (Labor Courts)
Model Details
The adapter was trained using Apple MLX on an M1 Pro MacBook, demonstrating efficient legal domain adaptation on consumer hardware.
| Component | Configuration |
|---|---|
| Base Model | Llama-3.2-3B-Instruct (4-bit quantized) |
| Adapter | LoRA, rank 16, 16 layers |
| Training Data | 10,000 German legal Q&A pairs |
| Training Framework | MLX (Apple Silicon native) |
| Training Steps | 500 |
| Final Train Loss | 1.874 |
| Final Val Loss | 1.908 |
| Peak Memory | 4.3 GB |
| Adapter Size | 46 MB |
Training Data
Trained on GerLayQA (EACL 2024) — real legal questions from German citizens paired with expert lawyer answers.
| Source | Examples | Coverage |
|---|---|---|
| GerLayQA (BGB) | 8,000+ | Civil law, contracts, liability |
| GerLayQA (StGB) | 1,000+ | Criminal law, sentencing |
| GerLayQA (ZPO) | 500+ | Procedural law |
RAG Pipeline (Recommended)
This adapter works best combined with retrieval over German federal statutes. The full system indexes 103,000+ legal text chunks from 6,111 German federal laws.
Query → Embed → FAISS Search → Retrieve § Text → Generate Answer
With RAG, the model produces factually grounded answers citing the correct statutory provisions. Without RAG, the model may hallucinate legal content.
Usage
With MLX (Apple Silicon)
from mlx_lm import load, generate
model, tokenizer = load(
"mlx-community/Llama-3.2-3B-Instruct-4bit",
adapter_path="jonprompter/german-legal-qa-3b-lora"
)
prompt = """<|begin_of_text|><|start_header_id|>system<|end_header_id|>
Du bist ein deutschsprachiger Rechtsassistent. Beantworte rechtliche Fragen präzise und verständlich. Zitiere relevante Paragraphen wenn möglich. Dies ist keine Rechtsberatung.<|eot_id|><|start_header_id|>user<|end_header_id|>
Was besagt §823 BGB?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
"""
response = generate(model, tokenizer, prompt=prompt, max_tokens=256)
print(response)
With Transformers (PyTorch)
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base_model = AutoModelForCausalLM.from_pretrained("unsloth/Llama-3.2-3B-Instruct")
model = PeftModel.from_pretrained(base_model, "jonprompter/german-legal-qa-3b-lora")
tokenizer = AutoTokenizer.from_pretrained("unsloth/Llama-3.2-3B-Instruct")
Evaluation
Evaluated on held-out GerLayQA test set with RAG retrieval (50 samples):
| Metric | Score | Description |
|---|---|---|
| Token F1 | 0.218 | Word overlap with reference |
| ROUGE-L | 0.101 | Longest common subsequence |
| BERTScore F1 | 0.652 | Semantic similarity |
| Citation Accuracy | 0.059 | Correct §-reference matching |
Scores reflect comparison against verbose forum-style lawyer answers. The system provides concise statutory answers — different style, same meaning (shown by BERTScore).
Example Output
Q: Was besagt §823 BGB?
A: § 823 BGB besagt, dass wer vorsätzlich oder fahrlässig das Leben, den Körper, die Gesundheit, die Freiheit, das Eigentum oder ein sonstiges Recht eines anderen widerrechtlich verletzt, dem anderen zum Ersatz des daraus entstehenden Schadens verpflichtet ist.
Limitations
- Requires RAG retrieval for factually accurate answers
- Trained on German law only — not applicable to other jurisdictions
- Should not be used as a substitute for professional legal advice
- May produce hallucinations without retrieval context
- Early-stage model (500 training steps) — answer quality improves with further training
Full System
The complete RAG pipeline (data acquisition, indexing, training, evaluation, demo) is available at:
github.com/myaxyo/german-legal-qa
Features:
- Data pipeline: 6,111 German federal statutes indexed
- FAISS vector search: 103K chunks, sub-second retrieval
- Hybrid retrieval: keyword + semantic search
- Gradio demo: Interactive chatbot with source citations
- MLX training: Fine-tune on Apple Silicon in 30 minutes
Citation
@software{german_legal_qa_2026,
title={German Legal QA Assistant},
author={jonprompter},
year={2026},
url={https://github.com/myaxyo/german-legal-qa}
}