Inspiration
German law is renowned for its analytical rigor and strict methodology. Whether analyzing a complex civil contract breach under the BGB or assessing criminal liability under the StGB, legal practitioners and students must adhere to the formal Gutachtenstil (hypothetical syllogistic method: Obersatz → Definition → Subsumption → Conclusion) or the Urteilsstil (declarative judicial method).
However, traditional generic LLMs frequently struggle with German legal analysis:
Methodological Hallucinations: They mix conclusions into the premise or generate single-child structural anomalies (violating the cardinal German rule: "Wer A sagt, muss auch B sagen"). Lack of Verifiable Grounding: They invent court citations or apply outdated norm versions. Rigid Meta-Texting: Many AI tools output unnatural bullet points labeled "Definition:" or "Subsumption:" rather than the authentic, flowing scholarly prose required in judicial rulings and state exams. We created Subsumator to bridge this gap: a dedicated, AI-assisted legal expert system and Gutachten generator that pairs deep legal tree reasoning with a high-performance RAG database of over 423,000 court decisions and 113,000 statutory norms.
What it does
Subsumator transforms unstructured case facts into fully structured, legally grounded, and publication-ready legal opinions (Rechtsgutachten) and judicial drafts (Urteile):
Interactive 3-Column Legal Workspace: Left Column (Case Facts & Data Hub): Preset cases (Criminal Law § 177 StGB, Sales Warranty §§ 437/323 BGB, Tort Law § 823 BGB), instant word counting, style switcher (Gutachtenstil vs. Urteilsstil), and local RAG dataset manager. Middle Column (Exam Tree & Validation): Automatically builds hierarchical legal exam trees with authentic numbering (A., I., 1., a), aa)), real-time status badges (Draft, Defined, Subsumed, Disputed), and active single-child violation detection with 1-click auto-fixes (Inline Merge or Add Counter-Point). Right Column (3-Tab Legal Inspector): Subsumption Editor: Fine-tune premises, definitions, factual subsumption, and opinion disputes (h.M. vs. Mindermeinung). RAG Sources Inspector: Live sub-millisecond retrieval across statutory norms and BGH decisions with extracted Leitsätze and 1-click citation insertion. Document Synthesis: Generates continuous, publication-ready legal prose without artificial meta-labels, featuring 1-click Markdown export, live editing, and instant print/PDF rendering. Hybrid RAG Knowledge Engine: Connects directly to an integrated SQLite FTS5 database (30.5 GB) indexing 113,537 federal norms and 423,941 German court decisions with zero RAM overhead. Two-Tier LLM Architecture: Employs fast models (Tier 1) for rapid tree decomposition and query generation, and deep reasoning models (Tier 2) for complex subsumption and controversial legal disputes, with a 100% offline mock fallback.
How we built it
Frontend & App Framework: Next.js 14 (App Router, Server Components & Route Handlers), React 18, TypeScript, Tailwind CSS, and Lucide React. State Management: Modular Zustand stores (useExamTreeStore, useRAGStore, useSettingsStore) ensuring reactive tree updates and local persistence. Search & Knowledge Engine: SQLite FTS5 + WAL Mode: Full-text indexing with unicode61 tokenization, B-Tree indexes on statutory markers (book_code, section, file_number), and BM25 ranking. BM25 & Leitsatz Extractor: Custom German legal tokenizer capturing paragraph markers (§, Abs., Nr.), compound words, and court headnotes. Cross-Scoring Reranker: Boosts exact norm matches and decisions from federal courts (BGH, BVerfG, BAG, BFH, BVerwG). Prose Synthesizer: LegalProseSynthesizer algorithmically weaves Obersatz, definition citations, factual subsumption, and conclusions into seamless German legal paragraphs. Multi-Provider LLM Router: Secure server-side gateway supporting OpenAI, Anthropic Claude, Google Gemini, Ollama (Local), and OpenRouter. Containerization & Cloud Deployment: Multi-stage node:22-alpine Dockerfile in Next.js Standalone mode, orchestrated via docker-compose and 1-click deployment scripts (deploy-gcp.ps1 / deploy-gcp.sh) for Google Cloud Run.
Challenges we ran into
Massive Dataset Scale (30+ GB JSONL): Attempting to stream 27 GB of raw court decisions into memory caused memory pressure. We resolved this by building a dedicated streaming pipeline (build_sqlite_index.py & sqlite-rag-service.ts) that indexed the entire dataset into SQLite FTS5 using transactions and WAL mode, reducing RAM consumption to nearly zero while dropping query latency below 5 ms. Enforcing German Legal Formalism: LLMs naturally tend to format output as bullet points with explicit labels like "Subsumption:" and "Conclusion:". We engineered specialized few-shot prompts and a dedicated structural prose synthesizer to transform tree nodes into authentic, academic legal text. Cross-Platform Containerization: Compiling native C++ SQLite addons (better-sqlite3) inside minimal Alpine Linux containers required tuning the multi-stage build with python3, make, g++, and Node 22 LTS to ensure rock-solid performance on both Windows and Linux hosts.
Accomplishments that we're proud of
Gigabyte-Scale Search in Milliseconds: Built a blazing-fast local search system capable of querying 423,941 court decisions in under 5 milliseconds. Flawless German Legal Methodology: Created an automated validator for the strict single-child rule ("Wer A sagt, muss auch B sagen") with instant merge and counter-point solutions. Production-Ready Cloud Deployability: Developed a self-contained Docker container with 1-click Google Cloud Run deployment and zero external database dependencies.
What we learned
Domain-Specific Legal Tokenization: Standard English or generic BPE tokenizers split German legal citations like § 177 Abs. 5 Nr. 1 StGB into fragmented tokens. Custom tokenization and unicode normalization dramatically improve retrieval relevance. Balancing Structure and Prose: Visual tree editing is optimal for human analysis and outlining, but continuous prose is essential for legal documents. Decoupling the tree state from the prose rendering pipeline provides the best of both worlds. Local-First RAG Performance: SQLite FTS5 with WAL mode provides enterprise-grade performance for read-heavy text datasets without the operational overhead of heavy database clusters.
What's next for Subsumator
PDF & DOCX Template Export: Exporting styled legal briefs with customized law firm letterheads, formal court headers, and academic footnote formatting. Embedding-Based Dense Retrieval (Vector Hybrid Search): Combining SQLite FTS5 keyword search with local quantized vector embeddings (sqlite-vss / bge-m3) for semantic search across subtle legal concepts. Interactive Multi-Agent Moot Court / Opposing Counsel Mode: Introducing an automated "Advocatus Diaboli" agent to challenge weak subsumption arguments and surface conflicting minority opinions (Mindermeinungen). Expanded State Law Repositories: Integrating state-specific administrative and police law databases (Landesrecht like PolG, BauO, VwVfG) for all 16 German federal states.
Built With
- docker
- gemini
- nextjs
- python
- rag
- typescript
